FirstApp / app.py
Jayod's picture
Update app.py
12f2fb7
Raw History Blame Contribute Delete
622 Bytes
from transformers import pipeline, DistilBertTokenizerFast
from fastapi import FastAPI
app = FastAPI()
model_name = "distilbert-base-uncased"
tokenizer = DistilBertTokenizerFast.from_pretrained(model_name)
classifier = pipeline("text-classification", model=model_name, tokenizer=tokenizer)
@app.post("/classify_text")
async def classify_text(text: str):
result = classifier(text)
label = result[0]['label']
if label == 'LABEL_1':
return {"classification": "Not flirty"}
elif label == 'LABEL_2':
return {"classification": "Flirty"}
else:
return {"classification": "Unknown"}