Spaces:
Runtime error
Runtime error
paul hilders
commited on
Commit
•
39c7251
1
Parent(s):
41478ca
Add Entity: to labels
Browse files
app.py
CHANGED
@@ -78,11 +78,14 @@ iface = gr.Interface(fn=run_demo,
|
|
78 |
["example_images/dogs_on_bed.png", "Cat"]])
|
79 |
|
80 |
# NER demo:
|
81 |
-
def add_label_to_img(img, label):
|
82 |
img = ImageOps.expand(img, border=45, fill=(255,255,255))
|
83 |
draw = ImageDraw.Draw(img)
|
84 |
-
font = ImageFont.truetype("arial.ttf",
|
85 |
-
|
|
|
|
|
|
|
86 |
|
87 |
return img
|
88 |
|
@@ -99,7 +102,7 @@ def NER_demo(image, text):
|
|
99 |
overlapped, highlighted_text = run_demo(image, text)
|
100 |
|
101 |
# Then, we run the demo for each of the named entities:
|
102 |
-
gallery_images = [overlapped]
|
103 |
for ent_text, ent_label in highlighed_entities:
|
104 |
overlapped_ent, highlighted_text_ent = run_demo(image, ent_text)
|
105 |
overlapped_ent_labelled = add_label_to_img(overlapped_ent, ent_text)
|
|
|
78 |
["example_images/dogs_on_bed.png", "Cat"]])
|
79 |
|
80 |
# NER demo:
|
81 |
+
def add_label_to_img(img, label, add_entity_label=True):
|
82 |
img = ImageOps.expand(img, border=45, fill=(255,255,255))
|
83 |
draw = ImageDraw.Draw(img)
|
84 |
+
font = ImageFont.truetype("arial.ttf", 24)
|
85 |
+
if add_entity_label:
|
86 |
+
draw.text((0,0), "Entity: " + str(label), align="center", fill=(0, 0, 0), font=font)
|
87 |
+
else:
|
88 |
+
draw.text((0,0), str(label), align="center", fill=(0, 0, 0), font=font)
|
89 |
|
90 |
return img
|
91 |
|
|
|
102 |
overlapped, highlighted_text = run_demo(image, text)
|
103 |
|
104 |
# Then, we run the demo for each of the named entities:
|
105 |
+
gallery_images = [add_label_to_img(overlapped, "Full explanation", add_entity_label=False)]
|
106 |
for ent_text, ent_label in highlighed_entities:
|
107 |
overlapped_ent, highlighted_text_ent = run_demo(image, ent_text)
|
108 |
overlapped_ent_labelled = add_label_to_img(overlapped_ent, ent_text)
|