(model, img_path,prompt)
| 127 | |
| 128 | @ torch.inference_mode() |
| 129 | def generate_output(model, img_path,prompt): |
| 130 | |
| 131 | if img_path is not None: |
| 132 | image = Image.open(img_path).convert('RGB') |
| 133 | image = transform_val(image).unsqueeze(0) |
| 134 | else: |
| 135 | image = None |
| 136 | _prompt = format_prompt(prompt) |
| 137 | |
| 138 | if image is not None: |
| 139 | image = image.cuda() |
| 140 | with torch.cuda.amp.autocast(dtype=torch.bfloat16): |
| 141 | results = model.generate([_prompt], image, max_gen_len=512, temperature=0.1, top_p=0.7) |
| 142 | text_output = results[0].strip() |
| 143 | |
| 144 | return text_output |
| 145 | |
| 146 | |
| 147 |
no test coverage detected