Spaces:
Sleeping
Sleeping
File size: 560 Bytes
5039c41 7ab18eb 5039c41 7ab18eb 5039c41 d3bc1ff daf8484 5039c41 7ab18eb 5039c41 7ab18eb df25445 5039c41 1e56664 5039c41 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import gradio as gr
import open_clip
import torch
device = torch.device("cuda")
model, _, transform = open_clip.create_model_and_transforms(
"coca_ViT-L-14",
pretrained="laion2B-s13B-b90k-mscoco-2014.pt"
)
model.to(device)
def output_generate(image):
im = transform(image).unsqueeze(0).to(device)
generated = model.generate(im, seq_len=20)
return open_clip.decode(generated[0]).split("<end_of_text>")[0].replace("<start_of_text>", "")
iface = gr.Interface(fn=output_generate, inputs=gr.Image(type="pil"), outputs="text")
iface.launch() |