File size: 622 Bytes
12f2fb7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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"}
|