devrajsinh2012 commited on
Commit
9e4f343
Β·
1 Parent(s): cf93910

chore: migrate backend deployment from Fly.io to Hugging Face Spaces

Browse files

- Dockerfile: port 8000 -> 7860 (HF Spaces requirement), use ENV PORT
- README.md: add HF Spaces YAML frontmatter, replace Fly.io deploy docs
- backend/config.py: add HF Space URL to default CORS origins
- frontend/.env.production: set VITE_WS_URL for HF Space (wss)
- frontend/.env.example: document env vars for local dev

Dockerfile CHANGED
@@ -29,7 +29,9 @@ COPY CNN_Autoencoder_LightGBM/ /models/CNN_Autoencoder_LightGBM/
29
  COPY CNN_PreTrained/ /models/CNN_PreTrained/
30
 
31
  # ── Runtime environment ───────────────────────────────────────────────────────
 
32
  ENV WEIGHTS_DIR=/models \
 
33
  KERAS_BACKEND=tensorflow \
34
  TF_CPP_MIN_LOG_LEVEL=3 \
35
  CUDA_VISIBLE_DEVICES="" \
@@ -38,11 +40,11 @@ ENV WEIGHTS_DIR=/models \
38
  PYTHONDONTWRITEBYTECODE=1 \
39
  PYTHONUNBUFFERED=1
40
 
41
- EXPOSE 8000
42
 
43
  # ── Health-check ──────────────────────────────────────────────────────────────
44
  # Wait up to 3 minutes for models to load before marking the container healthy.
45
  HEALTHCHECK --interval=30s --timeout=10s --start-period=180s --retries=3 \
46
- CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=5)"
47
 
48
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
29
  COPY CNN_PreTrained/ /models/CNN_PreTrained/
30
 
31
  # ── Runtime environment ───────────────────────────────────────────────────────
32
+ # PORT=7860 is the Hugging Face Spaces default; override with -e PORT=xxxx if needed.
33
  ENV WEIGHTS_DIR=/models \
34
+ PORT=7860 \
35
  KERAS_BACKEND=tensorflow \
36
  TF_CPP_MIN_LOG_LEVEL=3 \
37
  CUDA_VISIBLE_DEVICES="" \
 
40
  PYTHONDONTWRITEBYTECODE=1 \
41
  PYTHONUNBUFFERED=1
42
 
43
+ EXPOSE 7860
44
 
45
  # ── Health-check ──────────────────────────────────────────────────────────────
46
  # Wait up to 3 minutes for models to load before marking the container healthy.
47
  HEALTHCHECK --interval=30s --timeout=10s --start-period=180s --retries=3 \
48
+ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:${PORT}/health', timeout=5)"
49
 
50
+ CMD uvicorn app.main:app --host 0.0.0.0 --port ${PORT}
README.md CHANGED
@@ -1,3 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
1
  # SanketSetu
2
 
3
  A real-time sign language recognition system using machine learning and computer vision.
@@ -81,13 +92,62 @@ Run the development servers:
81
  .\start.ps1
82
  ```
83
 
84
- ## Docker
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- Build and run using Docker:
87
 
88
  ```bash
89
  docker build -t sanketsetu .
90
- docker run -p 8000:8000 sanketsetu
91
  ```
92
 
93
  ## Testing
 
1
+ ---
2
+ title: SanketSetu Backend
3
+ emoji: 🀟
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: docker
7
+ app_port: 7860
8
+ pinned: false
9
+ short_description: Real-time Gujarati Sign Language recognition API
10
+ ---
11
+
12
  # SanketSetu
13
 
14
  A real-time sign language recognition system using machine learning and computer vision.
 
92
  .\start.ps1
93
  ```
94
 
