import gradio as gr from transformers import pipeline # Load the pre-trained sentiment analysis model model_name = "distilbert-base-uncased-finetuned-sst-2-english" sentiment_model = pipeline("text-classification", model=model_name) # Define the function to analyze sentiment def analyze_sentiment(input_text): result = sentiment_model(input_text)[0] label = result["label"] score = result["score"] return f"Sentiment: {label}, Confidence: {score:.2f}" # Create the Gradio interface interface = gr.Interface( fn=analyze_sentiment, inputs="text", outputs="text", title="Sentiment Analysis App", description="Enter a sentence to analyze its sentiment (Positive or Negative).", ) # Launch the app interface.launch()