Maxwell commited on
Fix: run uvicorn directly + use root_path='' to fix Gradio UI on HF Spaces
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from fastapi.responses import StreamingResponse, JSONResponse
|
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List, Optional
|
| 8 |
import json
|
|
|
|
| 9 |
|
| 10 |
model_path = hf_hub_download(
|
| 11 |
repo_id="RavikxxBGamin/MinecraftAI-Chat",
|
|
@@ -88,7 +89,7 @@ demo = gr.ChatInterface(
|
|
| 88 |
chatbot=gr.Chatbot(height=400, show_label=False),
|
| 89 |
)
|
| 90 |
|
| 91 |
-
# Create FastAPI app
|
| 92 |
fastapi_app = FastAPI()
|
| 93 |
|
| 94 |
|
|
@@ -138,5 +139,9 @@ def chat_completions_no_prefix(req: ChatRequest):
|
|
| 138 |
return chat_completions(req)
|
| 139 |
|
| 140 |
|
| 141 |
-
# Mount Gradio
|
|
|
|
| 142 |
app = gr.mount_gradio_app(fastapi_app, demo, path="/", root_path="")
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List, Optional
|
| 8 |
import json
|
| 9 |
+
import uvicorn
|
| 10 |
|
| 11 |
model_path = hf_hub_download(
|
| 12 |
repo_id="RavikxxBGamin/MinecraftAI-Chat",
|
|
|
|
| 89 |
chatbot=gr.Chatbot(height=400, show_label=False),
|
| 90 |
)
|
| 91 |
|
| 92 |
+
# Create standalone FastAPI app for OpenAI-compatible endpoints
|
| 93 |
fastapi_app = FastAPI()
|
| 94 |
|
| 95 |
|
|
|
|
| 139 |
return chat_completions(req)
|
| 140 |
|
| 141 |
|
| 142 |
+
# Mount Gradio onto the FastAPI app
|
| 143 |
+
# root_path="" ensures static assets are served correctly on HuggingFace Spaces
|
| 144 |
app = gr.mount_gradio_app(fastapi_app, demo, path="/", root_path="")
|
| 145 |
+
|
| 146 |
+
# Start the server (runs both Gradio UI and FastAPI endpoints)
|
| 147 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|