RamshaAnwar commited on
Commit
b7bda5c
·
1 Parent(s): f06652d

fix(hf): mount fastapi into gradio instead of running uvicorn manually

Browse files
Files changed (1) hide show
  1. app.py +5 -17
app.py CHANGED
@@ -1,25 +1,13 @@
1
  import gradio as gr
2
  from app.main import app as fastapi_app
3
- import uvicorn
4
-
5
- def health_check(name):
6
- return f"Hello {name}! The ContextQuery API is running."
7
 
 
8
  demo = gr.Interface(
9
- fn=health_check,
10
  inputs="text",
11
  outputs="text",
12
- title="ContextQuery AI Backend",
13
- description="This is the backend API for ContextQuery AI."
14
  )
15
 
16
- # Mount Gradio into FastAPI
17
- app = gr.mount_gradio_app(fastapi_app, demo, path="/")
18
-
19
- # Override the launch method.
20
- # Hugging Face's runner automatically calls demo.launch().
21
- # We replace it with our own function that starts the FastAPI server instead.
22
- def custom_launch(*args, **kwargs):
23
- uvicorn.run(app, host="0.0.0.0", port=7860)
24
-
25
- demo.launch = custom_launch
 
1
  import gradio as gr
2
  from app.main import app as fastapi_app
 
 
 
 
3
 
4
+ # Create a dummy UI so Gradio has something to launch
5
  demo = gr.Interface(
6
+ fn=lambda x: "ContextQuery API is running",
7
  inputs="text",
8
  outputs="text",
9
+ title="ContextQuery AI Backend"
 
10
  )
11
 
12
+ # Mount the FastAPI app directly onto the Gradio app's server
13
+ demo.app.mount("/", fastapi_app)