ShreyMehra commited on
Commit
90db0fc
·
unverified ·
1 Parent(s): bdb81d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -38,10 +38,13 @@ class UI:
38
  # print(3)
39
  # pixel_values = pixel_values.to(torch.float32)
40
 
41
- print(4)
42
  generated_ids = model.to(device, torch.float32).generate(pixel_values=pixel_values, max_length=25)
 
 
43
  generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
44
 
 
45
  st.write(generated_caption)
46
 
47
  st.success("Here you go!")
@@ -55,10 +58,12 @@ class UI:
55
  class Model:
56
  def load_model(self):
57
  peft_model_id = "Shrey23/Image-Captioning"
58
- config = PeftConfig.from_pretrained(peft_model_id)
59
  global model
60
  global processor
61
- model = Blip2ForConditionalGeneration.from_pretrained(config.base_model_name_or_path, low_cpu_mem_usage=True, torch_dtype=torch.float16) #, device_map="auto", load_in_8bit=True
 
 
62
  model = PeftModel.from_pretrained(model, peft_model_id)
63
  processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
64
 
 
38
  # print(3)
39
  # pixel_values = pixel_values.to(torch.float32)
40
 
41
+ print(3)
42
  generated_ids = model.to(device, torch.float32).generate(pixel_values=pixel_values, max_length=25)
43
+
44
+ print(4)
45
  generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
46
 
47
+ print(5, generated_caption)
48
  st.write(generated_caption)
49
 
50
  st.success("Here you go!")
 
58
  class Model:
59
  def load_model(self):
60
  peft_model_id = "Shrey23/Image-Captioning"
61
+ # config = PeftConfig.from_pretrained(peft_model_id)
62
  global model
63
  global processor
64
+ PATH = "./model/"
65
+ local_files_only=True
66
+ model = Blip2ForConditionalGeneration.from_pretrained(PATH, local_files_only=True, low_cpu_mem_usage=True, torch_dtype=torch.float16) #, device_map="auto", load_in_8bit=True
67
  model = PeftModel.from_pretrained(model, peft_model_id)
68
  processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
69