Spaces:
Sleeping
Sleeping
File size: 707 Bytes
43ef6ea 31d5557 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 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')
|