Download app.py from unshorn/foobar: direct link, hf CLI and curl.
- Browser
- Download file 645 Bytes
-
https://huggingface.co/spaces/unshorn/foobar/resolve/main/app.py
- Command line
-
hf download hf://spaces/unshorn/foobar/app.py
-
curl -L -o app.py https://huggingface.co/spaces/unshorn/foobar/resolve/main/app.py
645 Bytes
| # 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() | |