Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load pipeline | |
| sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") | |
| def analyze_sentiment(text): | |
| result = sentiment_analyzer(text)[0] | |
| return f"Predicted Sentiment: {result['label']} stars" | |
| # gradio interface | |
| demo = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(label="Enter text for sentiment analysis", lines=3, placeholder="Type text here..."), | |
| outputs=gr.Textbox(label="Sentiment Result", lines=1), | |
| title="Sentiment Analysis", | |
| examples=[ | |
| ["I love this product! It's amazing!"], | |
| ["This was the worst experience I've ever had."], | |
| ["The movie was okay, not great but not bad either."], | |
| ["Absolutely fantastic! I would recommend it to everyone."] | |
| ] | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| demo.launch() |