Spaces:
Running
Running
File size: 916 Bytes
a65e7e5 2ae9fb3 a65e7e5 d794995 a65e7e5 2ae9fb3 a65e7e5 2ae9fb3 a65e7e5 2ae9fb3 a65e7e5 2ae9fb3 a65e7e5 2ae9fb3 8d84024 a29b172 a65e7e5 a29b172 a65e7e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.middleware.wsgi import WSGIMiddleware
app = FastAPI() # 创建 FastAPI 应用
# 定义请求模型
class TextRequest(BaseModel):
text: str
# 定义两个 API 路由处理函数
@app.post("/api/aaa")
async def api_aaa(request: TextRequest):
result = request.text + 'aaa'
return {"result": result}
@app.post("/api/bbb")
async def api_bbb(request: TextRequest):
result = request.text + 'bbb'
return {"result": result}
# Gradio 假界面,仅用于通过 Hugging Face Spaces 部署
def fake_interface():
return "Gradio Interface Placeholder"
# 将 Gradio 应用挂载到 "/gradio" 路径
app = gr.mount_gradio_app(app, gr.Interface(fn=fake_interface, inputs=None, outputs="text"), path="/gradio")
# 注意:Hugging Face Spaces 会自动运行此 app 文件,因此不需要 __main__ 入口。
|