Spaces:
Sleeping
Sleeping
File size: 802 Bytes
4f801ba e4f2a3f 4f801ba 4d246e5 4f801ba e4f2a3f 4f801ba 4d246e5 4f801ba e4f2a3f 4f801ba e4f2a3f 4f801ba e4f2a3f 4f801ba e4f2a3f | 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 26 27 28 29 30 | from transformers import pipeline
import gradio as gr
classifier = pipeline("sentiment-analysis")
def analyze_sentiment(text):
if not text:
return "No input", 0
try:
result = classifier(text)[0] # should return a dict
label = result.get('label', 'Unknown')
score = round(result.get('score', 0), 3)
return label, score
except Exception as e:
return f"Error: {str(e)}", 0
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs=[
gr.Textbox(label="Sentiment"),
gr.Number(label="Confidence Score")
],
title="Sentiment Analyzer",
description="Enter a sentence to get its sentiment (POSITIVE/NEGATIVE) and confidence score."
)
iface.launch()
|