Spaces:
Runtime error
Runtime error
ahmedmbutt
commited on
Commit
•
61ab183
1
Parent(s):
00513e4
Update app.py
Browse files
app.py
CHANGED
@@ -238,14 +238,13 @@ def inference(img,model_name):
|
|
238 |
model_path = coco_weight
|
239 |
else:
|
240 |
model_path = conceptual_weight
|
241 |
-
model.load_state_dict(torch.load(model_path, map_location=CPU))
|
242 |
model = model.eval()
|
243 |
device = CUDA(0) if is_gpu else "cpu"
|
244 |
model = model.to(device)
|
245 |
|
246 |
use_beam_search = False
|
247 |
-
|
248 |
-
pil_image = PIL.Image.fromarray(image)
|
249 |
image = preprocess(pil_image).unsqueeze(0).to(device)
|
250 |
with torch.no_grad():
|
251 |
prefix = clip_model.encode_image(image).to(device, dtype=torch.float32)
|
@@ -263,11 +262,10 @@ article = "<p style='text-align: center'><a href='https://github.com/rmokady/CLI
|
|
263 |
examples=[['water.jpeg',"COCO"]]
|
264 |
gr.Interface(
|
265 |
inference,
|
266 |
-
[gr.
|
267 |
-
gr.
|
268 |
title=title,
|
269 |
description=description,
|
270 |
article=article,
|
271 |
-
enable_queue=True,
|
272 |
examples=examples
|
273 |
).launch(debug=True)
|
|
|
238 |
model_path = coco_weight
|
239 |
else:
|
240 |
model_path = conceptual_weight
|
241 |
+
model.load_state_dict(torch.load(model_path, map_location=CPU), strict=False)
|
242 |
model = model.eval()
|
243 |
device = CUDA(0) if is_gpu else "cpu"
|
244 |
model = model.to(device)
|
245 |
|
246 |
use_beam_search = False
|
247 |
+
pil_image = PIL.Image.fromarray(img)
|
|
|
248 |
image = preprocess(pil_image).unsqueeze(0).to(device)
|
249 |
with torch.no_grad():
|
250 |
prefix = clip_model.encode_image(image).to(device, dtype=torch.float32)
|
|
|
262 |
examples=[['water.jpeg',"COCO"]]
|
263 |
gr.Interface(
|
264 |
inference,
|
265 |
+
inputs=[gr.Image(label="Input"),gr.Radio(choices=["COCO","Conceptual captions"], value="COCO", label="Model")],
|
266 |
+
outputs=gr.Textbox(label="Output"),
|
267 |
title=title,
|
268 |
description=description,
|
269 |
article=article,
|
|
|
270 |
examples=examples
|
271 |
).launch(debug=True)
|