Spaces:
Build error
Build error
File size: 1,134 Bytes
a9069a7 |
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 33 34 35 36 37 38 39 40 41 |
import torch
from rudalle import get_tokenizer, get_vae
from rudalle.utils import seed_everything
import sys
from rudolph.model.utils import get_i2t_attention_mask, get_t2t_attention_mask
from rudolph.model import get_rudolph_model, ruDolphModel, FP16Module
from rudolph.pipelines import generate_codebooks, self_reranking_by_image, self_reranking_by_text, show, generate_captions, generate_texts from rudolph.pipelines import zs_clf
import gradio as gr
from rudolph import utils
device = 'cuda'
model = get_rudolph_model('350M', fp16=True, device='cuda')
tokenizer = get_tokenizer()
vae = get_vae(dwt=False).to(device)
# Download human-readable labels for ImageNet.
def classify_image(inp):
print(type(inp))
inp = Image.fromarray(inp)
texts = generate_captions(inp, tokenizer, model, vae, template=template, top_k=16, captions_num=1, bs=16, top_p=0.6, seed=43, temperature=0.8)
return texts
image = gr.inputs.Image(shape=(128, 128))
label = gr.outputs.Label(num_top_classes=3)
iface = gr.Interface(fn=classify_image, inputs=image, outputs="text",examples=[
['b9c277a3.jpeg']])
iface.launch(share=True)
|