Download app.py from Jayod/FirstApp: direct link, hf CLI and curl.
- Browser
- Download file 622 Bytes
-
https://huggingface.co/spaces/Jayod/FirstApp/resolve/main/app.py
- Command line
-
hf download hf://spaces/Jayod/FirstApp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Jayod/FirstApp/resolve/main/app.py
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) | |
| 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"} | |