jawaduddin commited on
Commit
5abcb04
·
1 Parent(s): 51c9c0c

Setup automated Hugging Face deployment via GitHub Actions

Browse files
.github/workflows/deploy_to_hf.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face Hub
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ sync-to-hub:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ with:
14
+ fetch-depth: 0
15
+ lfs: true
16
+ - name: Push to Hub
17
+ env:
18
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
+ run: |
20
+ git push https://udidin:$HF_TOKEN@huggingface.co/spaces/BugHu/voice-detector main
Dockerfile CHANGED
@@ -23,9 +23,9 @@ RUN pip install --no-cache-dir -r requirements.txt
23
  COPY . .
24
 
25
  # Expose the port the app runs on
26
- # Standard port for Koyeb/Render
27
- ENV PORT=8000
28
- EXPOSE 8000
29
 
30
  # Run the application
31
  CMD ["python", "backend/main.py"]
 
23
  COPY . .
24
 
25
  # Expose the port the app runs on
26
+ # Hugging Face Spaces defaults to 7860
27
+ ENV PORT=7860
28
+ EXPOSE 7860
29
 
30
  # Run the application
31
  CMD ["python", "backend/main.py"]
backend/main.py CHANGED
@@ -58,24 +58,6 @@ feature_extractor = FeatureExtractor(sr=16000)
58
  voice_classifier = VoiceClassifier()
59
  explainer = VoiceExplainer()
60
 
61
- # Serve static files
62
- # Find the absolute path to the frontend directory
63
- frontend_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "frontend")
64
- if os.path.exists(frontend_path):
65
- app.mount("/static", StaticFiles(directory=frontend_path), name="static")
66
-
67
- @app.get("/")
68
- async def read_index():
69
- return FileResponse(os.path.join(frontend_path, "index.html"))
70
-
71
- # Also serve other html files at root level for convenience
72
- @app.get("/{page}.html")
73
- async def read_html(page: str):
74
- file_path = os.path.join(frontend_path, f"{page}.html")
75
- if os.path.exists(file_path):
76
- return FileResponse(file_path)
77
- raise HTTPException(status_code=404, detail="Page not found")
78
-
79
 
80
  # Request/Response models
81
  class VoiceDetectionRequest(BaseModel):
@@ -233,7 +215,7 @@ async def shutdown_event():
233
 
234
 
235
  # Health check endpoint
236
- @app.get("/")
237
  async def root():
238
  """Health check endpoint"""
239
  return {
@@ -599,6 +581,12 @@ async def get_prediction_history(
599
  detail="Failed to retrieve prediction history"
600
  )
601
 
 
 
 
 
 
 
602
 
603
 
604
  if __name__ == "__main__":
 
58
  voice_classifier = VoiceClassifier()
59
  explainer = VoiceExplainer()
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  # Request/Response models
63
  class VoiceDetectionRequest(BaseModel):
 
215
 
216
 
217
  # Health check endpoint
218
+ @app.get("/api/health")
219
  async def root():
220
  """Health check endpoint"""
221
  return {
 
581
  detail="Failed to retrieve prediction history"
582
  )
583
 
584
+ # Serve static files
585
+ # This is placed at the end so it doesn't intercept API routes
586
+ frontend_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "frontend")
587
+ if os.path.exists(frontend_path):
588
+ # Mount frontend files at root
589
+ app.mount("/", StaticFiles(directory=frontend_path, html=True), name="frontend")
590
 
591
 
592
  if __name__ == "__main__":