File size: 669 Bytes
08a1a2e
 
 
b27155d
 
08a1a2e
 
b27155d
08a1a2e
 
 
b27155d
 
 
 
08a1a2e
 
 
b27155d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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()