Spaces:
Running on Zero
Running on Zero
Download app.py from kani1021/image-classifier: direct link, hf CLI and curl.
- Browser
- Download file 693 Bytes
-
https://huggingface.co/spaces/kani1021/image-classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/kani1021/image-classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/kani1021/image-classifier/resolve/main/app.py
693 Bytes
| try: | |
| import spaces # HF ZeroGPU 需要先於 torch/transformers 匯入 | |
| except ImportError: | |
| spaces = None | |
| import gradio as gr | |
| from transformers import pipeline | |
| classifier = pipeline( | |
| task="image-classification", | |
| model="model", | |
| image_processor="model", | |
| ) | |
| gpu = spaces.GPU if spaces else lambda fn: fn | |
| def predict(image): | |
| results = classifier(image, top_k=3) | |
| return {item["label"]: item["score"] for item in results} | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil", label="Upload image"), | |
| outputs=gr.Label(num_top_classes=3, label="Prediction"), | |
| title="Ball Sport Classifier", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |