Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,23 +37,24 @@ def recognize_handwritten_text(image):
|
|
37 |
return Image.fromarray(processed_image), "No text detected"
|
38 |
|
39 |
boxes = outputs[0]["boxes"]
|
40 |
-
print(f"Debug: Boxes structure = {boxes}") #
|
41 |
pil_image = Image.fromarray(processed_image)
|
42 |
texts = []
|
43 |
|
44 |
-
#
|
45 |
for box in boxes:
|
46 |
-
if len(box) == 4: # [x, y, width, height]
|
47 |
-
|
48 |
-
|
49 |
-
y_max =
|
50 |
-
elif len(box) == 2 and len(
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
y_max =
|
55 |
else:
|
56 |
-
|
|
|
57 |
|
58 |
crop = pil_image.crop((x_min, y_min, x_max, y_max))
|
59 |
pixel_values = processor(images=crop, return_tensors="pt").pixel_values
|
|
|
37 |
return Image.fromarray(processed_image), "No text detected"
|
38 |
|
39 |
boxes = outputs[0]["boxes"]
|
40 |
+
print(f"Debug: Boxes structure = {boxes}") # Log the exact structure
|
41 |
pil_image = Image.fromarray(processed_image)
|
42 |
texts = []
|
43 |
|
44 |
+
# Handle box format (assuming [x, y, width, height] or [[x1, y1], [x2, y2]])
|
45 |
for box in boxes:
|
46 |
+
if len(box) == 4: # [x, y, width, height]
|
47 |
+
x, y, width, height = box
|
48 |
+
x_min, y_min = x, y
|
49 |
+
x_max, y_max = x + width, y + height
|
50 |
+
elif len(box) == 2 and all(len(p) == 2 for p in box): # [[x1, y1], [x2, y2]]
|
51 |
+
x1, y1 = box[0]
|
52 |
+
x2, y2 = box[1]
|
53 |
+
x_min, y_min = min(x1, x2), min(y1, y2)
|
54 |
+
x_max, y_max = max(x1, x2), max(y1, y2)
|
55 |
else:
|
56 |
+
print(f"Debug: Skipping invalid box {box}") # Log invalid boxes
|
57 |
+
continue
|
58 |
|
59 |
crop = pil_image.crop((x_min, y_min, x_max, y_max))
|
60 |
pixel_values = processor(images=crop, return_tensors="pt").pixel_values
|