File size: 1,417 Bytes
47011be 6828757 47011be 15e8a30 927aaec 47011be |
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 |
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()
|