File size: 799 Bytes
daa0506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
from base64 import b64decode
from io import BytesIO

import gradio as gr
import spaces
from PIL import Image
from transformers import pipeline

model = pipeline(
    task="zero-shot-object-detection",
    model="google/owlvit-large-patch14",
)


@spaces.GPU
def predict(base64: str, texts: str):
    decoded_img = b64decode(base64)
    image_stream = BytesIO(decoded_img)
    img = Image.open(image_stream)
    predictions = model(img, text_queries=["".join(list(term)).strip() for term in texts.split(",")])
    return predictions


demo = gr.Interface(
    fn=predict,
    inputs=[
        gr.Text(label="Image (B64)"),
        gr.Text(label="Queries", placeholder="A photo of a dog,A photo of a cat")
    ],
    outputs=gr.JSON(label="Predictions"),
)
demo.launch()