Mehdi commited on
Commit
2d50118
·
1 Parent(s): 008db30

fix: inject /blog into Gradio's internal FastAPI router at position 0

Browse files

gr.mount_gradio_app + uvicorn was ignored by HF Spaces (expects demo.launch).
Use prevent_thread_lock=True to get the live FastAPI app, then insert the
static-files Mount at index 0 so it is checked before Gradio's catch-all.

Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1077,9 +1077,15 @@ with gr.Blocks(title="PaperProf", css=CSS) as demo:
1077
  print("✅ Gradio demo defined successfully")
1078
 
1079
  print("✅ Launching demo...")
1080
- _fastapi = FastAPI()
1081
- _fastapi.mount("/blog", StaticFiles(directory="blog", html=True), name="blog")
1082
- app = gr.mount_gradio_app(_fastapi, demo, path="/")
1083
-
1084
- if __name__ == "__main__":
1085
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
1077
  print("✅ Gradio demo defined successfully")
1078
 
1079
  print("✅ Launching demo...")
1080
+ app, local_url, _ = demo.launch(
1081
+ server_name="0.0.0.0",
1082
+ server_port=7860,
1083
+ prevent_thread_lock=True,
1084
+ )
1085
+
1086
+ # Insert /blog BEFORE Gradio's catch-all route so it takes priority
1087
+ from starlette.routing import Mount
1088
+ app.router.routes.insert(0, Mount("/blog", StaticFiles(directory="blog", html=True), name="blog"))
1089
+ print(f"✅ Blog mounted at {local_url}blog")
1090
+
1091
+ demo.block_thread()