copilot/upgrade-ai-autocorrect-assistant
AI-powered autocorrect typing assistant — runs 100% in the browser via GitHub Pages. No backend, no account, no internet required after first load.
A production-ready Android custom keyboard and GitHub Pages web app with intelligent autocorrect powered by edit-distance algorithms.
A fully client-side autocorrect demo that runs directly in any modern browser — no server, no build step required.
After enabling GitHub Pages (see below), your demo will be available at:
https://<your-username>.github.io/Smart-AutoCorrect-Keyboard/
- Real-time autocorrect — suggestions appear on every keystroke
- Damerau-Levenshtein edit-distance implemented in pure JavaScript
- Frequency-ranked suggestions — common words win ties
- Runs 100% offline — no network calls after the initial page load
- Responsive card layout — looks great on mobile and desktop
| File | Purpose |
|---|---|
index.html |
Page structure — input box, result displays, accessible markup |
style.css |
Modern, responsive card UI |
script.js |
Edit-distance algorithm and autocorrect logic |
dictionary.json |
English word → frequency map (used by the autocorrect engine) |
Simply open index.html in your browser:
# Option 1 – double-click index.html in your file manager
# Option 2 – serve with Python (avoids fetch() restrictions in some browsers)
python -m http.server 8080
# then visit http://localhost:8080- Push the repository to GitHub (all four web-app files must be in the root of the default branch).
- Go to Settings → Pages in your GitHub repository.
- Under Source, choose Deploy from a branch.
- Set the branch to
main(ormaster) and the folder to/ (root). - Click Save.
- GitHub will publish the site — the URL appears at the top of the Pages settings page.
ℹ️ Changes pushed to the selected branch are automatically redeployed within a few minutes.
dictionary.jsonis fetched asynchronously on page load.- The typed word is lower-cased and looked up directly in the dictionary (O(1)).
If found → "✅ Correct!"; if not → the edit-distance search runs. - Every dictionary word whose length difference from the input is within the allowed threshold is scored:
- Edit distance is computed with the Damerau-Levenshtein algorithm (handles swaps, inserts, deletes, substitutions).
- Score =
frequency − distance × 50so common words win ties.
- The highest-scoring candidate within the tolerance window is shown.
Edit-distance tolerance (mirrors the Android Kotlin implementation):
| Input length | Max allowed distance |
|---|---|
| ≤ 3 | 0 (no correction) |
| 4–5 | 1 |
| 6–8 | 2 |
| ≥ 9 | 3 |
A production-ready Android custom keyboard with intelligent autocorrect, word suggestions, bigram prediction, and Clean Architecture. main
| Feature | Details |
|---|---|
| 🔴 Real-time highlighting | Misspelled words are underlined in red as you type |
| 💡 Top 5 suggestions | Ranked by Levenshtein distance + word frequency |
| 🖱️ Click to replace | Tap any suggestion chip to instantly fix the word |
| 📊 Live statistics | Word count, correction count, accuracy percentage |
| 📱 Mobile responsive | Fluid layout that works on every screen size |
| 📲 PWA / Installable | Add to home screen on iOS & Android |
| Service Worker caches all assets after first visit | |
| 🔒 100% private | All processing is local — nothing leaves your browser |
The autocorrect engine uses the classic Levenshtein edit-distance algorithm to measure how "close" any two words are:
distance(a, b) = minimum number of single-character edits
(insertions · deletions · substitutions)
required to transform a into b
| Word length | Max allowed distance |
|---|---|
| ≤ 3 | 0 — no correction |
| 4 – 5 | 1 |
| 6 – 8 | 2 |
| ≥ 9 | 3 |
Suggestions are ranked by a combined score:
score = distance − log₂(frequency) × 0.1
Lower score = better suggestion. This ensures that common words rank ahead of rare words at the same edit distance.
| Step | Complexity |
|---|---|
| Single pair comparison | O(m × n) where m, n are word lengths |
| Dictionary scan | O(D × m × n) — optimised with length pre-filter |
| Length pre-filter | Skips any dict word whose length differs by > maxDist |
Smart-AutoCorrect-Keyboard/
├── index.html ← Single-page app shell
├── style.css ← Dark-theme responsive styles
├── script.js ← Levenshtein engine + UI logic
├── words.json ← 500+ word dictionary
├── manifest.json ← PWA manifest
├── sw.js ← Service Worker (offline support)
├── assets/
│ └── icon.png ← App icon (192 × 192)
└── README.md
- Fork or clone this repository
- Go to Settings → Pages
- Under Source, choose Deploy from a branch
- Select branch
main(or your default branch) and folder/ (root) - Click Save
Your app will be live at:
https://<your-username>.github.io/Smart-AutoCorrect-Keyboard/
No build step required — just open index.html in a browser:
# Option 1: Python simple server (recommended — needed for fetch() + SW)
python3 -m http.server 8080
# Then open http://localhost:8080
# Option 2: Node.js
npx serve .
⚠️ Important: Open viahttp://localhost:…rather thanfile://so thatfetch('words.json')and the Service Worker work correctly.
The main card with real-time highlighted preview and suggestion chips:
┌─────────────────────────────────────────────┐
│ ● ● ● autocorrect.ai — typing assistant │
├─────────────────────────────────────────────┤
│ YOUR TEXT │
│ ┌───────────────────────────────────────┐ │
│ │ Teh quik brwon fox jmps over the… │ │
│ └───────────────────────────────────────┘ │
│ HIGHLIGHTED PREVIEW │
│ [Teh] [quik] [brwon] fox [jmps] over the… │
│ SUGGESTIONS │
│ [① the d=1] [② ten d=2] [③ tea d=2] │
├──────┬──────┬──────┬────────────────────────┤
│ 12 │ 4 │ 67% │ 550 │
│ Words│Fixes │Accur.│ Dict │
└──────┴──────┴──────┴────────────────────────┘
words.json is a plain JSON array of strings. Add your own domain-specific terms:
{
"words": [
"javascript", "typescript", "react", "your-custom-term",
...
]
}The engine will deduplicate and sort the list automatically at load time.
Pull requests are welcome! Please open an issue first to discuss what you would like to change.
This project is open source and available under the MIT Licence.
Made with ❤️ — runs 100% in your browser