Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ ENTITY_COLORS = {
|
|
| 12 |
"B-ORG": "#3380FF",
|
| 13 |
"I-ORG": "#1A66FF",
|
| 14 |
"O": "#E0E0E0"
|
| 15 |
-
}
|
| 16 |
|
| 17 |
def highlight_entities(text):
|
| 18 |
"""
|
|
@@ -41,6 +41,7 @@ def highlight_entities(text):
|
|
| 41 |
|
| 42 |
formatted_text += text[last_idx:]
|
| 43 |
|
|
|
|
| 44 |
legend_html = "<div><b>Legend:</b><br>"
|
| 45 |
for label, color in ENTITY_COLORS.items():
|
| 46 |
legend_html += f'<span style="background-color:{color}; padding:2px 5px; border-radius:5px; margin-right:5px;">{label}</span>'
|
|
@@ -48,14 +49,25 @@ def highlight_entities(text):
|
|
| 48 |
|
| 49 |
return legend_html + formatted_text
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
grn = gr.Interface(
|
| 54 |
fn=highlight_entities,
|
| 55 |
-
inputs=gr.Textbox(label="Enter Spanish Text"
|
| 56 |
outputs=gr.HTML(label="NER Highlighted Text"),
|
| 57 |
title="Spanish Named Entity Recognition",
|
| 58 |
description="This interactive demo performs Named Entity Recognition (NER) on Spanish text. Recognized entities such as persons, locations, and organizations are highlighted in distinct colors for better readability. A legend is provided to help interpret the color coding.",
|
|
|
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
grn.launch()
|
|
|
|
| 12 |
"B-ORG": "#3380FF",
|
| 13 |
"I-ORG": "#1A66FF",
|
| 14 |
"O": "#E0E0E0"
|
| 15 |
+
}
|
| 16 |
|
| 17 |
def highlight_entities(text):
|
| 18 |
"""
|
|
|
|
| 41 |
|
| 42 |
formatted_text += text[last_idx:]
|
| 43 |
|
| 44 |
+
# Generate legend
|
| 45 |
legend_html = "<div><b>Legend:</b><br>"
|
| 46 |
for label, color in ENTITY_COLORS.items():
|
| 47 |
legend_html += f'<span style="background-color:{color}; padding:2px 5px; border-radius:5px; margin-right:5px;">{label}</span>'
|
|
|
|
| 49 |
|
| 50 |
return legend_html + formatted_text
|
| 51 |
|
| 52 |
+
example_sentences = [
|
| 53 |
+
"Elon Musk vive en Estados Unidos y es due帽o de SpaceX, Tesla y Starlink.",
|
| 54 |
+
"Lionel Messi juega para el Inter Miami y ha ganado m煤ltiples Bal贸n de Oro.",
|
| 55 |
+
"Amazon es una de las empresas tecnol贸gicas m谩s grandes con sede en Seattle, EE.UU.",
|
| 56 |
+
"Madrid es la capital de Espa帽a y alberga el famoso museo del Prado.",
|
| 57 |
+
"Shakira naci贸 en Colombia y es una de las artistas m谩s reconocidas a nivel mundial."
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
def example_selector(example):
|
| 61 |
+
return highlight_entities(example)
|
| 62 |
|
| 63 |
grn = gr.Interface(
|
| 64 |
fn=highlight_entities,
|
| 65 |
+
inputs=gr.Textbox(label="Enter Spanish Text"),
|
| 66 |
outputs=gr.HTML(label="NER Highlighted Text"),
|
| 67 |
title="Spanish Named Entity Recognition",
|
| 68 |
description="This interactive demo performs Named Entity Recognition (NER) on Spanish text. Recognized entities such as persons, locations, and organizations are highlighted in distinct colors for better readability. A legend is provided to help interpret the color coding.",
|
| 69 |
+
examples=example_sentences,
|
| 70 |
+
allow_flagging="never"
|
| 71 |
)
|
| 72 |
|
| 73 |
grn.launch()
|