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

# Load the sentiment analysis model
classifier = pipeline("sentiment-analysis")

# Define the function to analyze sentiment
def analyze_sentiment(text):
    result = classifier(text)[0]
    return f"Sentiment: {result['label']}", f"Confidence: {result['score']:.2f}"

# Create a Gradio interface
demo = gr.Interface(
    fn=analyze_sentiment,
    inputs="text",
    outputs=["text", "text"],
    title="Sentiment Analyzer",
    description="Enter a sentence to analyze sentiment (Positive or Negative)."
)

if __name__ == "__main__":
    demo.launch()