import gradio as gr from transformers import pipeline # Initialize the sentiment analysis pipeline classifier = pipeline("sentiment-analysis") def analyze_sentiment(text): result = classifier(text) return result[0]['label'], result[0]['score'] # Create Gradio interface demo = gr.Interface( fn=analyze_sentiment, inputs=gr.Textbox(label="Enter text to analyze"), outputs=[ gr.Label(label="Sentiment"), gr.Number(label="Confidence Score") ], title="Sentiment Analysis Demo", description="Enter some text to analyze its sentiment using Hugging Face's transformers." ) if __name__ == "__main__": demo.launch()