Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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.
|
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(
|
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,
|
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]
|