Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -59,10 +59,18 @@ def iob_to_label(label):
|
|
59 |
return label
|
60 |
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
def process_image(image):
|
64 |
|
65 |
-
|
66 |
width, height = image.size
|
67 |
|
68 |
# encode
|
@@ -84,11 +92,10 @@ def process_image(image):
|
|
84 |
# draw predictions over the image
|
85 |
draw = ImageDraw.Draw(image)
|
86 |
font = ImageFont.load_default()
|
87 |
-
for prediction, box in zip(true_predictions, true_boxes):
|
88 |
predicted_label = iob_to_label(prediction)
|
89 |
draw.rectangle(box, outline=label2color[predicted_label])
|
90 |
-
draw.text((box[0]+10, box[1]
|
91 |
-
draw.text((box[0]+10, box[1]+10), text=dataset[0]["ner_tags"][id], fill='black', font=font)
|
92 |
|
93 |
return image
|
94 |
|
@@ -112,4 +119,4 @@ iface = gr.Interface(fn=process_image,
|
|
112 |
css=css,
|
113 |
analytics_enabled = True, enable_queue=True)
|
114 |
|
115 |
-
iface.launch(inline=False, share=False, debug=False)
|
|
|
59 |
return label
|
60 |
|
61 |
|
62 |
+
def print_content(image, predictions, token_boxes, ner_tags):
|
63 |
+
width, height = image.size
|
64 |
+
content_list = []
|
65 |
+
for prediction, box, tag in zip(predictions, token_boxes, ner_tags):
|
66 |
+
if not is_subword[idx]:
|
67 |
+
predicted_label = iob_to_label(prediction)
|
68 |
+
content = image.crop(box).copy().convert("RGB")
|
69 |
+
content_list.append((predicted_label, tag, content))
|
70 |
+
return content_list
|
71 |
|
|
|
72 |
|
73 |
+
def process_image(image, ner_tags):
|
74 |
width, height = image.size
|
75 |
|
76 |
# encode
|
|
|
92 |
# draw predictions over the image
|
93 |
draw = ImageDraw.Draw(image)
|
94 |
font = ImageFont.load_default()
|
95 |
+
for prediction, box, ner_tag in zip(true_predictions, true_boxes, ner_tags):
|
96 |
predicted_label = iob_to_label(prediction)
|
97 |
draw.rectangle(box, outline=label2color[predicted_label])
|
98 |
+
draw.text((box[0]+10, box[1]+10), text=ner_tag, fill='black', font=font)
|
|
|
99 |
|
100 |
return image
|
101 |
|
|
|
119 |
css=css,
|
120 |
analytics_enabled = True, enable_queue=True)
|
121 |
|
122 |
+
iface.launch(inline=False, share=False, debug=False)
|