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()