A modern web application that recognizes handwritten digits using a Convolutional Neural Network (CNN) trained on the MNIST dataset. The application features a clean, dark-themed UI for uploading and processing handwritten digit images.
- Deep Learning Model: Custom CNN architecture trained on MNIST dataset
- Modern Web Interface: Dark-themed, responsive UI with drag-and-drop functionality
- Real-time Processing: Instant digit recognition with confidence scores
- Monitoring System: Logging system for predictions and error tracking
- RESTful API: Flask backend serving predictions via JSON responses
Digit_App/
├── training/ # Model training code and data
│ ├── train_digit_model.py # CNN model definition and training script
│ └── data/ # MNIST dataset (downloaded automatically)
├── model/ # Saved model weights
│ └── improved_digit_model.pth
├── api/ # Flask backend
│ └── app.py # API endpoints and model serving
├── web/ # Frontend
│ └── templates/
│ └── index.html # Main web interface
├── monitor/ # Monitoring and logging
│ └── logger.py # Prediction logging system
└── requirements.txt # Python dependencies
- Backend: Python, Flask
- Deep Learning: PyTorch, torchvision
- Frontend: HTML5, Tailwind CSS, JavaScript
- Image Processing: Pillow
- Monitoring: Python logging
-
Clone the Repository
git clone https://github.com/yourusername/Digit_App.git cd Digit_App -
Create Virtual Environment
cd api python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies
pip install flask torch torchvision pillow numpy
-
Train the Model
cd ../training python train_digit_model.pyThis will:
- Download the MNIST dataset
- Train the CNN model
- Save the model weights to
model/improved_digit_model.pth
-
Start the Flask Server
cd ../api python app.py -
Access the Web Interface
- Open your browser
- Navigate to
http://localhost:5000 - Start recognizing digits!
The CNN architecture consists of:
- 3 Convolutional layers with batch normalization
- Max pooling and dropout for regularization
- 2 Fully connected layers
- Output layer for 10 digits (0-9)
Training parameters:
- Optimizer: Adam
- Learning rate: 0.001
- Batch size: 64
- Epochs: 20 (with early stopping)
-
GET /
- Returns the main web interface
-
POST /predict
- Accepts: Image file via FormData
- Returns: JSON with predicted digit
{ "digit": 5 }
The application logs:
- Predictions with confidence scores
- Error messages
- Processing times
Logs are stored in:
monitor/predictions.log- Console output (during development)
This project is licensed under the MIT License - see the LICENSE file for details.
- MNIST Dataset: http://yann.lecun.com/exdb/mnist/
- PyTorch Documentation: https://pytorch.org/docs/
- Flask Documentation: https://flask.palletsprojects.com/