JasonTPhillipsJr commited on
Commit
cfadf58
·
verified ·
1 Parent(s): 9822204

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
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
- # 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)
 
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)