Spaces:
Sleeping
Sleeping
cyberai-1 commited on
Commit ·
9992528
1
Parent(s): ba646e4
Only essentials
Browse files
README.md
CHANGED
|
@@ -51,3 +51,102 @@ For production, set a strong secret:
|
|
| 51 |
```text
|
| 52 |
SECRET_KEY=your-secret-value
|
| 53 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
```text
|
| 52 |
SECRET_KEY=your-secret-value
|
| 53 |
```
|
| 54 |
+
|
| 55 |
+
## Docker Deployment
|
| 56 |
+
|
| 57 |
+
### Prerequisites
|
| 58 |
+
- Docker installed on your system
|
| 59 |
+
- Docker Hub account (for pushing to registry)
|
| 60 |
+
- All project files including `traffic_classifier.h5`
|
| 61 |
+
|
| 62 |
+
### Building Docker Image
|
| 63 |
+
|
| 64 |
+
Build the Docker image locally:
|
| 65 |
+
|
| 66 |
+
```bash
|
| 67 |
+
docker build -t traffic-sign-classifier:latest .
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### Running Docker Container Locally
|
| 71 |
+
|
| 72 |
+
Run the container on your local machine:
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
docker run -p 7860:7860 \
|
| 76 |
+
-e SECRET_KEY=your-secret-key \
|
| 77 |
+
-v $(pwd)/instance:/app/instance \
|
| 78 |
+
traffic-sign-classifier:latest
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
Then access the application at `http://localhost:7860`.
|
| 82 |
+
|
| 83 |
+
### Pushing to Docker Hub
|
| 84 |
+
|
| 85 |
+
1. Tag the image:
|
| 86 |
+
```bash
|
| 87 |
+
docker tag traffic-sign-classifier:latest yourusername/traffic-sign-classifier:latest
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
2. Push to Docker Hub:
|
| 91 |
+
```bash
|
| 92 |
+
docker login
|
| 93 |
+
docker push yourusername/traffic-sign-classifier:latest
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
### Deploying to Hugging Face Spaces
|
| 97 |
+
|
| 98 |
+
1. Create a new Space on [Hugging Face Spaces](https://huggingface.co/spaces)
|
| 99 |
+
2. Select **Docker** as the SDK
|
| 100 |
+
3. In the Space settings, set environment variable:
|
| 101 |
+
- `SECRET_KEY=your-production-secret`
|
| 102 |
+
4. Upload your project files including:
|
| 103 |
+
- `Dockerfile`
|
| 104 |
+
- `app.py`
|
| 105 |
+
- `requirements.txt`
|
| 106 |
+
- `traffic_classifier.h5`
|
| 107 |
+
- `templates/` directory
|
| 108 |
+
- `static/` directory
|
| 109 |
+
|
| 110 |
+
5. Hugging Face will automatically build and deploy the container
|
| 111 |
+
6. Your app will be accessible at `https://huggingface.co/spaces/YOUR-USERNAME/YOUR-SPACE-NAME`
|
| 112 |
+
|
| 113 |
+
### Docker Compose (Optional)
|
| 114 |
+
|
| 115 |
+
Create a `docker-compose.yml` for local development:
|
| 116 |
+
|
| 117 |
+
```yaml
|
| 118 |
+
version: '3.8'
|
| 119 |
+
services:
|
| 120 |
+
traffic-classifier:
|
| 121 |
+
build: .
|
| 122 |
+
ports:
|
| 123 |
+
- "7860:7860"
|
| 124 |
+
environment:
|
| 125 |
+
- SECRET_KEY=dev-secret-key
|
| 126 |
+
- FLASK_ENV=development
|
| 127 |
+
volumes:
|
| 128 |
+
- ./instance:/app/instance
|
| 129 |
+
- ./templates:/app/templates
|
| 130 |
+
- ./static:/app/static
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
Run with:
|
| 134 |
+
```bash
|
| 135 |
+
docker-compose up
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
### Persistent Data
|
| 139 |
+
|
| 140 |
+
The SQLite database is stored in the `instance/` directory, which is mounted as a volume. This ensures data persists across container restarts.
|
| 141 |
+
|
| 142 |
+
### Health Check
|
| 143 |
+
|
| 144 |
+
To verify the container is running:
|
| 145 |
+
|
| 146 |
+
```bash
|
| 147 |
+
curl http://localhost:7860/
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
You should receive the welcome page HTML.
|
| 151 |
+
|
| 152 |
+
`
|
app.py
CHANGED
|
@@ -80,7 +80,7 @@ TRAFFIC_SIGN_CLASSES = [
|
|
| 80 |
|
| 81 |
|
| 82 |
app = Flask(__name__)
|
| 83 |
-
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "
|
| 84 |
app.config["MAX_CONTENT_LENGTH"] = 8 * 1024 * 1024
|
| 85 |
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
|
| 86 |
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
app = Flask(__name__)
|
| 83 |
+
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "a7f69cd2-a2a7-4daa-85a0-984f44fcecea")
|
| 84 |
app.config["MAX_CONTENT_LENGTH"] = 8 * 1024 * 1024
|
| 85 |
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
|
| 86 |
|