Convert to Gradio Space to bypass Docker paywall
Browse files- README.md +2 -2
- main.py β app.py +12 -5
- requirements.txt +0 -0
README.md
CHANGED
|
@@ -3,8 +3,8 @@ title: PACE AI Inference
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: indigo
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
---
|
| 9 |
|
| 10 |
# PACE AI Inference Service
|
|
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
---
|
| 9 |
|
| 10 |
# PACE AI Inference Service
|
main.py β app.py
RENAMED
|
@@ -7,13 +7,13 @@ from fastapi.responses import StreamingResponse
|
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
| 8 |
import threading
|
| 9 |
|
| 10 |
-
|
| 11 |
title="PACE AI Inference Service",
|
| 12 |
description="Hugging Face Deployment for PACE Actor-Critic Ensemble",
|
| 13 |
version="1.0.0"
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
| 17 |
CORSMiddleware,
|
| 18 |
allow_origins=["*"],
|
| 19 |
allow_credentials=True,
|
|
@@ -28,15 +28,15 @@ class GenerateRequest(BaseModel):
|
|
| 28 |
|
| 29 |
_generate_lock = threading.Lock()
|
| 30 |
|
| 31 |
-
@
|
| 32 |
def root():
|
| 33 |
return {"status": "PACE AI Service Running"}
|
| 34 |
|
| 35 |
-
@
|
| 36 |
def health():
|
| 37 |
return {"status": "healthy"}
|
| 38 |
|
| 39 |
-
@
|
| 40 |
def generate_stream(request: GenerateRequest):
|
| 41 |
def event_stream():
|
| 42 |
if not _generate_lock.acquire(blocking=False):
|
|
@@ -67,3 +67,10 @@ def generate_stream(request: GenerateRequest):
|
|
| 67 |
_generate_lock.release()
|
| 68 |
|
| 69 |
return StreamingResponse(event_stream(), media_type="application/x-ndjson")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
| 8 |
import threading
|
| 9 |
|
| 10 |
+
fastapi_app = FastAPI(
|
| 11 |
title="PACE AI Inference Service",
|
| 12 |
description="Hugging Face Deployment for PACE Actor-Critic Ensemble",
|
| 13 |
version="1.0.0"
|
| 14 |
)
|
| 15 |
|
| 16 |
+
fastapi_app.add_middleware(
|
| 17 |
CORSMiddleware,
|
| 18 |
allow_origins=["*"],
|
| 19 |
allow_credentials=True,
|
|
|
|
| 28 |
|
| 29 |
_generate_lock = threading.Lock()
|
| 30 |
|
| 31 |
+
@fastapi_app.get("/")
|
| 32 |
def root():
|
| 33 |
return {"status": "PACE AI Service Running"}
|
| 34 |
|
| 35 |
+
@fastapi_app.get("/health")
|
| 36 |
def health():
|
| 37 |
return {"status": "healthy"}
|
| 38 |
|
| 39 |
+
@fastapi_app.post("/generate_stream")
|
| 40 |
def generate_stream(request: GenerateRequest):
|
| 41 |
def event_stream():
|
| 42 |
if not _generate_lock.acquire(blocking=False):
|
|
|
|
| 67 |
_generate_lock.release()
|
| 68 |
|
| 69 |
return StreamingResponse(event_stream(), media_type="application/x-ndjson")
|
| 70 |
+
|
| 71 |
+
import gradio as gr
|
| 72 |
+
demo = gr.Blocks()
|
| 73 |
+
with demo:
|
| 74 |
+
gr.Markdown("# PACE AI Backend Running\nThis is a FastAPI backend running inside a Gradio Space.")
|
| 75 |
+
|
| 76 |
+
app = gr.mount_gradio_app(fastapi_app, demo, path="/ui")
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|