File size: 1,041 Bytes
a803b83
a65e7e5
2ae9fb3
 
a65e7e5
d794995
a65e7e5
2ae9fb3
a65e7e5
2ae9fb3
 
 
a65e7e5
2ae9fb3
 
a65e7e5
2ae9fb3
 
 
 
a65e7e5
2ae9fb3
8d84024
a29b172
a65e7e5
 
 
a29b172
 
a65e7e5
a803b83
 
 
 
 
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
32
33
34
35
36
import os
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")

# 启动应用,使用环境变量指定的端口
if __name__ == "__main__":
    import uvicorn
    port = int(os.getenv("PORT", 7860))  # 获取 PORT 环境变量
    uvicorn.run(app, host="0.0.0.0", port=port)