File size: 473 Bytes
5039c41
 
 
 
 
 
daf8484
5039c41
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import gradio as gr
import open_clip


model, _, transform = open_clip.create_model_and_transforms(
    "coca_ViT-B-32",
    pretrained="laion2B-s13B-b90k-mscoco-2014.pt"
)

def output_generate(image):
    im = transform(image).unsqueeze(0)
    generated = model.generate(im)
    return open_clip.decode(generated).split("<end_of_text>")[0].replace("<start_of_text>", "")

iface = gr.Interface(fn=output_generate, inputs=gr.image(type="pil"), outputs="text")
iface.launch()