Spaces:
Sleeping
Sleeping
JasonTPhillipsJr
commited on
Commit
•
5c91758
1
Parent(s):
52dffea
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,34 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
4 |
|
5 |
-
|
6 |
|
7 |
-
st.title("
|
|
|
8 |
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import spacy
|
3 |
from transformers import pipeline
|
4 |
from PIL import Image
|
5 |
|
6 |
+
nlp = spacy.load("en_core_web_sm")
|
7 |
|
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
|
14 |
+
if st.button("Highlight Geo-Entities"):
|
15 |
+
if user_input.strip():
|
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 ["GPE", "LOC"]: # GPE = Geopolitical Entity, LOC = Location
|
23 |
+
highlighted_text = (
|
24 |
+
highlighted_text[:ent.start_char] +
|
25 |
+
f"**:green[{ent.text}]**" +
|
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
|