Spaces:
Runtime error
Runtime error
Commit Β·
0c68577
1
Parent(s): a8d4641
Expose API routes through ZeroGPU Gradio launcher
Browse files
app.py
CHANGED
|
@@ -5,8 +5,8 @@ import uuid
|
|
| 5 |
import asyncio
|
| 6 |
import threading
|
| 7 |
import queue as queue_mod
|
| 8 |
-
import uvicorn
|
| 9 |
import gradio as gr
|
|
|
|
| 10 |
from fastapi import FastAPI, Request
|
| 11 |
from fastapi.responses import StreamingResponse, JSONResponse
|
| 12 |
from huggingface_hub import hf_hub_download
|
|
@@ -127,6 +127,12 @@ def _load_model():
|
|
| 127 |
threading.Thread(target=_load_model, daemon=True).start()
|
| 128 |
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
# ββ Gradio chat helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 131 |
|
| 132 |
def user_submit(message, history):
|
|
@@ -333,9 +339,10 @@ with gr.Blocks(title="Lumen \u2014 Axion Labs") as demo:
|
|
| 333 |
|
| 334 |
|
| 335 |
# ββ FastAPI routes ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 336 |
-
# Gradio 6
|
| 337 |
-
#
|
| 338 |
-
#
|
|
|
|
| 339 |
|
| 340 |
api_app = FastAPI()
|
| 341 |
|
|
@@ -449,17 +456,9 @@ async def chat_completions(request: Request):
|
|
| 449 |
|
| 450 |
# ββ Launch βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 451 |
|
| 452 |
-
app = gr.mount_gradio_app(
|
| 453 |
-
api_app,
|
| 454 |
-
demo,
|
| 455 |
-
path="/",
|
| 456 |
-
theme=THEME,
|
| 457 |
-
css=CSS,
|
| 458 |
-
)
|
| 459 |
-
|
| 460 |
if __name__ == "__main__":
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
)
|
|
|
|
| 5 |
import asyncio
|
| 6 |
import threading
|
| 7 |
import queue as queue_mod
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
+
import spaces
|
| 10 |
from fastapi import FastAPI, Request
|
| 11 |
from fastapi.responses import StreamingResponse, JSONResponse
|
| 12 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 127 |
threading.Thread(target=_load_model, daemon=True).start()
|
| 128 |
|
| 129 |
|
| 130 |
+
# ZeroGPU requires one decorated function even though inference stays on CPU.
|
| 131 |
+
@spaces.GPU
|
| 132 |
+
def _zerogpu_compatibility_marker():
|
| 133 |
+
return True
|
| 134 |
+
|
| 135 |
+
|
| 136 |
# ββ Gradio chat helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 137 |
|
| 138 |
def user_submit(message, history):
|
|
|
|
| 339 |
|
| 340 |
|
| 341 |
# ββ FastAPI routes ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 342 |
+
# Gradio 6 recreates its FastAPI app during demo.launch(), and its catch-all
|
| 343 |
+
# routes shadow custom routes attached directly to demo.app. Build the API
|
| 344 |
+
# routes separately and pass them into the new app at construction time so
|
| 345 |
+
# they are registered before Gradio's catch-all routes.
|
| 346 |
|
| 347 |
api_app = FastAPI()
|
| 348 |
|
|
|
|
| 456 |
|
| 457 |
# ββ Launch βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
if __name__ == "__main__":
|
| 460 |
+
demo.launch(
|
| 461 |
+
theme=THEME,
|
| 462 |
+
css=CSS,
|
| 463 |
+
app_kwargs={"routes": api_app.router.routes},
|
| 464 |
)
|