Spaces:
Sleeping
Sleeping
Download app.py from yaimara/SentAnalysis: direct link, hf CLI and curl.
- Browser
- Download file 942 Bytes
-
https://huggingface.co/spaces/yaimara/SentAnalysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/yaimara/SentAnalysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/yaimara/SentAnalysis/resolve/main/app.py
942 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Return scores for both labels so Gradio can show a nice bar chart | |
| classifier = pipeline("sentiment-analysis", return_all_scores=True) | |
| def analyze(text: str): | |
| if not text.strip(): | |
| return {} | |
| scores = classifier(text)[0] # [{'label': 'NEGATIVE', 'score': ...}, {'label': 'POSITIVE', 'score': ...}] | |
| return {item["label"]: float(item["score"]) for item in scores} | |
| demo = gr.Interface( | |
| fn=analyze, | |
| inputs=gr.Textbox(lines=4, label="Enter text"), | |
| outputs=gr.Label(num_top_classes=2, label="Sentiment"), | |
| title="Hugging Face Sentiment (Transformers + Gradio)", | |
| description="Type text and get POSITIVE/NEGATIVE scores.", | |
| examples=[ | |
| ["I've been waiting for a Hugging Face course my whole life."], | |
| ["This is the worst thing ever."], | |
| ["Meh, it's okay—nothing special."] | |
| ], | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |