test-zero-shot / app.py
isingh's picture
candidates are passed to classifier
8a17b6b
raw
history blame
No virus
650 Bytes
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()