Spaces:
Sleeping
Sleeping
File size: 693 Bytes
632f92d baa242e ec94ca0 baa242e ec94ca0 baa242e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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
@gpu
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()
|