Spaces:
Running
Running
Download app.py from hsienberg/dictionary: direct link, hf CLI and curl.
- Browser
- Download file 776 Bytes
-
https://huggingface.co/spaces/hsienberg/dictionary/resolve/main/app.py
- Command line
-
hf download hf://spaces/hsienberg/dictionary/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hsienberg/dictionary/resolve/main/app.py
776 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| classifier = pipeline( | |
| "sentiment-analysis", | |
| model="distilbert-base-uncased-finetuned-sst-2-english" | |
| ) | |
| def analyze(text): | |
| if not text.strip(): | |
| return "Please enter some text." | |
| result = classifier(text)[0] | |
| label = result["label"] | |
| score = round(result["score"] * 100, 1) | |
| return f"**{label}** ({score}% confidence)" | |
| demo = gr.Interface( | |
| fn=analyze, | |
| inputs=gr.Textbox( | |
| label="Enter text", | |
| placeholder="Type a sentence to analyze...", | |
| lines=3 | |
| ), | |
| outputs=gr.Markdown(label="Result"), | |
| title="Mood Meter", | |
| description="Analyze the sentiment of any text. " | |
| "Uses DistilBERT (67M parameters) running on free CPU." | |
| ) | |
| demo.launch() |