import gradio as gr from transformers import pipeline # Load pre-trained sentiment analysis model from Hugging Face classifier = pipeline("sentiment-analysis") # Define the function to predict sentiment def predict_sentiment(text): result = classifier(text) label = result[0]['label'] confidence = result[0]['score'] return f"Sentiment: {label}, Confidence: {confidence:.2f}" # Gradio interface interface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text", title="Sentiment Analysis", description="Enter text to predict sentiment") interface.launch(share=True)