Spaces:
Runtime error
Runtime error
Commit ·
b7bda5c
1
Parent(s): f06652d
fix(hf): mount fastapi into gradio instead of running uvicorn manually
Browse files
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=
|
| 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
|
| 17 |
-
app
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|