import gradio as gr from transformers import pipeline # Load the sentiment analysis pipeline from Hugging Face Transformers sentiment_analyzer = pipeline("sentiment-analysis") def analyze_sentiment(text): result = sentiment_analyzer(text) sentiment = result[0]['label'] confidence = result[0]['score'] return f"Sentiment: {sentiment} (Confidence: {confidence:.2f})" # Create the Gradio interface iface = gr.Interface( fn=analyze_sentiment, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Textbox(), title="Sentiment Analysis Tool", description="Enter a piece of text and get its sentiment analysis result.", ) # Launch the Gradio interface iface.launch()