import gradio as gr from transformers import pipeline # ✅ 使用通用模型來分類不只熱狗的圖片 classifier = pipeline(task="image-classification", model="google/vit-base-patch16-224") def predict(input_img): predictions = classifier(input_img) return input_img, {p["label"]: p["score"] for p in predictions} gradio_app = gr.Interface( fn=predict, inputs=gr.Image(label="Upload an image", sources=['upload', 'webcam'], type="pil"), outputs=[gr.Image(label="Input Image"), gr.Label(label="Predictions", num_top_classes=3)], title="🍽️ Image Classifier — What Is This?", ) if __name__ == "__main__": gradio_app.launch()