soorajaryan007 commited on
Commit
a154b61
·
verified ·
1 Parent(s): cad9a39

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Hugging Face Space entrypoint.
3
+ Serves FastAPI backend + static frontend from a single process.
4
+
5
+ HF Spaces expects the app to listen on port 7860.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ # Make sure backend package is importable
13
+ sys.path.insert(0, str(Path(__file__).parent / "backend"))
14
+
15
+ from fastapi import FastAPI, HTTPException, Request
16
+ from fastapi.staticfiles import StaticFiles
17
+ from fastapi.responses import HTMLResponse, FileResponse
18
+ import uvicorn
19
+
20
+ # Import the backend app and patch in the Groq key from HF secrets / env
21
+ from backend.main import app, rag
22
+
23
+ # Mount the frontend
24
+ frontend_path = Path(__file__).parent / "frontend"
25
+ app.mount("/static", StaticFiles(directory=str(frontend_path)), name="static")
26
+
27
+ # Override root to serve index.html
28
+ @app.get("/", response_class=HTMLResponse, include_in_schema=False)
29
+ async def serve_frontend():
30
+ return FileResponse(str(frontend_path / "index.html"))
31
+
32
+
33
+ if __name__ == "__main__":
34
+ # HF Spaces uses port 7860
35
+ port = int(os.environ.get("PORT", 7860))
36
+ uvicorn.run(
37
+ "app:app",
38
+ host="0.0.0.0",
39
+ port=port,
40
+ reload=False,
41
+ log_level="info",
42
+ )