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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -8,19 +8,20 @@ nlp = spacy.load("./models/en_core_web_sm")
8
  st.title("SpaGAN Demo")
9
  st.write("Enter a text, and the system will highlight the geo-entities within it.")
10
 
11
- # Define a color map for different entity types
12
  COLOR_MAP = {
13
- 'FAC': 'red', # Facilities (e.g., buildings, airports)
14
- 'ORG': 'blue', # Organizations (e.g., companies, institutions)
15
- 'LOC': 'purple', # Locations (e.g., mountain ranges, water bodies)
16
- 'GPE': 'green' # Geopolitical Entities (e.g., countries, cities)
17
  }
18
 
19
- # Display the color key
20
  st.write("**Color Key:**")
21
- for label, color in COLOR_MAP.items():
22
- st.markdown(f"- **{label}**: <span style='color:{color}'>{color}</span>", unsafe_allow_html=True)
23
 
 
24
  user_input = st.text_area("Input Text", height=200)
25
 
26
  # Process the text when the button is clicked
@@ -33,7 +34,7 @@ if st.button("Highlight Geo-Entities"):
33
  highlighted_text = user_input
34
  for ent in reversed(doc.ents):
35
  if ent.label_ in COLOR_MAP:
36
- color = COLOR_MAP[ent.label_]
37
  highlighted_text = (
38
  highlighted_text[:ent.start_char] +
39
  f"<span style='color:{color}; font-weight:bold'>{ent.text}</span>" +
 
8
  st.title("SpaGAN Demo")
9
  st.write("Enter a text, and the system will highlight the geo-entities within it.")
10
 
11
+ # Define a color map and descriptions for different entity types
12
  COLOR_MAP = {
13
+ 'FAC': ('red', 'Facilities (e.g., buildings, airports)'),
14
+ 'ORG': ('blue', 'Organizations (e.g., companies, institutions)'),
15
+ 'LOC': ('purple', 'Locations (e.g., mountain ranges, water bodies)'),
16
+ 'GPE': ('green', 'Geopolitical Entities (e.g., countries, cities)')
17
  }
18
 
19
+ # Display the color key with descriptions
20
  st.write("**Color Key:**")
21
+ for label, (color, description) in COLOR_MAP.items():
22
+ st.markdown(f"- **{label}**: <span style='color:{color}'>{color}</span> - {description}", unsafe_allow_html=True)
23
 
24
+ # Text input
25
  user_input = st.text_area("Input Text", height=200)
26
 
27
  # Process the text when the button is clicked
 
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>" +