Spaces:
Runtime error
Runtime error
disabled models except blip2
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoProcessor,
|
|
|
|
|
3 |
import torch
|
4 |
import open_clip
|
5 |
|
@@ -18,17 +20,17 @@ torch.hub.download_url_to_file('https://cdn.openai.com/dall-e-2/demos/text2im/as
|
|
18 |
# git_processor_large_textcaps = AutoProcessor.from_pretrained("microsoft/git-large-r-textcaps")
|
19 |
# git_model_large_textcaps = AutoModelForCausalLM.from_pretrained("microsoft/git-large-r-textcaps")
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
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)
|
32 |
|
33 |
# vitgpt_processor = AutoImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
34 |
# vitgpt_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
@@ -42,10 +44,10 @@ blip2_model_8_bit = Blip2ForConditionalGeneration.from_pretrained("Salesforce/bl
|
|
42 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
43 |
|
44 |
# git_model_base.to(device)
|
45 |
-
|
46 |
# git_model_large_coco.to(device)
|
47 |
# 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)
|
@@ -80,9 +82,9 @@ def generate_captions(image):
|
|
80 |
|
81 |
# caption_git_large_textcaps = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
|
82 |
|
83 |
-
|
84 |
|
85 |
-
caption_blip_large = generate_caption(blip_processor_large, blip_model_large, image)
|
86 |
|
87 |
# caption_vitgpt = generate_caption(vitgpt_processor, vitgpt_model, image, vitgpt_tokenizer)
|
88 |
|
@@ -90,16 +92,16 @@ def generate_captions(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 |
-
return
|
97 |
|
98 |
|
99 |
|
100 |
examples = [["cats.jpg"], ["stop_sign.png"], ["astronaut.jpg"]]
|
101 |
# 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")]
|
102 |
-
outputs = [gr.outputs.Textbox(label="Caption generated by BLIP-
|
103 |
|
104 |
title = "Interactive demo: comparing image captioning models"
|
105 |
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."
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoProcessor, BlipForConditionalGeneration
|
3 |
+
|
4 |
+
# from transformers import AutoProcessor, AutoTokenizer, AutoImageProcessor, AutoModelForCausalLM, BlipForConditionalGeneration, Blip2ForConditionalGeneration, VisionEncoderDecoderModel
|
5 |
import torch
|
6 |
import open_clip
|
7 |
|
|
|
20 |
# git_processor_large_textcaps = AutoProcessor.from_pretrained("microsoft/git-large-r-textcaps")
|
21 |
# git_model_large_textcaps = AutoModelForCausalLM.from_pretrained("microsoft/git-large-r-textcaps")
|
22 |
|
23 |
+
blip_processor_base = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
24 |
+
blip_model_base = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
25 |
|
26 |
+
# blip_processor_large = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
27 |
+
# blip_model_large = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
28 |
|
29 |
# blip2_processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
30 |
# blip2_model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16)
|
31 |
|
32 |
+
# blip2_processor_8_bit = AutoProcessor.from_pretrained("Salesforce/blip2-opt-6.7b")
|
33 |
+
# blip2_model_8_bit = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-6.7b", device_map="auto", load_in_8bit=True)
|
34 |
|
35 |
# vitgpt_processor = AutoImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
36 |
# vitgpt_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
|
|
44 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
45 |
|
46 |
# git_model_base.to(device)
|
47 |
+
blip_model_base.to(device)
|
48 |
# git_model_large_coco.to(device)
|
49 |
# git_model_large_textcaps.to(device)
|
50 |
+
# blip_model_large.to(device)
|
51 |
# vitgpt_model.to(device)
|
52 |
# coca_model.to(device)
|
53 |
# blip2_model.to(device)
|
|
|
82 |
|
83 |
# caption_git_large_textcaps = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
|
84 |
|
85 |
+
caption_blip_base = generate_caption(blip_processor_base, blip_model_base, image)
|
86 |
|
87 |
+
# caption_blip_large = generate_caption(blip_processor_large, blip_model_large, image)
|
88 |
|
89 |
# caption_vitgpt = generate_caption(vitgpt_processor, vitgpt_model, image, vitgpt_tokenizer)
|
90 |
|
|
|
92 |
|
93 |
# caption_blip2 = generate_caption(blip2_processor, blip2_model, image, use_float_16=True).strip()
|
94 |
|
95 |
+
# caption_blip2_8_bit = generate_caption(blip2_processor_8_bit, blip2_model_8_bit, image, use_float_16=True).strip()
|
96 |
|
97 |
# return caption_git_large_coco, caption_git_large_textcaps, caption_blip_large, caption_coca, caption_blip2_8_bit
|
98 |
+
return caption_blip_base
|
99 |
|
100 |
|
101 |
|
102 |
examples = [["cats.jpg"], ["stop_sign.png"], ["astronaut.jpg"]]
|
103 |
# 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")]
|
104 |
+
outputs = [gr.outputs.Textbox(label="Caption generated by BLIP-base"),]
|
105 |
|
106 |
title = "Interactive demo: comparing image captioning models"
|
107 |
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."
|