Spaces:
Sleeping
Sleeping
| title: Traffic Sign Classification | |
| emoji: 🐠 | |
| colorFrom: purple | |
| colorTo: green | |
| sdk: docker | |
| pinned: false | |
| # Traffic Sign Classifier Flask App | |
| This project deploys a `traffic_classifier.h5` model as a Flask web app for Hugging Face Spaces with Docker. | |
| ## Features | |
| - Welcome page based on the provided visual template direction | |
| - Login and registration | |
| - Protected traffic sign prediction page | |
| - SQLite storage inside the container at `instance/traffic_signs.sqlite3` | |
| - Per-user prediction history | |
| - True/false feedback for every prediction | |
| - Dashboard with total predictions, reviewed predictions, true/false counts, and feedback accuracy | |
| ## Run Locally | |
| ```bash | |
| python -m venv .venv | |
| source .venv/bin/activate | |
| pip install -r requirements.txt | |
| python app.py | |
| ``` | |
| Open `http://localhost:7860`. | |
| ## Model | |
| Place the trained model in the project root: | |
| ```text | |
| traffic_classifier.h5 | |
| ``` | |
| The app expects a 43-class traffic sign classifier using 30x30 RGB images, matching the common GTSRB class list. | |
| ## Hugging Face Space | |
| This Space uses Docker and exposes port `7860`. | |
| For production, set a strong secret: | |
| ```text | |
| SECRET_KEY=your-secret-value | |
| ``` | |
| ## Docker Deployment | |
| ### Prerequisites | |
| - Docker installed on your system | |
| - Docker Hub account (for pushing to registry) | |
| - All project files including `traffic_classifier.h5` | |
| ### Building Docker Image | |
| Build the Docker image locally: | |
| ```bash | |
| docker build -t traffic-sign-classifier:latest . | |
| ``` | |
| ### Running Docker Container Locally | |
| Run the container on your local machine: | |
| ```bash | |
| docker run -p 7860:7860 \ | |
| -e SECRET_KEY=your-secret-key \ | |
| -v $(pwd)/instance:/app/instance \ | |
| traffic-sign-classifier:latest | |
| ``` | |
| Then access the application at `http://localhost:7860`. | |
| ### Pushing to Docker Hub | |
| 1. Tag the image: | |
| ```bash | |
| docker tag traffic-sign-classifier:latest yourusername/traffic-sign-classifier:latest | |
| ``` | |
| 2. Push to Docker Hub: | |
| ```bash | |
| docker login | |
| docker push yourusername/traffic-sign-classifier:latest | |
| ``` | |
| ### Deploying to Hugging Face Spaces | |
| 1. Create a new Space on [Hugging Face Spaces](https://huggingface.co/spaces) | |
| 2. Select **Docker** as the SDK | |
| 3. In the Space settings, set environment variable: | |
| - `SECRET_KEY=your-production-secret` | |
| 4. Upload your project files including: | |
| - `Dockerfile` | |
| - `app.py` | |
| - `requirements.txt` | |
| - `traffic_classifier.h5` | |
| - `templates/` directory | |
| - `static/` directory | |
| 5. Hugging Face will automatically build and deploy the container | |
| 6. Your app will be accessible at `https://huggingface.co/spaces/YOUR-USERNAME/YOUR-SPACE-NAME` | |
| ### Docker Compose (Optional) | |
| Create a `docker-compose.yml` for local development: | |
| ```yaml | |
| version: '3.8' | |
| services: | |
| traffic-classifier: | |
| build: . | |
| ports: | |
| - "7860:7860" | |
| environment: | |
| - SECRET_KEY=dev-secret-key | |
| - FLASK_ENV=development | |
| volumes: | |
| - ./instance:/app/instance | |
| - ./templates:/app/templates | |
| - ./static:/app/static | |
| ``` | |
| Run with: | |
| ```bash | |
| docker-compose up | |
| ``` | |
| ### Persistent Data | |
| The SQLite database is stored in the `instance/` directory, which is mounted as a volume. This ensures data persists across container restarts. | |
| ### Health Check | |
| To verify the container is running: | |
| ```bash | |
| curl http://localhost:7860/ | |
| ``` | |
| You should receive the welcome page HTML. | |
| ` | |