This project is an AI-powered web application that uses Markov Chains to predict and suggest the next words based on user input. Built with Flask, it provides an interactive interface for text prediction, leveraging a statistical model to analyze patterns in text sources.
This project was created as part of the 2nd semester Probability and Statistics course for the BS AI program. The task was to demonstrate a practical application of a probability concept in AI.
This app predicts the next words as you type by learning from text sources. It uses a probability model called a Markov Chain, which looks at the last one or two words you wrote to guess what might come next. For example, if you type "Romeo and" it suggests words that often follow, like "juliet" based on patterns in the training texts. You can also choose which texts to use for predictions through the app’s interface.
- Generates up to three word suggestions with probabilities using first and second-order Markov Chains.
- Supports dynamic addition and toggling of text sources for training the model.
- Provides real-time predictions with a debounced input handler for optimized performance.
- Displays the Markov Chain order (1st or 2nd) used for predictions.
- Filters out invalid tokens, ensuring only meaningful words are used in predictions.
- Offers a reset button to clear input and suggestions.
- Logs prediction request times for performance monitoring.
- Features a responsive front-end with suggestion chips and a loading overlay for smooth interaction.
- Automatically loads
.txtfiles from a sources directory for model training. If no txt file is found, it uses hardcoded sample passages for training.
- Backend: Python, Flask (2.3.2), NLTK (3.8.1)
- Frontend: HTML, JavaScript, Tailwind CSS
- Version Control: Git
MarkovTextPrediction/
│
├── sources/ # Directory for text source files
│ ├── shakespeare.txt # Sample text source
│ └── small.txt # Sample text source
├── ss/
│ └── image.jpeg # Screenshot of the website
├── static/
│ └── script.js # JavaScript for frontend logic
├── templates/
│ └── index.html # Main HTML template
├── .gitignore
├── app.py # Main Flask application file
├── markov_chain.py # Markov Chain logic implementation
├── README.md
├── requirements.txt # Python dependencies
├── LICENSE
![]() SAMI |
![]() IQRA |
|---|
-
Clone the Repository:
git clone https://github.com/samiternity/MarkovTextPrediction.git cd MarkovTextPrediction -
Install Dependencies:
pip install -r requirements.txt
-
Run the Flask App:
python app.py
-
Access the Application: Open your browser and navigate to
http://localhost:5000.
- Input Text: Enter text into the provided input area.
- View Suggestions: See real-time word suggestions with their probabilities.
- Toggle Sources: Enable or disable text sources to adjust the training data.
- Reset: Clear the input and suggestions using the reset button.
This project is licensed under the MIT License. See the LICENSE file for details.


