Download app.py from HamzaAS/sentiment-analysis-space: direct link, hf CLI and curl.
- Browser
- Download file 737 Bytes
-
https://huggingface.co/spaces/HamzaAS/sentiment-analysis-space/resolve/main/app.py
- Command line
-
hf download hf://spaces/HamzaAS/sentiment-analysis-space/app.py
-
curl -L -o app.py https://huggingface.co/spaces/HamzaAS/sentiment-analysis-space/resolve/main/app.py
737 Bytes
| """ | |
| Space Gradio — Analyse de sentiment (DistilBERT fine-tuné). | |
| """ | |
| import gradio as gr | |
| from transformers import pipeline | |
| MODEL_ID = "HamzaAS/distilbert-sentiment-demo" | |
| classifier = pipeline("sentiment-analysis", model=MODEL_ID, truncation=True) | |
| def predict(text): | |
| if not text or not text.strip(): | |
| return {} | |
| preds = classifier(text, top_k=None) | |
| return {p["label"]: float(p["score"]) for p in preds} | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(lines=4, label="Votre texte", placeholder="This movie was fantastic!"), | |
| outputs=gr.Label(num_top_classes=2, label="Sentiment"), | |
| title="🎬 Sentiment Analysis (DistilBERT)" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |