Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,24 +1,28 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
-
from
|
3 |
from pydantic import BaseModel
|
4 |
-
from transformers import pipeline
|
5 |
-
import uvicorn
|
6 |
|
7 |
-
|
|
|
8 |
|
|
|
|
|
9 |
|
10 |
-
class
|
11 |
text: str
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
pipe = pipeline("text-classification",
|
16 |
-
model="SamLowe/roberta-base-go_emotions")
|
17 |
-
return pipe(text)
|
18 |
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
@app.post(
|
21 |
-
|
22 |
-
|
23 |
-
return
|
24 |
-
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from models import sa_pipeline, query_index
|
3 |
from pydantic import BaseModel
|
|
|
|
|
4 |
|
5 |
+
class QARequest(BaseModel):
|
6 |
+
question: str
|
7 |
|
8 |
+
class QAResponse(BaseModel):
|
9 |
+
answer: str
|
10 |
|
11 |
+
class SentimentRequest(BaseModel):
|
12 |
text: str
|
13 |
|
14 |
+
class SentimentResponse(BaseModel):
|
15 |
+
label: str
|
16 |
+
score: float
|
17 |
|
18 |
+
app = FastAPI()
|
|
|
|
|
|
|
19 |
|
20 |
+
@app.post('/question-answering', response_model=QAResponse)
|
21 |
+
def query(query: QARequest):
|
22 |
+
data = query.dict()
|
23 |
+
return {'answer': query_index(data['question'])}
|
24 |
|
25 |
+
@app.post('/sentiment-analysis', response_model=SentimentResponse)
|
26 |
+
def query(query: SentimentRequest):
|
27 |
+
data = query.dict()
|
28 |
+
return sa_pipeline(data['text'])[0]
|
|