BuckLakeAI / app.py
parkerjj's picture
Change to Gradio
a29b172
raw
history blame
916 Bytes
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__ 入口。