Spaces:
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
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:
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:
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:
docker build -t traffic-sign-classifier:latest .
Running Docker Container Locally
Run the container on your local machine:
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
- Tag the image:
docker tag traffic-sign-classifier:latest yourusername/traffic-sign-classifier:latest
- Push to Docker Hub:
docker login
docker push yourusername/traffic-sign-classifier:latest
Deploying to Hugging Face Spaces
Create a new Space on Hugging Face Spaces
Select Docker as the SDK
In the Space settings, set environment variable:
SECRET_KEY=your-production-secret
Upload your project files including:
Dockerfileapp.pyrequirements.txttraffic_classifier.h5templates/directorystatic/directory
Hugging Face will automatically build and deploy the container
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:
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:
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:
curl http://localhost:7860/
You should receive the welcome page HTML.
`