Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
# Load the sentiment analysis model | |
sentiment_pipeline = pipeline("sentiment-analysis") | |
def analyze_sentiment(text): | |
result = sentiment_pipeline(text)[0] | |
return f"Label: {result['label']}, Confidence: {result['score']:.4f}" | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=analyze_sentiment, | |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), | |
outputs="text", | |
title="Sentiment Analysis", | |
description="Enter a sentence to analyze its sentiment." | |
) | |
# Launch the interface | |
iface.launch() |