File size: 528 Bytes
c16c3d0
 
 
 
1128830
c16c3d0
1128830
 
 
c16c3d0
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import gradio as gr
from PIL import Image
# Use a pipeline as a high-level helper
from transformers import pipeline
import torch

device = "cuda" if torch.cuda.is_available() else "cpu"

pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-large-patch14",device=0 if device == "cuda" else -1)
def classify_image(image):
    result = pipe(image, ["cat", "dog", "car", "person", "building"])
    return result

demo = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil"), outputs="json")

demo.launch()