yuragoithf commited on
Commit
217a758
·
verified ·
1 Parent(s): 17b3106

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
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}") # Debug output to logs
41
  pil_image = Image.fromarray(processed_image)
42
  texts = []
43
 
44
- # Adjust box unpacking based on actual structure
45
  for box in boxes:
46
- if len(box) == 4: # [x, y, width, height] format
47
- x_min, y_min, width, height = box
48
- x_max = x_min + width
49
- y_max = y_min + height
50
- elif len(box) == 2 and len(box[0]) == 2: # [[x, y], [width, height]] format
51
- x_min, y_min = box[0]
52
- width, height = box[1]
53
- x_max = x_min + width
54
- y_max = y_min + height
55
  else:
56
- continue # Skip invalid boxes
 
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