SANMUGAPIRIYA/sentimentanalysisapp
0
1from transformers import pipeline2import gradio as gr3 4# Load pre-trained sentiment analysis pipeline5sentiment_pipeline = pipeline("sentiment-analysis")6 7# Function to analyze sentiment8def analyze_sentiment(text):9 results = sentiment_pipeline(text)10 return {result['label']: round(result['score'], 2) for result in results}11 12# Gradio Interface13iface = gr.Interface(14 fn=analyze_sentiment,15 inputs=gr.Textbox(lines=2, placeholder="Enter a sentence here..."),16 outputs=gr.Label(num_top_classes=3),17 title="Sentiment Analysis",18 description="Enter a sentence, and the model will classify it as Positive, Negative, or Neutral."19)20 21# Launch the app22iface.launch()v