CoolFace
Apppublic

the237/zero_shot_imageClassification

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py24 linesDownload Raw Back to root
1from turtle import title2import gradio as gr3from transformers import pipeline4import numpy as np5from PIL import Image6 7 8pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")9 10def shot(image, labels_text):11    PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')12    labels = labels_text.split(",")13    res = pipe(images=PIL_image, 14           candidate_labels=labels,15           hypothesis_template= "This is a photo of a {}")16    return {dic["label"]: dic["score"] for dic in res}17    18iface = gr.Interface(shot, 19                    ["image", "text"], 20                    "label", 21                    description="Add a picture and a list of labels separated by commas",22                    title="Zero-shot Image Classification")23 24iface.launch()