BuckLakeAI / app.py
parkerjj's picture
Change to Docker
efad2c7
raw
history blame
856 Bytes
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}
@app.get("/")
async def root():
return {"message": "Welcome to the API. Use /api/aaa or /api/bbb for processing."}
# 启动应用,使用环境变量指定的端口
if __name__ == "__main__":
import uvicorn
port = int(os.getenv("PORT", 7860)) # 获取 PORT 环境变量
uvicorn.run(app, host="0.0.0.0", port=port)