95
+ ## Deployment
96
+
97
+ ### Backend β€” Hugging Face Spaces (Docker SDK)
98
+
99
+ The backend is deployed as a [Hugging Face Space](https://huggingface.co/spaces) using the Docker SDK.
100
+
101
+ **Steps to create a new Space and push:**
102
+
103
+ 1. **Create the Space** on [huggingface.co/new-space](https://huggingface.co/new-space)
104
+ - SDK: **Docker**
105
+ - Visibility: Public (or Private)
106
+ - Note your `username` and `space-name`
107
+
108
+ 2. **Clone the Space repo and push your code:**
109
+ ```bash
110
+ # Add HF Space as a remote (from repo root)
111
+ git remote add space https://huggingface.co/spaces/devrajsinh2012/Sanket-Setu
112
+
113
+ git push space main
114
+ ```
115
+ HF Spaces will automatically build the Docker image and start the container.
116
+
117
+ 3. **Set Space Secrets** (via HF Space β†’ Settings β†’ Repository secrets):
118
+ | Secret | Example value |
119
+ |--------|---------------|
120
+ | `CORS_ORIGINS` | `https://sanketsetu.vercel.app,http://localhost:5173` |
121
+ | `PIPELINE_MODE` | `ensemble` |
122
+ | `CONFIDENCE_THRESHOLD` | `0.70` |
123
+
124
+ 4. **Update the frontend** β€” set the `VITE_WS_URL` Vercel environment variable:
125
+ ```
126
+ wss://devrajsinh2012-sanket-setu.hf.space
127
+ ```
128
+ In Vercel dashboard: **Settings β†’ Environment Variables β†’ VITE_WS_URL**
129
+
130
+ **Space URL format:**
131
+ - HTTPS API: `https://devrajsinh2012-sanket-setu.hf.space`
132
+ - WebSocket: `wss://devrajsinh2012-sanket-setu.hf.space/ws/landmarks`
133
+ - Health: `https://devrajsinh2012-sanket-setu.hf.space/health`
134
+
135
+ ### Frontend β€” Vercel
136
+
137
+ ```bash
138
+ cd frontend
139
+ # deploy via Vercel CLI or connect the GitHub repo in Vercel dashboard
140
+ ```
141
+
142
+ Set the `VITE_WS_URL` environment variable in Vercel to the HF Space WebSocket URL above.
143
+
144
+ ## Docker (local)
145
 
146
+ Build and run using Docker locally:
147
 
148
  ```bash
149
  docker build -t sanketsetu .
150
+ docker run -p 7860:7860 sanketsetu
151
  ```
152
 
153
  ## Testing
backend/app/config.py CHANGED
@@ -55,7 +55,14 @@ MAX_WS_CONNECTIONS: int = int(os.getenv("MAX_WS_CONNECTIONS", "100"))
55
  WS_SEND_RATE_LIMIT: int = int(os.getenv("WS_SEND_RATE_LIMIT", "15")) # max frames/sec per client
56
 
57
  # Allowed CORS origins (comma-separated list in env var)
58
- _cors_env = os.getenv("CORS_ORIGINS", "http://localhost:5173,http://localhost:3000")
 
 
 
 
 
 
 
59
  CORS_ORIGINS: list[str] = [o.strip() for o in _cors_env.split(",") if o.strip()]
60
 
61
  # ---------------------------------------------------------------------------
 
55
  WS_SEND_RATE_LIMIT: int = int(os.getenv("WS_SEND_RATE_LIMIT", "15")) # max frames/sec per client
56
 
57
  # Allowed CORS origins (comma-separated list in env var)
58
+ # Default includes Vercel frontend and the Hugging Face Space URL.
59
+ # Replace YOUR_HF_USERNAME and YOUR_SPACE_NAME with your actual HF values.
60
+ _cors_env = os.getenv(
61
+ "CORS_ORIGINS",
62
+ "http://localhost:5173,http://localhost:3000,"
63
+ "https://sanketsetu.vercel.app,"
64
+ "https://devrajsinh2012-sanket-setu.hf.space",
65
+ )
66
  CORS_ORIGINS: list[str] = [o.strip() for o in _cors_env.split(",") if o.strip()]
67
 
68
  # ---------------------------------------------------------------------------
frontend/.env.example ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Frontend environment variables β€” copy this file to .env.local for local development
2
+ # (Vite loads .env.local automatically; never commit .env.local)
3
+
4
+ # WebSocket URL of the backend server.
5
+ # For local development (backend running on default port):
6
+ VITE_WS_URL=ws://localhost:8000
7
+
8
+ # For production (Hugging Face Spaces backend):
9
+ # VITE_WS_URL=wss://devrajsinh2012-sanket-setu.hf.space
frontend/.env.production ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Production environment β€” used by Vercel when building the frontend.
2
+ # Replace YOUR_HF_USERNAME and YOUR_SPACE_NAME with your actual Hugging Face values.
3
+ # The URL format is: https://{username}-{space-name}.hf.space
4
+ #
5
+ # Example: if your HF username is "devrajsinh" and the Space is named "sanketsetu-backend"
6
+ # VITE_WS_URL=wss://devrajsinh-sanketsetu-backend.hf.space
7
+ VITE_WS_URL=wss://devrajsinh2012-sanket-setu.hf.space