File size: 650 Bytes
56c84f4
dc00b27
 
 
 
56c84f4
8a17b6b
 
 
10d665a
56c84f4
1fe2c75
 
 
 
 
59e9ce4
1fe2c75
10d665a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import gradio as gr
from transformers import pipeline

checkpoint = "openai/clip-vit-large-patch14"
detector = pipeline(model=checkpoint, task="zero-shot-image-classification")

def classify(img, candidates):
    labels = candidates.split(sep=",")
    predictions = detector(img, candidate_labels=labels)
    return predictions

with gr.Blocks() as iface:
    image = gr.Image(type="pil", label="Image")
    candidates = gr.Textbox(label="Candidates")
    predictions = gr.Textbox(label="Predictions")
    btn = gr.Button("Classify")
    btn.click(fn=classify, inputs=[image, candidates], outputs=predictions, api_name="classify")
    
iface.launch()