nielsr HF staff commited on
Commit
c62ee55
1 Parent(s): 857eed2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -22,10 +22,10 @@ def box_cxcywh_to_xyxy(x):
22
 
23
 
24
  def rescale_bboxes(out_bbox, size):
25
- img_w, img_h = size
26
- b = box_cxcywh_to_xyxy(out_bbox)
27
- b = b * torch.tensor([img_w, img_h, img_w, img_h], dtype=torch.float32)
28
- return b
29
 
30
 
31
  def outputs_to_objects(outputs, img_size, id2label):
@@ -50,8 +50,8 @@ def fig2img(fig):
50
  buf = io.BytesIO()
51
  fig.savefig(buf)
52
  buf.seek(0)
53
- img = Image.open(buf)
54
- return img
55
 
56
 
57
  def visualize_detected_tables(img, det_tables):
@@ -117,7 +117,7 @@ def detect_table(image):
117
  detected_tables = outputs_to_objects(outputs, image.size, id2label)
118
 
119
  # visualize
120
- fig = visualize_detected_tables(img, detected_tables)
121
  image = fig2img(fig)
122
 
123
  return image
 
22
 
23
 
24
  def rescale_bboxes(out_bbox, size):
25
+ width, height = size
26
+ boxes = box_cxcywh_to_xyxy(out_bbox)
27
+ boxes = boxes * torch.tensor([width, height, width, height], dtype=torch.float32)
28
+ return boxes
29
 
30
 
31
  def outputs_to_objects(outputs, img_size, id2label):
 
50
  buf = io.BytesIO()
51
  fig.savefig(buf)
52
  buf.seek(0)
53
+ image = Image.open(buf)
54
+ return image
55
 
56
 
57
  def visualize_detected_tables(img, det_tables):
 
117
  detected_tables = outputs_to_objects(outputs, image.size, id2label)
118
 
119
  # visualize
120
+ fig = visualize_detected_tables(image, detected_tables)
121
  image = fig2img(fig)
122
 
123
  return image