VijayPulmamidi's picture
Update app.py
cab374f verified
raw
history blame contribute delete
758 Bytes
from transformers import pipeline
import gradio as gr
# Load sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
def analyze_sentiment(text):
result = sentiment_pipeline(text)[0]
label = result['label']
score = result['score']
# Set emoji based on sentiment
emoji = "🙂" if label == "POSITIVE" else "☹️"
return f"{emoji} {label} ({score:.2f})", score
# Create Gradio interface
interface = gr.Interface(
fn=analyze_sentiment,
inputs="text",
outputs=[gr.Textbox(), gr.Slider(minimum=0, maximum=1, step=0.01)], # New: Confidence bar
title="Sentiment Analyzer",
description="Type a sentence to see if it's Positive or Negative",
)
# Launch the app
interface.launch()