Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
-
|
|
|
2 |
from transformers import pipeline
|
3 |
-
# 加载模型
|
4 |
-
sentiment_model = pipeline("text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
inputs="text",
|
13 |
-
outputs="text",
|
14 |
-
title="chatgpt-detector-roberta"
|
15 |
-
)
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
from transformers import pipeline
|
|
|
|
|
4 |
|
5 |
+
# 创建 FastAPI 实例
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
# 加载预训练模型
|
9 |
+
sentiment_model = pipeline("text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
|
10 |
|
11 |
+
# 定义请求体的格式
|
12 |
+
class TextRequest(BaseModel):
|
13 |
+
text: str
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# 定义一个 POST 请求处理函数
|
16 |
+
@app.post("/predict")
|
17 |
+
async def predict(request: TextRequest):
|
18 |
+
result = sentiment_model(request.text)
|
19 |
+
return {"result": result}
|