showme commited on
Commit
5e1e3c6
1 Parent(s): f3e8658

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,17 +1,19 @@
1
- import gradio as gr
 
2
  from transformers import pipeline
3
- # 加载模型
4
- sentiment_model = pipeline("text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
5
 
6
- def predict(text):
7
- return sentiment_model(text)
 
 
 
8
 
9
- # 构建 UI
10
- interface = gr.Interface(
11
- fn=predict,
12
- inputs="text",
13
- outputs="text",
14
- title="chatgpt-detector-roberta"
15
- )
16
 
17
- interface.launch()
 
 
 
 
 
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}