Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,8 +24,8 @@ git_model_large_textcaps = AutoModelForCausalLM.from_pretrained("microsoft/git-l
|
|
24 |
blip_processor_large = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
25 |
blip_model_large = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
26 |
|
27 |
-
blip2_processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
28 |
-
blip2_model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16)
|
29 |
|
30 |
blip2_processor_8_bit = AutoProcessor.from_pretrained("Salesforce/blip2-opt-6.7b")
|
31 |
blip2_model_8_bit = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-6.7b", device_map="auto", load_in_8bit=True)
|
@@ -48,7 +48,7 @@ git_model_large_textcaps.to(device)
|
|
48 |
blip_model_large.to(device)
|
49 |
# vitgpt_model.to(device)
|
50 |
coca_model.to(device)
|
51 |
-
blip2_model.to(device)
|
52 |
|
53 |
def generate_caption(processor, model, image, tokenizer=None, use_float_16=False):
|
54 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
@@ -88,15 +88,15 @@ def generate_captions(image):
|
|
88 |
|
89 |
caption_coca = generate_caption_coca(coca_model, coca_transform, image)
|
90 |
|
91 |
-
caption_blip2 = generate_caption(blip2_processor, blip2_model, image, use_float_16=True).strip()
|
92 |
|
93 |
caption_blip2_8_bit = generate_caption(blip2_processor_8_bit, blip2_model_8_bit, image, use_float_16=True).strip()
|
94 |
|
95 |
-
return caption_git_large_coco, caption_git_large_textcaps, caption_blip_large, caption_coca,
|
96 |
|
97 |
|
98 |
examples = [["cats.jpg"], ["stop_sign.png"], ["astronaut.jpg"]]
|
99 |
-
outputs = [gr.outputs.Textbox(label="Caption generated by GIT-large fine-tuned on COCO"), gr.outputs.Textbox(label="Caption generated by GIT-large fine-tuned on TextCaps"), gr.outputs.Textbox(label="Caption generated by BLIP-large"), gr.outputs.Textbox(label="Caption generated by CoCa"), gr.outputs.Textbox(label="Caption generated by BLIP-2 OPT
|
100 |
|
101 |
title = "Interactive demo: comparing image captioning models"
|
102 |
description = "Gradio Demo to compare GIT, BLIP, CoCa, and BLIP-2, 4 state-of-the-art vision+language models. To use it, simply upload your image and click 'submit', or click one of the examples to load them. Read more at the links below."
|
|
|
24 |
blip_processor_large = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
25 |
blip_model_large = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
26 |
|
27 |
+
# blip2_processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
28 |
+
# blip2_model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16)
|
29 |
|
30 |
blip2_processor_8_bit = AutoProcessor.from_pretrained("Salesforce/blip2-opt-6.7b")
|
31 |
blip2_model_8_bit = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-6.7b", device_map="auto", load_in_8bit=True)
|
|
|
48 |
blip_model_large.to(device)
|
49 |
# vitgpt_model.to(device)
|
50 |
coca_model.to(device)
|
51 |
+
# blip2_model.to(device)
|
52 |
|
53 |
def generate_caption(processor, model, image, tokenizer=None, use_float_16=False):
|
54 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
|
|
88 |
|
89 |
caption_coca = generate_caption_coca(coca_model, coca_transform, image)
|
90 |
|
91 |
+
# caption_blip2 = generate_caption(blip2_processor, blip2_model, image, use_float_16=True).strip()
|
92 |
|
93 |
caption_blip2_8_bit = generate_caption(blip2_processor_8_bit, blip2_model_8_bit, image, use_float_16=True).strip()
|
94 |
|
95 |
+
return caption_git_large_coco, caption_git_large_textcaps, caption_blip_large, caption_coca, caption_blip2_8_bit
|
96 |
|
97 |
|
98 |
examples = [["cats.jpg"], ["stop_sign.png"], ["astronaut.jpg"]]
|
99 |
+
outputs = [gr.outputs.Textbox(label="Caption generated by GIT-large fine-tuned on COCO"), gr.outputs.Textbox(label="Caption generated by GIT-large fine-tuned on TextCaps"), gr.outputs.Textbox(label="Caption generated by BLIP-large"), gr.outputs.Textbox(label="Caption generated by CoCa"), gr.outputs.Textbox(label="Caption generated by BLIP-2 OPT 6.7b")]
|
100 |
|
101 |
title = "Interactive demo: comparing image captioning models"
|
102 |
description = "Gradio Demo to compare GIT, BLIP, CoCa, and BLIP-2, 4 state-of-the-art vision+language models. To use it, simply upload your image and click 'submit', or click one of the examples to load them. Read more at the links below."
|