| import gradio as gr |
| from transformers import pipeline |
|
|
| sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") |
|
|
| def analyze_sentiment(text): |
| result = sentiment_analyzer(text)[0] |
| score = result['label'] |
| return score |
|
|
| interface = gr.Interface( |
| fn=analyze_sentiment, |
| inputs=[ |
| gr.Textbox(label="Enter your text here", placeholder="Type a sentence or paragraph...", lines=5), |
| ], |
| outputs=gr.Label(label="Predicted Sentiment (1-5 stars)"), |
| 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."], |
| ["I'm very disappointed with the customer service."], |
| ["The concert was fantastic, I had an amazing time!"], |
| ["I regret buying this product, it's terrible."] |
| ], |
| title="Sentiment Analysis App", |
| description="This app analyzes the sentiment of the text you provide, showing a score from 1 to 5 stars, where 1 is negative and 5 is positive." |
| ) |
|
|
| interface.launch() |
|
|