Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline, DistilBertTokenizerFast
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
|
| 6 |
+
model_name = "distilbert-base-uncased"
|
| 7 |
+
tokenizer = DistilBertTokenizerFast.from_pretrained(model_name)
|
| 8 |
+
classifier = pipeline("text-classification", model=model_name, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
@app.post("/classify_text")
|
| 11 |
+
async def classify_text(text: str):
|
| 12 |
+
result = classifier(text)
|
| 13 |
+
label = result[0]['label']
|
| 14 |
+
if label == 'LABEL_1':
|
| 15 |
+
return {"classification": "Not flirty"}
|
| 16 |
+
elif label == 'LABEL_2':
|
| 17 |
+
return {"classification": "Flirty"}
|
| 18 |
+
else:
|
| 19 |
+
return {"classification": "Unknown"}
|
| 20 |
+
|