{"id":30848351,"url":"https://github.com/pushkar-112/dl-handwritten-digit-recognition","last_synced_at":"2026-05-03T10:32:34.532Z","repository":{"id":311487315,"uuid":"1043660531","full_name":"pushkar-112/DL-Handwritten-Digit-Recognition","owner":"pushkar-112","description":"A Flask web app that recognizes handwritten digits in real-time using a custom neural network trained on MNIST","archived":false,"fork":false,"pushed_at":"2025-08-24T20:37:13.000Z","size":2401,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-24T22:50:48.527Z","etag":null,"topics":["cnn","deep-learning","flask","handwritten-digits-recognition","mnist","python","tensorflow"],"latest_commit_sha":null,"homepage":"https://digit-recognition-app-latest.onrender.com/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pushkar-112.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-24T10:55:19.000Z","updated_at":"2025-08-24T20:39:58.000Z","dependencies_parsed_at":"2025-08-24T22:50:52.500Z","dependency_job_id":"d9e06d0c-b7ec-49e7-82aa-b7a582e3cf24","html_url":"https://github.com/pushkar-112/DL-Handwritten-Digit-Recognition","commit_stats":null,"previous_names":["pushkar-112/dl-handwritten-digit-recognition"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/pushkar-112/DL-Handwritten-Digit-Recognition","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushkar-112%2FDL-Handwritten-Digit-Recognition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushkar-112%2FDL-Handwritten-Digit-Recognition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushkar-112%2FDL-Handwritten-Digit-Recognition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushkar-112%2FDL-Handwritten-Digit-Recognition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pushkar-112","download_url":"https://codeload.github.com/pushkar-112/DL-Handwritten-Digit-Recognition/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushkar-112%2FDL-Handwritten-Digit-Recognition/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273990253,"owners_count":25203307,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnn","deep-learning","flask","handwritten-digits-recognition","mnist","python","tensorflow"],"created_at":"2025-09-07T03:08:53.224Z","updated_at":"2026-05-03T10:32:34.412Z","avatar_url":"https://github.com/pushkar-112.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔢 Digit Recognition Web App\n[![Live Demo](https://img.shields.io/badge/Live-Demo-brightgreen)](https://digit-recognition-app-latest.onrender.com)\n\n\nA modern web application that uses deep learning to recognize handwritten digits (0-9). Built with Flask and TensorFlow, featuring both image upload and drawing canvas functionality.\n\n![Python](https://img.shields.io/badge/python-v3.8+-blue.svg)\n![Flask](https://img.shields.io/badge/flask-v2.3+-red.svg)\n![TensorFlow](https://img.shields.io/badge/tensorflow-v2.13+-orange.svg)\n![License](https://img.shields.io/badge/license-MIT-green.svg)\n\n## 🌟 Features\n\n- **📁 Image Upload**: Upload PNG/JPG images of handwritten digits\n- **✏️ Drawing Canvas**: Draw digits directly in the browser with touch support\n- **🧠 AI Prediction**: Real-time digit recognition using trained neural network\n- **📊 Confidence Scores**: View prediction probabilities for all digits (0-9)\n- 🐳 **Dockerized Deployment**: Run the app in a container with all dependencies pre-installed. Easy to deploy locally or on cloud platforms like Render, Heroku, or AWS.\n- **📱 Responsive Design**: Works seamlessly on desktop and mobile devices\n- **🎨 Modern UI**: Beautiful gradient interface with smooth animations\n\n## 🚀 Demo\n\n### Image Upload\nUpload any image containing a handwritten digit and get instant predictions:\n\n### Drawing Canvas  \nDraw digits directly in the browser:\n\n### Results Display\nView predictions with confidence scores and probability distributions:\n\n## 🌐 Live Demo\n\nTry the app online without any setup!  \n[Click here to use the Digit Recognition Web App](https://digit-recognition-app-latest.onrender.com)\n\n\n## 🛠 Installation\n\n### Prerequisites\n- Python 3.8 or higher\n- pip package manager\n\n### Setup\n\n1. **Clone the repository**\n   ```bash\n   git clone https://github.com/pushkar-112/DL-Handwritten-Digit-Recognition.git\n   cd DL-Handwritten-Digit-Recognition\n   ```\n\n2. **Create virtual environment** (recommended)\n   ```bash\n   python -m venv venv\n   source venv/bin/activate  # On Windows: venv\\Scripts\\activate\n   ```\n\n3. **Install dependencies**\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n4. **Add your trained model**\n   - Place your trained model file (`*.h5`) in the `model/` directory\n   - Rename it to `digit_recognition_model.h5` OR update the path in `app_production.py`\n\n5. **Run the application**\n   ```bash\n   python app_production.py\n   ```\n\n6. **Open your browser** and navigate to `http://localhost:5000`\n\n## 📁 Project Structure\n\n```\nDL-Handwritten-Digit-Recognition/\n├── app_production.py          # Main Flask application (production)\n├── app.py                     # Development version with debug features\n├── requirements.txt           # Python dependencies\n├── model/\n│   └── digit_recognition_model.h5   # Your trained model (add this file)\n├── templates/\n│   ├── index_production.html  # Clean production template\n│   └── index.html            # Debug template\n├── debug_model_path.py       # Model path debugging utility\n├── quick_fix.py              # Automatic path fixing utility\n└── README.md                 # This file\n```\n\n## 🔧 Configuration\n\n### Model Requirements\nYour model should:\n- Accept flattened 28×28 grayscale images (784 features)\n- Input shape: `(None, 784)`\n- Output 10 classes (digits 0-9)\n- Be saved as a `.h5` file (Keras format)\n\n### Supported Model Architecture Example\n```python\nmodel = Sequential([\n    Dense(128, activation='relu', input_shape=(784,)),\n    Dropout(0.2),\n    Dense(10, activation='softmax')\n])\n```\n\n## 🎯 Usage\n\n### Image Upload\n1. Click \"Upload Image\" section\n2. Select a PNG/JPG file containing a handwritten digit\n3. Click \"🔮 Predict from Image\"\n4. View results with confidence scores\n\n### Drawing Canvas\n1. Use mouse or touch to draw a digit in the canvas\n2. Click \"🔮 Predict from Drawing\" \n3. Use \"🗑️ Clear Canvas\" to reset and try again\n\n## 🧪 Development\n\n### Debug Mode\nFor development and troubleshooting, use the debug version:\n```bash\npython app.py\n```\n\nThis includes additional features:\n- Image preprocessing visualization\n- Debug endpoint (`/debug_image`)\n- Detailed error logging\n- Step-by-step preprocessing display\n\n### Model Path Issues\nIf you encounter model loading issues:\n```bash\npython debug_model_path.py  # Diagnose path problems\npython quick_fix.py         # Auto-fix common path issues\n```\n\n## 🔍 API Endpoints\n\n- `GET /` - Main web interface\n- `POST /predict` - Prediction endpoint\n  - Accepts: Form data with image file OR JSON with canvas data\n  - Returns: JSON with predicted digit and probabilities\n- `GET /health` - Health check endpoint\n\n### Example API Usage\n```python\nimport requests\n\n# Upload image\nwith open('digit_image.png', 'rb') as f:\n    response = requests.post('http://localhost:5000/predict', \n                           files={'file': f})\n    result = response.json()\n    print(f\"Predicted digit: {result['predicted_digit']}\")\n```\n\n## 🚀 Deployment\n\n### Local Development\n```bash\npython app_production.py\n```\n\n### Production Deployment\nThe app is ready for deployment on platforms like:\n- **Heroku**: Add `Procfile` with `web: python app_production.py`\n- **AWS EC2**: Use gunicorn with `gunicorn app_production:app`\n- **Docker**: Create Dockerfile based on Python slim image\n\n### Environment Variables (Optional)\n```bash\nexport FLASK_ENV=production\nexport MODEL_PATH=model/your_model.h5\n```\n\n## 🧠 How It Works\n\n### Image Preprocessing Pipeline\n1. **Resize** → 28×28 pixels (MNIST standard)\n2. **Grayscale** → Convert RGB to single channel\n3. **Background Detection** → Auto-invert if light background detected\n4. **Enhancement** → Increase contrast and apply thresholding\n5. **Normalization** → Scale pixel values to 0-1 range\n6. **Flattening** → Reshape to (1, 784) for model input\n\n### Model Architecture\nThe app expects a trained model with:\n- Dense layers (not convolutional)\n- Input: Flattened 28×28 images (784 features)\n- Output: 10 classes with softmax activation\n\n## 🧠 Model Details - digit_recognition_model.h5\n\n- **Dataset**: MNIST handwritten digits\n- **Architecture**: \n  - Input: Flattened 28x28 images (784 features)\n  - Dense Layer 1: 128 units, ReLU\n  - Dense Layer 2: 10 units, Softmax\n- **Training**: \n  - Optimizer: Adam\n  - Loss: Sparse Categorical Crossentropy\n  - Epochs: 10\n  - Validation split: 0.1\n  - Scaling applied: pixel values normalized to [0,1]\n- **Overfitting Mitigation**: Dropout layers used\n- **Test Accuracy**: ~98%\n- **Notebook**: [Link to the Jupyter notebook](notebooks\\HandwrittenDigitRecognitionNN.ipynb)\n\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📝 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgments\n\n- Built with [Flask](https://flask.palletsprojects.com/) web framework\n- Neural network powered by [TensorFlow](https://tensorflow.org/)\n- Inspired by the classic MNIST dataset\n- UI designed with modern CSS gradients and animations\n\n## 📞 Support\n\nIf you encounter any issues:\n\n1. **Model Loading Problems**: Run `python debug_model_path.py`\n2. **Path Issues**: Run `python quick_fix.py`\n3. **General Issues**: Check the console output for error messages\n4. **Feature Requests**: Open an issue on GitHub\n\n## 📈 Future Enhancements\n\n- [ ] Support for multi-digit numbers\n- [ ] Batch image processing\n- [ ] Model confidence thresholding\n- [ ] Export prediction results\n- [ ] Additional pre-trained models\n- [ ] REST API documentation\n- [ ] Docker containerization\n- [ ] Performance metrics dashboard\n\n---\n\n⭐ **Star this repository if you found it helpful!**\n\n**Made with ❤️ and Python** 🐍","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpushkar-112%2Fdl-handwritten-digit-recognition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpushkar-112%2Fdl-handwritten-digit-recognition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpushkar-112%2Fdl-handwritten-digit-recognition/lists"}