File size: 478 Bytes
5039c41
 
 
 
 
d3bc1ff
daf8484
5039c41
 
 
 
 
df25445
5039c41
df25445
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-L-14",
    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[0]).split("<end_of_text>")[0].replace("<start_of_text>", "")

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