File size: 738 Bytes
dfec65b
 
 
 
 
 
87fe2e2
dfec65b
87fe2e2
a02cd44
ea9eea4
22bc2c2
 
 
51c985c
3ab5bd0
 
 
22bc2c2
dfec65b
 
dfc2140
dfec65b
f5f2a5b
329e771
22bc2c2
 
 
 
 
 
 
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
import torch
import gradio as gr
from transformers import pipeline

device = "cuda" if torch.cuda.is_available() else "cpu"

def predict(image):
    classifier = pipeline(task="image-classification")
    preds = classifier(image)
    return {pred["label"]: round(float(pred["score"]), 4) for pred in preds}

def clear_interface():
    interface.inputs[0].clear()
    interface.outputs[0].clear()

description = """
"""

interface = gr.Interface(
    fn=predict,
    inputs=[
        gr.inputs.Image(label="Image to classify", type="pil"),
    ],
    outputs=gr.outputs.Label(),
    title="Image Classifier",
    description=description,
    buttons=[
        gr.Button(label="Clear", callback=clear_interface)
    ]
)

interface.launch()