Spaces:
Sleeping
Sleeping
| 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() |