| | import gradio as gr |
| | from transformers import pipeline |
| | import torch |
| | |
| | sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") |
| |
|
| | def analyze_sentiment(input_text): |
| | |
| | result = sentiment_analyzer(input_text) |
| | sentiment_score = result[0]['label'] |
| | return sentiment_score |
| |
|
| | |
| | example_inputs = [ |
| | "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." |
| | ] |
| |
|
| | |
| | interface = gr.Interface( |
| | fn=analyze_sentiment, |
| | inputs=gr.Textbox(label="Enter Text", placeholder="Type or paste your sentence or paragraph here...", lines=5), |
| | outputs=gr.Textbox(label="Predicted Sentiment (1 to 5 stars)"), |
| | examples=example_inputs, |
| | title="Sentiment Analysis App", |
| | description="Enter a sentence or paragraph and click the button to analyze the sentiment. The output will show a score from 1 to 5 stars." |
| | ) |
| |
|
| | |
| | if __name__ == "__main__": |
| | interface.launch() |