Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load sentiment analysis model | |
| sentiment_pipeline = pipeline("sentiment-analysis") | |
| # Define sentiment analysis function | |
| def analyze_sentiment(text): | |
| result = sentiment_pipeline(text)[0] # Get the first (only) result | |
| return f"Sentiment: {result['label']} (Confidence: {result['score']:.2f})" | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), | |
| outputs="text", | |
| title="Sentiment Analyzer", | |
| description="Enter a sentence to analyze its sentiment (Positive/Negative)." | |
| ) | |
| # Launch app | |
| if __name__ == "__main__": | |
| iface.launch() | |