File size: 744 Bytes
7dfd165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import gradio as gr

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

# Define the prediction function
def analyze_sentiment(text):
    result = classifier(text)[0]
    label = result['label']
    score = round(result['score'], 3)
    return f"Sentiment: {label} (Confidence: {score})"

# Create the Gradio interface
interface = gr.Interface(
    fn=analyze_sentiment,
    inputs=gr.Textbox(lines=4, placeholder="Enter some text here..."),
    outputs="text",
    title="Sentiment Analysis with Hugging Face 🤗",
    description="Enter text to find out if the sentiment is positive, negative, or neutral."
)

# Run the app
if __name__ == "__main__":
    interface.launch()