Spaces:
showme
/
Running

File size: 604 Bytes
5e1e3c6
 
142d567
 
5e1e3c6
 
 
 
1ce5d59
142d567
5e1e3c6
 
 
142d567
5e1e3c6
 
 
 
 
05ce864
229bd35
05ce864
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline

# 创建 FastAPI 实例
app = FastAPI()

# 加载预训练模型
sentiment_model = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")

# 定义请求体的格式
class TextRequest(BaseModel):
    text: str

# 定义一个 POST 请求处理函数
@app.post("/predict")
async def predict(request: TextRequest):
    result = sentiment_model(request.text)
    return {"result": result}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)