Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| import gradio as gr | |
| # Load sentiment analysis pipeline | |
| classifier = pipeline("sentiment-analysis") | |
| def analyze_sentiment(text): | |
| result = classifier(text)[0] | |
| label = result['label'] | |
| score = round(result['score'] * 100, 2) | |
| return f"Sentiment: {label} (Confidence: {score}%)" | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(label="Enter text"), | |
| outputs=gr.Textbox(label="Sentiment Result"), | |
| title="Sentiment Analyzer", | |
| description="Enter a sentence and see if it's positive or negative." | |
| ) | |
| iface.launch() | |