Spaces:
Sleeping
Sleeping
Commit ·
4857315
1
Parent(s): 424fc1b
Fix the loading of static frontend assets
Browse files- backend/app.py +15 -4
backend/app.py
CHANGED
|
@@ -19,10 +19,11 @@ app.add_middleware(
|
|
| 19 |
allow_headers=["*"],
|
| 20 |
)
|
| 21 |
|
| 22 |
-
# Mount static files
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
# Load tokenizer and BERT model
|
| 28 |
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
|
@@ -81,4 +82,14 @@ def generate(text: str):
|
|
| 81 |
|
| 82 |
@app.get("/")
|
| 83 |
async def read_index():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
return FileResponse("frontend/index.html")
|
|
|
|
| 19 |
allow_headers=["*"],
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# Mount static files for React app assets (CSS, JS)
|
| 23 |
+
app.mount("/assets", StaticFiles(directory="frontend/assets"), name="assets")
|
| 24 |
+
|
| 25 |
+
# Mount other static files (images, etc.)
|
| 26 |
+
app.mount("/static", StaticFiles(directory="frontend"), name="static")
|
| 27 |
|
| 28 |
# Load tokenizer and BERT model
|
| 29 |
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
|
|
|
| 82 |
|
| 83 |
@app.get("/")
|
| 84 |
async def read_index():
|
| 85 |
+
return FileResponse("frontend/index.html")
|
| 86 |
+
|
| 87 |
+
@app.get("/{file_path:path}")
|
| 88 |
+
async def serve_static_files(file_path: str):
|
| 89 |
+
"""Serve static files from frontend directory"""
|
| 90 |
+
import os
|
| 91 |
+
full_path = f"frontend/{file_path}"
|
| 92 |
+
if os.path.exists(full_path) and os.path.isfile(full_path):
|
| 93 |
+
return FileResponse(full_path)
|
| 94 |
+
# If file not found, serve index.html for React Router
|
| 95 |
return FileResponse("frontend/index.html")
|