Pretam1 commited on
Commit
319d3d6
·
verified ·
1 Parent(s): 9b0c2df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -22,9 +22,9 @@ def predict_caption(image):
22
  if image.mode != "RGB":
23
  image = image.convert(mode="RGB")
24
 
25
- # Process image and move pixel values to device
26
- pixel_values = feature_extractor(images=[image], return_tensors="pt").pixel_values.to(device)
27
-
28
  # Generate caption
29
  output_ids = model.generate(pixel_values, **gen_kwargs)
30
  preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
@@ -52,3 +52,4 @@ def main():
52
  # Run the application
53
  if __name__ == "__main__":
54
  main()
 
 
22
  if image.mode != "RGB":
23
  image = image.convert(mode="RGB")
24
 
25
+ # Process image with padding enabled to handle batched tensor conversion
26
+ pixel_values = feature_extractor(images=[image], return_tensors="pt", padding=True).pixel_values.to(device)
27
+
28
  # Generate caption
29
  output_ids = model.generate(pixel_values, **gen_kwargs)
30
  preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
 
52
  # Run the application
53
  if __name__ == "__main__":
54
  main()
55
+