File size: 865 Bytes
17f3a9b
 
 
 
d794995
17f3a9b
2ae9fb3
17f3a9b
 
 
2ae9fb3
17f3a9b
 
 
 
 
2ae9fb3
17f3a9b
 
 
 
8d84024
17f3a9b
 
 
a65e7e5
17f3a9b
a803b83
17f3a9b
 
 
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
import os
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"

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