from transformers import pipeline import gradio as gr # Load the sentiment analysis pipeline classifier = pipeline("sentiment-analysis") # Function to classify the sentiment def classify_sentiment(sentence): try: result = classifier(sentence)[0] sentiment = "happy" if result['label'] == 'POSITIVE' else "sad" return f"The sentence expresses {sentiment} with a confidence of {result['score']:.2f}." except Exception as e: return f"An error occurred: {str(e)}" # Create the Gradio interface iface = gr.Interface( fn=classify_sentiment, inputs="text", outputs="text", title="Sentiment Analysis", description="Classify if a sentence is happy or sad." ) # Launch the interface iface.launch()