File size: 815 Bytes
5bc2648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
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]
    label = result['label']
    score = result['score']
    
    if label == 'POSITIVE':
        emotion = "positive"
    elif label == 'NEGATIVE':
        emotion = "negative"
    else:
        emotion = "neutral"
    
    return f"Emotion: {emotion}\nConfidence: {score:.2f}"

# Create the Gradio interface
iface = gr.Interface(
    fn=analyze_sentiment,
    inputs=gr.Textbox(lines=5, placeholder="Enter your text here..."),
    outputs="text",
    title="Emotion Analysis",
    description="Analyze the sentiment of your text using Hugging Face Transformers."
)

# Launch the app
iface.launch()