duplicaction test
Browse files1234520 unmodified lines2627282729303132333435363730383940417 unmodified lines495051445253545556from copy import deepcopy
import gradio as grimport torchfrom transformers import AutoProcessor, LlavaForConditionalGeneration20 unmodified lines)
def text_to_image(image, prompt):def text_to_image(image, prompt, duplications: int): prompt = f'USER: <image>\n{prompt}\nASSISTANT:'
image_batch = [image] prompt_batch = [prompt] for _ in range(duplications): image_batch.append(deepcopy(image)) prompt_batch.append(prompt)
inputs = processor([prompt], images=[image], padding=True, return_tensors="pt").to(model.device) inputs = processor(prompt_batch, images=image_batch, padding=True, return_tensors="pt").to(model.device) output = model.generate(**inputs, max_new_tokens=500, temperature=0.3) generated_text = processor.batch_decode(output, skip_special_tokens=True) text = generated_text.pop()7 unmodified lines fn=text_to_image, inputs=[ gr.Image(label='Select an image to analyze', type='pil'), gr.Textbox(label='Enter Prompt') gr.Textbox(label='Enter Prompt'), gr.Number(label='How many duplications of the image (to test memory load)', value=0) ], outputs=[gr.Textbox(label='Maurice says:'), gr.JSON(label='Embedded text')])app.py+12-3