File size: 758 Bytes
572067b
 
 
 
 
 
 
 
 
 
cab374f
 
 
 
 
572067b
cab374f
 
 
 
 
 
 
 
572067b
cab374f
572067b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from transformers import pipeline
import gradio as gr

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

def analyze_sentiment(text):
    result = sentiment_pipeline(text)[0]
    label = result['label']
    score = result['score']
    
    # Set emoji based on sentiment
    emoji = "🙂" if label == "POSITIVE" else "☹️"
    
    return f"{emoji} {label} ({score:.2f})", score

# Create Gradio interface
interface = gr.Interface(
    fn=analyze_sentiment, 
    inputs="text", 
    outputs=[gr.Textbox(), gr.Slider(minimum=0, maximum=1, step=0.01)],  # New: Confidence bar
    title="Sentiment Analyzer",
    description="Type a sentence to see if it's Positive or Negative",
)

# Launch the app
interface.launch()