Spaces:
Runtime error
Runtime error
Commit
·
8b3c656
1
Parent(s):
3c04d54
try chonk
Browse files
app.py
CHANGED
@@ -18,10 +18,10 @@ blip_processor_large = AutoProcessor.from_pretrained("Salesforce/blip-image-capt
|
|
18 |
blip_model_large = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large").to(device)
|
19 |
|
20 |
blip2_processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-6.7b")
|
21 |
-
|
22 |
|
23 |
instructblip_processor = AutoProcessor.from_pretrained("Salesforce/instructblip-vicuna-7b")
|
24 |
-
|
25 |
|
26 |
def generate_caption(processor, model, image, tokenizer=None, use_float_16=False):
|
27 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
@@ -58,11 +58,11 @@ def generate_captions(image):
|
|
58 |
|
59 |
caption_blip_large = generate_caption(blip_processor_large, blip_model_large, image)
|
60 |
|
61 |
-
|
62 |
|
63 |
-
|
64 |
|
65 |
-
return caption_git_large_coco, caption_blip_large,
|
66 |
|
67 |
|
68 |
examples = [["cats.jpg"], ["stop_sign.png"], ["astronaut.jpg"]]
|
|
|
18 |
blip_model_large = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large").to(device)
|
19 |
|
20 |
blip2_processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-6.7b")
|
21 |
+
blip2_model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-6.7b", device_map="auto", torch_dtype=torch.float16)
|
22 |
|
23 |
instructblip_processor = AutoProcessor.from_pretrained("Salesforce/instructblip-vicuna-7b")
|
24 |
+
instructblip_model = InstructBlipForConditionalGeneration.from_pretrained("Salesforce/instructblip-vicuna-7b", device_map="auto", torch_dtype=torch.float16)
|
25 |
|
26 |
def generate_caption(processor, model, image, tokenizer=None, use_float_16=False):
|
27 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
|
|
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)
|
64 |
|
65 |
+
return caption_git_large_coco, caption_blip_large, caption_blip2, caption_instructblip
|
66 |
|
67 |
|
68 |
examples = [["cats.jpg"], ["stop_sign.png"], ["astronaut.jpg"]]
|