File size: 682 Bytes
476068c
da3b2ee
476068c
da3b2ee
476068c
 
da3b2ee
476068c
da3b2ee
 
476068c
da3b2ee
476068c
 
da3b2ee
 
 
 
476068c
 
da3b2ee
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import pipeline
import gradio as gr

# Load pre-trained sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# Function to analyze sentiment
def analyze_sentiment(text):
    results = sentiment_pipeline(text)
    return {result['label']: round(result['score'], 2) for result in results}

# Gradio Interface
iface = gr.Interface(
    fn=analyze_sentiment,
    inputs=gr.Textbox(lines=2, placeholder="Enter a sentence here..."),
    outputs=gr.Label(num_top_classes=3),
    title="Sentiment Analysis",
    description="Enter a sentence, and the model will classify it as Positive, Negative, or Neutral."
)

# Launch the app
iface.launch()