Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
from agreement_score import check_agreement
|
| 5 |
+
from sentimental import analyze_sentiment
|
| 6 |
+
from classifier import classify_message
|
| 7 |
+
|
| 8 |
+
app = FastAPI(title="Unified NLP API")
|
| 9 |
+
|
| 10 |
+
class AgreementRequest(BaseModel):
|
| 11 |
+
msg1: str
|
| 12 |
+
msg2: str
|
| 13 |
+
|
| 14 |
+
class TextRequest(BaseModel):
|
| 15 |
+
text: str
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@app.post("/agreement")
|
| 19 |
+
def agreement(req: AgreementRequest):
|
| 20 |
+
score = check_agreement(req.msg1, req.msg2)
|
| 21 |
+
return {"agreement_score": score}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@app.post("/sentiment")
|
| 25 |
+
def sentiment(req: TextRequest):
|
| 26 |
+
score = analyze_sentiment(req.text)
|
| 27 |
+
return {"sentiment_score": score}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@app.post("/classify")
|
| 31 |
+
def classify(req: TextRequest):
|
| 32 |
+
categories = classify_message(req.text)
|
| 33 |
+
return {"categories": categories}
|