multimodalart HF staff commited on
Commit
8b3c656
·
1 Parent(s): 3c04d54
Files changed (1) hide show
  1. app.py +5 -5
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
- blip2_model_4_bit = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-6.7b", device_map="auto", load_in_4bit=True, torch_dtype=torch.float16)
22
 
23
  instructblip_processor = AutoProcessor.from_pretrained("Salesforce/instructblip-vicuna-7b")
24
- instructblip_model_4_bit = InstructBlipForConditionalGeneration.from_pretrained("Salesforce/instructblip-vicuna-7b", device_map="auto", load_in_4bit=True, 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,11 +58,11 @@ def generate_captions(image):
58
 
59
  caption_blip_large = generate_caption(blip_processor_large, blip_model_large, image)
60
 
61
- caption_blip2_4_bit = generate_caption_blip2(blip2_processor, blip2_model_4_bit, image).strip()
62
 
63
- caption_instructblip_4_bit = generate_caption_blip2(instructblip_processor, instructblip_model_4_bit, image)
64
 
65
- return caption_git_large_coco, caption_blip_large, caption_blip2_4_bit, caption_instructblip_4_bit
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"]]