Priyansh Saxena commited on
Commit
cddce69
·
1 Parent(s): 9e7df56

FIX: Use absolute paths for static files and templates in HF Spaces (enables CSS loading)

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -29,9 +29,14 @@ app = FastAPI(
29
  version="2.0.0"
30
  )
31
 
 
 
 
 
 
32
  # Mount static files and templates
33
- app.mount("/static", StaticFiles(directory="static"), name="static")
34
- templates = Jinja2Templates(directory="templates")
35
 
36
  # Pydantic models
37
  class QueryRequest(BaseModel):
 
29
  version="2.0.0"
30
  )
31
 
32
+ # Get absolute paths for static files and templates (handles HF Spaces deployment)
33
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
34
+ STATIC_DIR = os.path.join(BASE_DIR, "static")
35
+ TEMPLATES_DIR = os.path.join(BASE_DIR, "templates")
36
+
37
  # Mount static files and templates
38
+ app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
39
+ templates = Jinja2Templates(directory=TEMPLATES_DIR)
40
 
41
  # Pydantic models
42
  class QueryRequest(BaseModel):