Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,19 @@ 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 |
user_input = st.text_area("Input Text", height=200)
|
| 12 |
|
| 13 |
# Process the text when the button is clicked
|
|
@@ -16,19 +29,18 @@ if st.button("Highlight Geo-Entities"):
|
|
| 16 |
# Process the text using spaCy
|
| 17 |
doc = nlp(user_input)
|
| 18 |
|
| 19 |
-
# Highlight geo-entities
|
| 20 |
highlighted_text = user_input
|
| 21 |
for ent in reversed(doc.ents):
|
| 22 |
-
if ent.label_ in
|
|
|
|
| 23 |
highlighted_text = (
|
| 24 |
highlighted_text[:ent.start_char] +
|
| 25 |
-
f"
|
| 26 |
highlighted_text[ent.end_char:]
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# Display the highlighted text
|
| 30 |
-
st.markdown(highlighted_text)
|
| 31 |
else:
|
| 32 |
-
st.error("Please enter some text.")
|
| 33 |
-
|
| 34 |
-
st.write("Note: The model identifies and highlights geo-entities.")
|
|
|
|
| 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
|
|
|
|
| 29 |
# Process the text using spaCy
|
| 30 |
doc = nlp(user_input)
|
| 31 |
|
| 32 |
+
# Highlight geo-entities with different colors
|
| 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>" +
|
| 40 |
highlighted_text[ent.end_char:]
|
| 41 |
)
|
| 42 |
|
| 43 |
+
# Display the highlighted text with HTML support
|
| 44 |
+
st.markdown(highlighted_text, unsafe_allow_html=True)
|
| 45 |
else:
|
| 46 |
+
st.error("Please enter some text.")
|
|
|
|
|
|