File size: 687 Bytes
6945fce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline from Hugging Face
sentiment_pipeline = pipeline("sentiment-analysis")
def analyze_sentiment(text):
result = sentiment_pipeline(text)[0]
sentiment = result['label']
confidence = result['score']
return f"Sentiment: {sentiment}, Confidence: {confidence:.2f}"
# Create the Gradio interface
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
outputs="text",
title="Sentiment Analysis",
description="Enter text and click the button to detect the sentiment."
)
# Launch the interface
iface.launch()
|