# app.py import gradio as gr from transformers import pipeline # Load once at startup clf = pipeline( "text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english" ) def predict(text): if not text or not text.strip(): return {"empty": 1.0} result = clf(text)[0] return {result["label"]: float(result["score"])} demo = gr.Interface( fn=predict, inputs=gr.Textbox(lines=5, label="Input text"), outputs=gr.Label(label="Prediction"), title="Sentiment Classifier", description="Simple ML inference in a Hugging Face Space" ) if __name__ == "__main__": demo.launch()