Skip to content

aditii23/algonive_predictive_text_generator

Repository files navigation

Predictive Text Generator

A lightweight N-gram based predictive text generator with multiple zero-dependency interfaces:

  • Local Web UI using only Python's standard library (no external packages)
  • Desktop UI using Tkinter (standard library)
  • Command Line Interface (CLI)
  • Optional Streamlit UI (requires dependencies)

Features

  • Robust N-gram model (configurable N from 2–4)
  • Preprocessing and tokenization with NLTK when available, with a built-in regex fallback
  • Laplace smoothing (configurable k)
  • Interpolated prediction combining different N-gram orders
  • User dictionary boosts: global word boosts and context-specific boosts
  • Model persistence: save to / load from JSON

Project Structure

.
├── app.py            # Streamlit UI (optional)
├── cli.py            # Command Line Interface
├── ngram_model.py    # Core N-gram model and utilities
├── tk_app.py         # Tkinter Desktop UI (fallback visual interface)
├── web_server.py     # Zero-dependency local Web UI (standard library)
├── user_dict.json    # Optional user boosts file
├── requirements.txt  # Dependencies for Streamlit UI
└── model.json        # Example persisted model file

Quickstart (No Dependencies)

You can use the Web UI, Desktop UI, or CLI without any external packages.

1) Web UI (recommended)

  • Start the server:
    • python web_server.py
  • Open in your browser:
    • http://127.0.0.1:8000/
  • Use the controls:
    • Parameters: set N-gram, Laplace k, Top-K, then click "Apply"
    • Corpus: paste text and click "Ingest Corpus"
    • Compose: type in the input field to see suggestions; click a suggestion pill to append
    • Boosts:
      • Global: word + value, click "Add"
      • Context: context + word + value, click "Add"
    • Model Persistence:
      • Path: set file path (e.g., model.json)
      • "Save" / "Load"

2) Desktop UI (Tkinter)

  • Launch: python tk_app.py
  • Similar controls for parameters, corpus ingestion, compose area, boosts, and save/load
  • Note: Tkinter is part of the standard library, but on some systems may require installing "tk" support

3) CLI

  • Run: python cli.py --n 3 --top-k 5
  • Options:
    • --n N-gram order (2–4)
    • --laplace-k Laplace smoothing constant (default 1.0)
    • --top-k number of suggestions to show (default 5)
    • --corpus PATH (optional) load text file(s) into the model
  • Interactive usage:
    • Type text and press Enter to see suggestions
    • Built-in help is available within the CLI (type help) and includes commands for global/context boosts and saving/loading the model

Optional: Streamlit UI

If you prefer Streamlit and can install dependencies:

  1. Create/Use a Python virtual environment (already present in the project as .venv).
  2. Upgrade pip (example for this project where the venv uses bin):
    • .venv\bin\python.exe -m pip install --upgrade pip
  3. Install dependencies:
    • pip install -r requirements.txt
  4. Run Streamlit:
    • python -m streamlit run app.py

If you encounter SSL/certificate or proxy issues when installing:

  • Configure pip to use your corporate proxy and certificate store
  • Try installing only streamlit first: pip install streamlit
  • Prefer precompiled wheels for packages like numpy and pandas

Model Persistence

  • Save: choose a path (e.g., model.json) in the UI or CLI command
  • Load: choose the same path to restore
  • The model JSON contains N, smoothing, counts, and user boosts

Tokenization Notes

  • NLTK-based tokenization is used when available
  • If NLTK is unavailable or punkt data is missing, the model automatically falls back to a regex tokenizer

Troubleshooting

  • SyntaxError: bytes can only contain ASCII literal characters
    • Ensure HTML strings use Unicode (no b""") in web_server.py
  • Tkinter not found
    • Install Python with Tk support or your OS-specific Tk package
  • Streamlit / pip install fails (SSL, proxies)
    • Use your system/corporate proxy settings, trusted certificates, or precompiled wheels

License

  • Internal/learning project. Add your preferred license as needed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors