phamvi856 commited on
Commit
91a6c4e
1 Parent(s): e0e589a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -57,7 +57,7 @@ def process_image(image):
57
  encoding = processor(image, truncation=True, padding="max_length", max_length=512, return_tensors="pt")
58
  input_ids = encoding.input_ids.to(device)
59
  attention_mask = encoding.attention_mask.to(device)
60
- bbox = encoding.bbox.to(device)
61
 
62
  # Inference
63
  outputs = model(input_ids=input_ids, bbox=bbox, attention_mask=attention_mask)
@@ -65,7 +65,7 @@ def process_image(image):
65
 
66
  # Extract content from boxes
67
  extracted_content = {}
68
- for idx, box in enumerate(encoding.bbox.tolist()):
69
  predicted_label = id2label[predicted_labels[idx]]
70
  box_width = np.array(box)[2] - np.array(box)[0]
71
  box_height = np.array(box)[3] - np.array(box)[1]
@@ -75,7 +75,7 @@ def process_image(image):
75
  # Draw predictions over the image
76
  draw = ImageDraw.Draw(image)
77
  font = ImageFont.load_default()
78
- for prediction, box in zip(predicted_labels, encoding.bbox.tolist()):
79
  predicted_label = iob_to_label(id2label[prediction])
80
  box_width = np.array(box)[2] - np.array(box)[0]
81
  box_height = np.array(box)[3] - np.array(box)[1]
 
57
  encoding = processor(image, truncation=True, padding="max_length", max_length=512, return_tensors="pt")
58
  input_ids = encoding.input_ids.to(device)
59
  attention_mask = encoding.attention_mask.to(device)
60
+ bbox = encoding.bbox[0].tolist()
61
 
62
  # Inference
63
  outputs = model(input_ids=input_ids, bbox=bbox, attention_mask=attention_mask)
 
65
 
66
  # Extract content from boxes
67
  extracted_content = {}
68
+ for idx, box in enumerate(bbox):
69
  predicted_label = id2label[predicted_labels[idx]]
70
  box_width = np.array(box)[2] - np.array(box)[0]
71
  box_height = np.array(box)[3] - np.array(box)[1]
 
75
  # Draw predictions over the image
76
  draw = ImageDraw.Draw(image)
77
  font = ImageFont.load_default()
78
+ for prediction, box in zip(predicted_labels, bbox):
79
  predicted_label = iob_to_label(id2label[prediction])
80
  box_width = np.array(box)[2] - np.array(box)[0]
81
  box_height = np.array(box)[3] - np.array(box)[1]