Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the sentiment analysis model | |
| sentiment_analyzer = pipeline("sentiment-analysis") | |
| # Function to analyze text sentiment | |
| def analyze_sentiment(text): | |
| result = sentiment_analyzer(text) | |
| sentiment = result[0]['label'] | |
| score = result[0]['score'] | |
| return f"Sentiment: {sentiment} (Confidence: {score:.2f})" | |
| # Gradio interface | |
| app = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(label="Enter text to analyze"), | |
| outputs=gr.Textbox(label="Sentiment Analysis Result"), | |
| title="Text Sentiment Analyzer", | |
| description="A simple app that analyzes the sentiment of your text input." | |
| ) | |
| if __name__ == "__main__": | |
| app.launch() | |