Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,26 @@
|
|
| 1 |
from fastapi import FastAPI, Request
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
|
|
|
| 6 |
def greet(name: str) -> str:
|
| 7 |
return f"Hello {name}!!"
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
@app.post("/predict")
|
| 12 |
async def predict(request: Request):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return {"message": "FastAPI is working!"}
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
# μ€μ μ²λ¦¬ ν¨μ
|
| 8 |
def greet(name: str) -> str:
|
| 9 |
return f"Hello {name}!!"
|
| 10 |
|
| 11 |
+
# FastAPI μλν¬μΈνΈ
|
|
|
|
| 12 |
@app.post("/predict")
|
| 13 |
async def predict(request: Request):
|
| 14 |
+
try:
|
| 15 |
+
data = await request.json()
|
| 16 |
+
name = data["data"][0]
|
| 17 |
+
result = greet(name)
|
| 18 |
+
return JSONResponse(content={"data": [result]})
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return JSONResponse(content={"error": str(e)}, status_code=400)
|
|
|
|
| 21 |
|
| 22 |
+
# Gradio μΈν°νμ΄μ€ (μ νμ )
|
| 23 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 24 |
|
| 25 |
+
# Space μ€ν μ Gradio UIμ FastAPI λμμ μλ
|
| 26 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, inline=False)
|