Update app.py
Browse files
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
|
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 |
+
|