Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -39,7 +39,8 @@ def generate_caption(processor, model, image, tokenizer=None, use_float_16=False
|
|
39 |
return generated_caption
|
40 |
|
41 |
|
42 |
-
def generate_caption_blip2(processor, model, image,
|
|
|
43 |
inputs = processor(images=image, text=prompt, return_tensors="pt").to(device=model.device, dtype=torch.float16)
|
44 |
|
45 |
generated_ids = model.generate(**inputs,
|
@@ -57,9 +58,9 @@ def generate_captions(image):
|
|
57 |
|
58 |
caption_blip_large = generate_caption(blip_processor_large, blip_model_large, image)
|
59 |
|
60 |
-
caption_blip2 = generate_caption_blip2(blip2_processor, blip2_model, image
|
61 |
|
62 |
-
caption_instructblip = generate_caption_blip2(instructblip_processor, instructblip_model, image,
|
63 |
|
64 |
return caption_git_large_coco, caption_blip_large, caption_blip2, caption_instructblip
|
65 |
|
|
|
39 |
return generated_caption
|
40 |
|
41 |
|
42 |
+
def generate_caption_blip2(processor, model, image, replace_token=False):
|
43 |
+
prompt = "A photo of"
|
44 |
inputs = processor(images=image, text=prompt, return_tensors="pt").to(device=model.device, dtype=torch.float16)
|
45 |
|
46 |
generated_ids = model.generate(**inputs,
|
|
|
58 |
|
59 |
caption_blip_large = generate_caption(blip_processor_large, blip_model_large, image)
|
60 |
|
61 |
+
caption_blip2 = generate_caption_blip2(blip2_processor, blip2_model, image).strip()
|
62 |
|
63 |
+
caption_instructblip = generate_caption_blip2(instructblip_processor, instructblip_model, image, replace_token=True)
|
64 |
|
65 |
return caption_git_large_coco, caption_blip_large, caption_blip2, caption_instructblip
|
66 |
|