Spaces:
Sleeping
Sleeping
Commit ·
16d4492
1
Parent(s): 684f981
Upload folder using huggingface_hub
Browse files- server/app.py +11 -6
server/app.py
CHANGED
|
@@ -56,17 +56,21 @@ if _STATIC_DIR.is_dir():
|
|
| 56 |
from fastapi.responses import FileResponse, RedirectResponse
|
| 57 |
from fastapi.staticfiles import StaticFiles
|
| 58 |
|
| 59 |
-
# Mount the
|
| 60 |
-
app.mount("/
|
| 61 |
|
| 62 |
-
# Handle legacy system links
|
| 63 |
@app.get("/api", include_in_schema=False)
|
| 64 |
def api_docs_redirect():
|
| 65 |
return RedirectResponse(url="/docs")
|
| 66 |
|
| 67 |
@app.get("/web", include_in_schema=False)
|
| 68 |
def web_legacy_redirect():
|
| 69 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
@app.get("/", include_in_schema=False)
|
| 72 |
def serve_dashboard():
|
|
@@ -75,11 +79,12 @@ if _STATIC_DIR.is_dir():
|
|
| 75 |
|
| 76 |
# Explicitly move our custom routes to the front of the routing table
|
| 77 |
# This ensures they take precedence over any default OpenEnv/Gradio routes
|
| 78 |
-
# that might be auto-mounted at the root.
|
| 79 |
custom_routes = []
|
| 80 |
for i in range(len(app.routes) - 1, -1, -1):
|
| 81 |
r = app.routes[i]
|
| 82 |
-
if hasattr(r, "path") and
|
|
|
|
|
|
|
| 83 |
custom_routes.append(app.routes.pop(i))
|
| 84 |
|
| 85 |
for r in reversed(custom_routes):
|
|
|
|
| 56 |
from fastapi.responses import FileResponse, RedirectResponse
|
| 57 |
from fastapi.staticfiles import StaticFiles
|
| 58 |
|
| 59 |
+
# Mount the static directory at /assets or similar if needed for CSS/JS
|
| 60 |
+
app.mount("/static", StaticFiles(directory=str(_STATIC_DIR)), name="static_assets")
|
| 61 |
|
| 62 |
+
# Handle legacy system links without redirects to avoid HF proxy breakage
|
| 63 |
@app.get("/api", include_in_schema=False)
|
| 64 |
def api_docs_redirect():
|
| 65 |
return RedirectResponse(url="/docs")
|
| 66 |
|
| 67 |
@app.get("/web", include_in_schema=False)
|
| 68 |
def web_legacy_redirect():
|
| 69 |
+
return FileResponse(str(_STATIC_DIR / "index.html"))
|
| 70 |
+
|
| 71 |
+
@app.get("/playground", include_in_schema=False)
|
| 72 |
+
def serve_playground():
|
| 73 |
+
return FileResponse(str(_STATIC_DIR / "index.html"))
|
| 74 |
|
| 75 |
@app.get("/", include_in_schema=False)
|
| 76 |
def serve_dashboard():
|
|
|
|
| 79 |
|
| 80 |
# Explicitly move our custom routes to the front of the routing table
|
| 81 |
# This ensures they take precedence over any default OpenEnv/Gradio routes
|
|
|
|
| 82 |
custom_routes = []
|
| 83 |
for i in range(len(app.routes) - 1, -1, -1):
|
| 84 |
r = app.routes[i]
|
| 85 |
+
if hasattr(r, "path") and r.path in ("/", "/web", "/playground", "/api"):
|
| 86 |
+
custom_routes.append(app.routes.pop(i))
|
| 87 |
+
elif hasattr(r, "path") and r.path.startswith("/static"):
|
| 88 |
custom_routes.append(app.routes.pop(i))
|
| 89 |
|
| 90 |
for r in reversed(custom_routes):
|