Spaces:
Running
on
Zero
Running
on
Zero
Fix: Append API routes instead of inserting to preserve Gradio static asset routes
Browse files
app.py
CHANGED
|
@@ -505,11 +505,13 @@ with gr.Blocks(
|
|
| 505 |
gradio_app.queue(max_size=8)
|
| 506 |
|
| 507 |
# Add routes after Blocks context when router is definitely ready
|
|
|
|
| 508 |
try:
|
| 509 |
if hasattr(gradio_app, '_api_handlers'):
|
| 510 |
from starlette.routing import Route
|
| 511 |
for path, handler, methods in gradio_app._api_handlers:
|
| 512 |
-
|
|
|
|
| 513 |
print(f"FastAPI routes added after Blocks context. Total routes: {len(gradio_app.app.router.routes)}")
|
| 514 |
# Clean up
|
| 515 |
del gradio_app._api_handlers
|
|
|
|
| 505 |
gradio_app.queue(max_size=8)
|
| 506 |
|
| 507 |
# Add routes after Blocks context when router is definitely ready
|
| 508 |
+
# Append routes instead of inserting to avoid interfering with Gradio's static asset routes
|
| 509 |
try:
|
| 510 |
if hasattr(gradio_app, '_api_handlers'):
|
| 511 |
from starlette.routing import Route
|
| 512 |
for path, handler, methods in gradio_app._api_handlers:
|
| 513 |
+
# Append routes so Gradio's routes (especially /_app/*) are checked first
|
| 514 |
+
gradio_app.app.router.routes.append(Route(path, handler, methods=methods))
|
| 515 |
print(f"FastAPI routes added after Blocks context. Total routes: {len(gradio_app.app.router.routes)}")
|
| 516 |
# Clean up
|
| 517 |
del gradio_app._api_handlers
|