File size: 748 Bytes
ee40669
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

def analyze_sentiment(text):
    result = sentiment_pipeline(text)[0]  # Extract the first result
    label = result["label"]
    score = result["score"]
    return f"Sentiment: {label} (Confidence: {score:.2f})"

# Create a Gradio interface
demo = gr.Interface(
    fn=analyze_sentiment,
    inputs=gr.Textbox(lines=3, placeholder="Enter a sentence..."),
    outputs="text",
    title="Sentiment Analysis Demo",
    description="Enter text to see its sentiment (Positive/Negative) along with a confidence score.",
)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)