Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,25 +29,17 @@ if st.button("Highlight Geo-Entities"):
|
|
| 29 |
if user_input.strip():
|
| 30 |
# Process the text using spaCy
|
| 31 |
doc = nlp(user_input)
|
| 32 |
-
|
| 33 |
-
# Generate highlighted text with different colors for each entity type
|
| 34 |
-
highlighted_text = ""
|
| 35 |
-
last_pos = 0
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
last_pos = ent.end_char
|
| 48 |
-
|
| 49 |
-
# Add any remaining text after the last entity
|
| 50 |
-
highlighted_text += user_input[last_pos:]
|
| 51 |
|
| 52 |
# Display the highlighted text with HTML support
|
| 53 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
|
|
|
| 29 |
if user_input.strip():
|
| 30 |
# Process the text using spaCy
|
| 31 |
doc = nlp(user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# Highlight geo-entities with different colors
|
| 34 |
+
highlighted_text = user_input
|
| 35 |
+
for ent in reversed(doc.ents):
|
| 36 |
+
if ent.label_ in COLOR_MAP:
|
| 37 |
+
color = COLOR_MAP[ent.label_][0]
|
| 38 |
+
highlighted_text = (
|
| 39 |
+
highlighted_text[:ent.start_char] +
|
| 40 |
+
f"<span style='color:{color}; font-weight:bold'>{ent.text}</span>" +
|
| 41 |
+
highlighted_text[ent.end_char:]
|
| 42 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Display the highlighted text with HTML support
|
| 45 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|