Spaces:
Runtime error
Runtime error
chats-bug
commited on
Commit
·
9cce4c8
1
Parent(s):
0d54c12
Added git base coco
Browse files
app.py
CHANGED
@@ -16,7 +16,11 @@ model_blip_base = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-
|
|
16 |
preprocessor_blip_large = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
17 |
model_blip_large = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
18 |
|
19 |
-
# Load the GIT coco model
|
|
|
|
|
|
|
|
|
20 |
preprocessor_git_large_coco = AutoProcessor.from_pretrained("microsoft/git-large-coco")
|
21 |
model_git_large_coco = AutoModelForCausalLM.from_pretrained("microsoft/git-large-coco")
|
22 |
|
@@ -30,6 +34,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
30 |
# Transfer the models to the device
|
31 |
model_blip_base.to(device)
|
32 |
model_blip_large.to(device)
|
|
|
33 |
model_git_large_coco.to(device)
|
34 |
model_oc_coca.to(device)
|
35 |
|
@@ -142,8 +147,14 @@ def generate_captions(
|
|
142 |
caption_blip_large = generate_caption(preprocessor_blip_large, model_blip_large, image).strip()
|
143 |
except Exception as e:
|
144 |
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
-
# Generate captions for the image using the GIT coco model
|
147 |
try:
|
148 |
caption_git_large_coco = generate_caption(preprocessor_git_large_coco, model_git_large_coco, image).strip()
|
149 |
except Exception as e:
|
@@ -155,7 +166,7 @@ def generate_captions(
|
|
155 |
except Exception as e:
|
156 |
print(e)
|
157 |
|
158 |
-
return caption_blip_base, caption_blip_large, caption_git_large_coco, caption_oc_coca
|
159 |
|
160 |
|
161 |
# Create the interface
|
@@ -171,6 +182,7 @@ iface = gr.Interface(
|
|
171 |
outputs=[
|
172 |
gr.outputs.Textbox(label="Blip base"),
|
173 |
gr.outputs.Textbox(label="Blip large"),
|
|
|
174 |
gr.outputs.Textbox(label="GIT large coco"),
|
175 |
gr.outputs.Textbox(label="CLIP"),
|
176 |
],
|
|
|
16 |
preprocessor_blip_large = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
17 |
model_blip_large = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
18 |
|
19 |
+
# Load the GIT coco base model
|
20 |
+
preprocessor_git_base_coco = AutoProcessor.from_pretrained("microsoft/git-base-coco")
|
21 |
+
model_git_base_coco = AutoModelForCausalLM.from_pretrained("microsoft/git-base-coco")
|
22 |
+
|
23 |
+
# Load the GIT coco large model
|
24 |
preprocessor_git_large_coco = AutoProcessor.from_pretrained("microsoft/git-large-coco")
|
25 |
model_git_large_coco = AutoModelForCausalLM.from_pretrained("microsoft/git-large-coco")
|
26 |
|
|
|
34 |
# Transfer the models to the device
|
35 |
model_blip_base.to(device)
|
36 |
model_blip_large.to(device)
|
37 |
+
model_git_base_coco.to(device)
|
38 |
model_git_large_coco.to(device)
|
39 |
model_oc_coca.to(device)
|
40 |
|
|
|
147 |
caption_blip_large = generate_caption(preprocessor_blip_large, model_blip_large, image).strip()
|
148 |
except Exception as e:
|
149 |
print(e)
|
150 |
+
|
151 |
+
# Generate captions for the image using the GIT coco base model
|
152 |
+
try:
|
153 |
+
caption_git_base_coco = generate_caption(preprocessor_git_base_coco, model_git_base_coco, image).strip()
|
154 |
+
except Exception as e:
|
155 |
+
print(e)
|
156 |
|
157 |
+
# Generate captions for the image using the GIT coco large model
|
158 |
try:
|
159 |
caption_git_large_coco = generate_caption(preprocessor_git_large_coco, model_git_large_coco, image).strip()
|
160 |
except Exception as e:
|
|
|
166 |
except Exception as e:
|
167 |
print(e)
|
168 |
|
169 |
+
return caption_blip_base, caption_blip_large, caption_git_base_coco, caption_git_large_coco, caption_oc_coca
|
170 |
|
171 |
|
172 |
# Create the interface
|
|
|
182 |
outputs=[
|
183 |
gr.outputs.Textbox(label="Blip base"),
|
184 |
gr.outputs.Textbox(label="Blip large"),
|
185 |
+
gr.outputs.Textbox(label="GIT base coco"),
|
186 |
gr.outputs.Textbox(label="GIT large coco"),
|
187 |
gr.outputs.Textbox(label="CLIP"),
|
188 |
],
|