ShreyMehra commited on
Commit
ea4b257
β€’
1 Parent(s): ea7519a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -28,8 +28,8 @@ class UI:
28
 
29
  with st.spinner("πŸ€– AI is at Work! "):
30
  device = "cuda" if torch.cuda.is_available() else "cpu"
31
- print(1)
32
- inputs = processor(images=input_image, return_tensors="pt").to(device, torch.float32)
33
 
34
  print(2)
35
  pixel_values = inputs.pixel_values
@@ -38,7 +38,7 @@ class UI:
38
  # pixel_values = pixel_values.to(torch.float32)
39
 
40
  print(3)
41
- generated_ids = model.to(device, torch.float32).generate(pixel_values=pixel_values, max_length=25)
42
 
43
  print(4)
44
  generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
@@ -58,7 +58,7 @@ class Model:
58
  def load_model(self):
59
  global model
60
  global processor
61
- model = Blip2ForConditionalGeneration.from_pretrained("Shrey23/Image-Captioning", torch_dtype=torch.float16) #, device_map="auto", load_in_8bit=True
62
  processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
63
 
64
  def main():
 
28
 
29
  with st.spinner("πŸ€– AI is at Work! "):
30
  device = "cuda" if torch.cuda.is_available() else "cpu"
31
+ print(1, device)
32
+ inputs = processor(images=input_image, return_tensors="pt").to(device, torch.float16)
33
 
34
  print(2)
35
  pixel_values = inputs.pixel_values
 
38
  # pixel_values = pixel_values.to(torch.float32)
39
 
40
  print(3)
41
+ generated_ids = model.generate(pixel_values=pixel_values, max_length=25) #.to(device, torch.float32)
42
 
43
  print(4)
44
  generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
 
58
  def load_model(self):
59
  global model
60
  global processor
61
+ model = Blip2ForConditionalGeneration.from_pretrained("Shrey23/Image-Captioning", device_map="auto", load_in_8bit=True, torch_dtype=torch.float16) #,
62
  processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
63
 
64
  def main():