Spaces:
Sleeping
Sleeping
| 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) | |
| sentiment = result[0]['label'] | |
| return sentiment | |
| 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."] | |
| ] | |
| #Gradio | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Sentiment Analysis") | |
| with gr.Row(): | |
| with gr.Column(): | |
| text_input = gr.Textbox(label="Enter Text", placeholder="Type a sentence or paragraph here ^^...") | |
| with gr.Column(): | |
| output = gr.Textbox(label="Predicted Sentiment (1-5 stars)", interactive=False) | |
| analyze_button = gr.Button("Analyze Sentiment", variant="primary") | |
| gr.Examples(examples=examples, inputs=text_input) | |
| analyze_button.click(analyze_sentiment, inputs=[text_input], outputs=output) | |
| demo.launch() | |