import gradio as gr from transformers import pipeline classifier = pipeline('sentiment-analysis', model='distilbert/distilbert-base-uncased-finetuned-sst-2-english') def analyze_sentiment(text): result = classifier(text) # The result is a list of dictionaries, e.g., [{'label': 'POSITIVE', 'score': 0.9998}] # We extract the label and score for better presentation. sentiment_label = result[0]['label'] sentiment_score = result[0]['score'] return f"Sentiment: {sentiment_label}, Score: {sentiment_score:.2f}" # Create and launch the Gradio interface iface = gr.Interface( fn=analyze_sentiment, inputs='text', outputs='text', title='Sentiment Analysis Application', description='Enter text to get its sentiment (positive/negative) and score.' ) # Launch the interface iface.launch()