Spaces:
Sleeping
Sleeping
Commit Β·
3b38e31
1
Parent(s): 04e68fe
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,2 +1,125 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MNIST Draw-and-Predict Digit Classifier
|
| 2 |
+
|
| 3 |
+
A web app where users can **draw digits (0β9)** on a canvas and get predictions from a **PyTorch-trained MNIST model**.
|
| 4 |
+
The app uses **FastAPI** for the backend (image processing + prediction) and **Gradio** for the frontend (drawing canvas).
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
## π§ Model
|
| 9 |
+
|
| 10 |
+
- PyTorch CNN trained on MNIST
|
| 11 |
+
- Achieves **~98.7% accuracy**
|
| 12 |
+
- Saved as `model.pt` in the backend folder
|
| 13 |
+
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
## π Project Structure
|
| 17 |
+
|
| 18 |
+
```
|
| 19 |
+
digit_classifier/
|
| 20 |
+
βββ backend/
|
| 21 |
+
β βββ main.py # FastAPI backend
|
| 22 |
+
β βββ model.pt # Trained MNIST model
|
| 23 |
+
β βββ requirements.txt
|
| 24 |
+
βββ frontend/
|
| 25 |
+
β βββ app.py # Gradio frontend
|
| 26 |
+
β βββ requirements.txt
|
| 27 |
+
βββ launch_all.py # Starts backend + frontend together
|
| 28 |
+
βββ Dockerfile # For Hugging Face Docker deployment
|
| 29 |
+
βββ README.md
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## β‘ Features
|
| 35 |
+
|
| 36 |
+
- Draw digits on a canvas
|
| 37 |
+
- Predicts digit and confidence
|
| 38 |
+
- Automatically inverts colors to match MNIST style
|
| 39 |
+
- Deployable with Docker or Hugging Face Spaces
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## π Local Setup
|
| 44 |
+
|
| 45 |
+
1. **Clone the repository:**
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
git clone <repo-url>
|
| 49 |
+
cd digit_classifier
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
2. **Install dependencies (backend + frontend):**
|
| 53 |
+
|
| 54 |
+
```bash
|
| 55 |
+
# Backend
|
| 56 |
+
cd backend
|
| 57 |
+
pip install -r requirements.txt
|
| 58 |
+
|
| 59 |
+
# Frontend
|
| 60 |
+
cd ../frontend
|
| 61 |
+
pip install -r requirements.txt
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
3. **Run the app:**
|
| 65 |
+
|
| 66 |
+
```bash
|
| 67 |
+
# Start backend (FastAPI)
|
| 68 |
+
cd ../backend
|
| 69 |
+
uvicorn main:app --reload
|
| 70 |
+
|
| 71 |
+
# In another terminal, start frontend (Gradio)
|
| 72 |
+
cd ../frontend
|
| 73 |
+
python app.py
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
4. **Open your browser:** [http://localhost:7860](http://localhost:7860)
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## π³ Docker Deployment
|
| 81 |
+
|
| 82 |
+
Make sure `Dockerfile` and `launch_all.py` are in the root directory.
|
| 83 |
+
|
| 84 |
+
**Build and run the container:**
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
docker build -t mnist-draw-app .
|
| 88 |
+
docker run -p 7860:7860 mnist-draw-app
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
**Open browser:** [http://localhost:7860](http://localhost:7860)
|
| 92 |
+
|
| 93 |
+
---
|
| 94 |
+
|
| 95 |
+
## π Hugging Face Deployment
|
| 96 |
+
|
| 97 |
+
1. Create a Hugging Face account: [https://huggingface.co/join](https://huggingface.co/join)
|
| 98 |
+
2. Create a new Space and select **Docker** as the runtime.
|
| 99 |
+
3. Push your repo:
|
| 100 |
+
|
| 101 |
+
```bash
|
| 102 |
+
git lfs install
|
| 103 |
+
git init
|
| 104 |
+
git remote add origin https://huggingface.co/spaces/<username>/<space_name>.git
|
| 105 |
+
git add .
|
| 106 |
+
git commit -m "Initial commit"
|
| 107 |
+
git push origin main
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
Hugging Face will automatically build the container and provide a public URL for your app.
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
## πΉ Notes
|
| 115 |
+
|
| 116 |
+
- Ensure `model.pt` is in the `backend/` folder before deploying.
|
| 117 |
+
- FastAPI handles image upload and prediction; Gradio is purely frontend.
|
| 118 |
+
- Canvas images are automatically inverted to match MNIST's white-on-black style.
|
| 119 |
+
- For large models, consider using HF model hosting and downloading at runtime to save space.
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## π¨βπ» Author
|
| 124 |
+
|
| 125 |
+
**Abdul Rafay** β Computer Science student at ITU, building AI-powered web apps.
|