Spaces:
Runtime error
Runtime error
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() |