File size: 3,299 Bytes
b5f3cb8
 
 
 
 
 
 
 
 
6bf9e00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9992528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
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.

`