How arceusomkar7/digit-recognizer works
Project type and purpose
• This is a lightweight full-stack web application (“Digit Recognizer”) that uses FastAPI on the backend to serve a single-page front-end (HTML + Tailwind + Canvas API). It exposes endpoints for accepting drawn or uploaded images and returning digit predictions powered by pre-trained scikit-learn models (KNN, SVM, etc.).
File structure
• Top level:
• run.py – entry script to launch the app (likely wraps uvicorn).
• requirements.txt – Python dependencies (FastAPI, joblib, scikit-learn, etc.).
• mnist.ipynb – exploratory notebook (development only).
• models/ – directory holding serialized model artifacts (joblib files).
• app/ – main application package:
– main.py – FastAPI app, routing, prediction logic.
– static/ – contains index.html (front-end assets; could host CSS/JS).
• No database or external microservices—pure in-memory ML inference.
README
• Confirms FastAPI backend, HTML/Tailwind/CANVAS front end, running via uvicorn.
• Describes usage flow: user draws or uploads image → choose model → see result.
• Lists dependencies and performance metrics for KNN and SVM.
a. Main components
• Client (Browser) – runs index.html, Canvas API + Tailwind UI.
• FastAPI Server – HTTP API endpoints: /home (serves UI), /predict (accepts image + model choice).
• Model Loader & Predictor – loads .joblib files from models/ on startup or per request; handles preprocessing.
• Joblib Models – KNN, SVM (and any others) serialized in models/.
• (Optional) Development Notebook – separate component for data exploration; not in production.
b. Relationships and interactions
• Browser → (HTTP POST) → /predict endpoint, sending image payload + model parameter.
• FastAPI → Model Loader → selected .joblib model → Prediction result.
• FastAPI → HTTP Response → JSON { digit: n, confidence: x }.
• Browser ← Response ← displays result on canvas/UI.
• Browser requests index.html and any CSS/JS via HTTP GET at /home (or root).
c. Architectural patterns
• MVC-like separation:
– V (View): static HTML/CSS/JS in app/static.
– C (Controller): FastAPI routes in main.py.
– M (Model): ML model artifacts (.joblib) + prediction logic.
• Single service (monolith), no external DB.
• Pre-trained models loaded at startup for low-latency inference.
d. Key technologies
• FastAPI (Python web framework)
• Uvicorn (ASGI server)
• scikit-learn, joblib (model serialization/inference)
• HTML + Tailwind CSS + Canvas API (frontend)
Essential elements
• Component labels (e.g., “Canvas API”, “SVM Model.joblib”).
• Optional: annotate ports (8000) and file locations (app/static, models/).