Download app.py from Lazer5641/Sentiment_Analysis_App: direct link, hf CLI and curl.
- Browser
- Download file 785 Bytes
-
https://huggingface.co/spaces/Lazer5641/Sentiment_Analysis_App/resolve/main/app.py
- Command line
-
hf download hf://spaces/Lazer5641/Sentiment_Analysis_App/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Lazer5641/Sentiment_Analysis_App/resolve/main/app.py
785 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Initialize sentiment analysis pipeline | |
| sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") | |
| def analyze_sentiment(text): | |
| if not text.strip(): | |
| return "Please enter text to analyze." | |
| result = sentiment_analyzer(text)[0] | |
| return f"Sentiment: {result['label']} (Confidence: {result['score']:.2f})" | |
| # Gradio interface | |
| demo = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(label="Enter text", placeholder="Type your text here..."), | |
| outputs=gr.Textbox(label="Sentiment Result"), | |
| title="Sentiment Analysis App", | |
| description="Analyze the sentiment of your text (positive or negative)." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |