from transformers import pipeline import gradio as gr # Load the text classification model classifier = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english") # Define the function that runs when the user submits input def classify_sentiment(text): result = classifier(text)[0] label = result['label'] score = result['score'] return f"{label} ({score:.2f})" # Build the Gradio app demo = gr.Interface( fn=classify_sentiment, inputs=gr.Textbox(lines=2, placeholder="Enter your sentence here..."), outputs="text", title="Sentiment Classifier", description="This app classifies your text as POSITIVE or NEGATIVE using a Hugging Face model." ) # Launch it demo.launch()