Spaces:
Sleeping
Sleeping
Commit ·
3480927
1
Parent(s): c27fef7
Update: Added catch-all routing for robust landing page visibility on Hugging Face
Browse files
classifier_service/api.py
CHANGED
|
@@ -17,7 +17,7 @@ app = FastAPI(title="Bacsense 2.0 API")
|
|
| 17 |
# Setup CORS to allow requests from the React frontend
|
| 18 |
app.add_middleware(
|
| 19 |
CORSMiddleware,
|
| 20 |
-
allow_origins=["*"],
|
| 21 |
allow_credentials=True,
|
| 22 |
allow_methods=["*"],
|
| 23 |
allow_headers=["*"],
|
|
@@ -49,6 +49,14 @@ async def root():
|
|
| 49 |
</html>
|
| 50 |
"""
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Global classifier instance
|
| 53 |
CLASSIFIER = None
|
| 54 |
|
|
|
|
| 17 |
# Setup CORS to allow requests from the React frontend
|
| 18 |
app.add_middleware(
|
| 19 |
CORSMiddleware,
|
| 20 |
+
allow_origins=["*"],
|
| 21 |
allow_credentials=True,
|
| 22 |
allow_methods=["*"],
|
| 23 |
allow_headers=["*"],
|
|
|
|
| 49 |
</html>
|
| 50 |
"""
|
| 51 |
|
| 52 |
+
# Catch-all route to resolve any routing issues on Hugging Face
|
| 53 |
+
@app.get("/{path_name:path}", response_class=HTMLResponse)
|
| 54 |
+
async def catch_all(path_name: str):
|
| 55 |
+
# If the user is trying to reach docs or health, let those routes handle it
|
| 56 |
+
if path_name in ["docs", "redoc", "openapi.json", "health", "debug_model", "predict_batch"]:
|
| 57 |
+
raise HTTPException(status_code=404)
|
| 58 |
+
return await root()
|
| 59 |
+
|
| 60 |
# Global classifier instance
|
| 61 |
CLASSIFIER = None
|
| 62 |
|