demo2gradio / app.py
pradeep4321's picture
Update app.py
31d5557 verified
raw
history blame contribute delete
707 Bytes
import gradio as gr
from transformers import pipeline
# Load sentiment-analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
def analyze_sentiment(text):
if not text.strip():
return "Please enter valid text."
result = sentiment_pipeline(text)[0]
label = result['label']
score = result['score']
return f"Sentiment: {label} | Score: {score:.2f}"
# Gradio interface
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=3, placeholder="Type something here..."),
outputs="text",
title="Sentiment Analysis App",
description="Enter a sentence to analyze its sentiment using Hugging Face Transformers."
)
iface.launch('share=True')