Spaces:
Paused
Paused
Commit
·
267c9ca
1
Parent(s):
1885320
add FastAPI /infer endpoint
Browse files- app.py +20 -5
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -1,15 +1,30 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
return f"Hello, {name}! 🎬 HoloCine Space is live."
|
| 5 |
|
|
|
|
| 6 |
demo = gr.Interface(
|
| 7 |
fn=hello,
|
| 8 |
inputs=gr.Textbox(label="Your name"),
|
| 9 |
outputs=gr.Textbox(label="Response"),
|
| 10 |
title="HoloCine Demo",
|
| 11 |
-
description="
|
| 12 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from gradio import Interface
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# Simple function for now
|
| 8 |
+
def hello(name: str):
|
| 9 |
return f"Hello, {name}! 🎬 HoloCine Space is live."
|
| 10 |
|
| 11 |
+
# Gradio UI
|
| 12 |
demo = gr.Interface(
|
| 13 |
fn=hello,
|
| 14 |
inputs=gr.Textbox(label="Your name"),
|
| 15 |
outputs=gr.Textbox(label="Response"),
|
| 16 |
title="HoloCine Demo",
|
| 17 |
+
description="Now also exposes a /infer API."
|
| 18 |
)
|
| 19 |
+
demo.queue()
|
| 20 |
+
|
| 21 |
+
# Mount Gradio inside FastAPI
|
| 22 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 23 |
|
| 24 |
+
# Custom API endpoint
|
| 25 |
+
@app.post("/infer")
|
| 26 |
+
async def infer(request: Request):
|
| 27 |
+
data = await request.json()
|
| 28 |
+
name = data.get("name", "")
|
| 29 |
+
result = hello(name)
|
| 30 |
+
return {"result": result}
|
requirements.txt
CHANGED
|
@@ -1 +1,3 @@
|
|
| 1 |
gradio
|
|
|
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
+
fastapi
|
| 3 |
+
uvicorn
|