import gradio as gr from transformers import pipeline import numpy as np from PIL import Image pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32") def shot(image, labels_text): PIL_image = Image.fromarray(np.uint8(image)).convert('RGB') labels = labels_text.split(";;") res = pipe(images=PIL_image, candidate_labels=labels, hypothesis_template="This is a photo of {}") return {dic["label"]: dic["score"] for dic in res} iface = gr.Interface(shot, ["image", "text"], "label", examples=[ ["examples/1.jpg", "ralph lauren;;apparel store;;ralph lauren store;;shirts;;wardrobe;;white flower"], ["examples/2.JPG", "adidas;;apparel store;;adidas store;;shirts;;wardrobe;;women training;;shoes"], ["examples/3.jpg", "project x;;sweet monster;;bags store;;store;;shoes store;;glass windows;;hanging lights"], ["examples/4.JPG", "multi brand store;;multi brand shoe store;;shoe store;;mannequins;;adidas store;;reebok store;;puma store"], ["examples/5.png", "sophie;;scene"], ], description="Add a picture and a list of labels separated by ;;", title="Zero-shot Image Classification") iface.launch()