Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,17 +29,25 @@ if st.button("Highlight Geo-Entities"):
|
|
| 29 |
if user_input.strip():
|
| 30 |
# Process the text using spaCy
|
| 31 |
doc = nlp(user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Display the highlighted text with HTML support
|
| 45 |
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 |
+
# Generate highlighted text with different colors for each entity type
|
| 34 |
+
highlighted_text = ""
|
| 35 |
+
last_pos = 0
|
| 36 |
|
| 37 |
+
for ent in doc.ents:
|
| 38 |
+
color = COLOR_MAP.get(ent.label_, ('black', ''))[0] # Default to black if label not in map
|
| 39 |
+
|
| 40 |
+
# Add text before the entity
|
| 41 |
+
highlighted_text += user_input[last_pos:ent.start_char]
|
| 42 |
+
|
| 43 |
+
# Add the highlighted entity text
|
| 44 |
+
highlighted_text += f"<span style='color:{color}; font-weight:bold'>{ent.text}</span>"
|
| 45 |
+
|
| 46 |
+
# Update the position
|
| 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)
|