Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,9 +48,6 @@ spaBERT_model.eval()
|
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
st.title("SpaGAN Demo")
|
| 55 |
st.write("Enter a text, and the system will highlight the geo-entities within it.")
|
| 56 |
|
|
@@ -68,16 +65,28 @@ for label, (color, description) in COLOR_MAP.items():
|
|
| 68 |
st.markdown(f"- **{label}**: <span style='color:{color}'>{color}</span> - {description}", unsafe_allow_html=True)
|
| 69 |
|
| 70 |
# Text input
|
| 71 |
-
user_input = st.text_area("Input Text", height=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
# Process the text when the button is clicked
|
| 74 |
if st.button("Highlight Geo-Entities"):
|
| 75 |
-
if
|
| 76 |
# Process the text using spaCy
|
| 77 |
-
doc = nlp(
|
| 78 |
|
| 79 |
# Highlight geo-entities with different colors
|
| 80 |
-
highlighted_text =
|
| 81 |
for ent in reversed(doc.ents):
|
| 82 |
if ent.label_ in COLOR_MAP:
|
| 83 |
color = COLOR_MAP[ent.label_][0]
|
|
@@ -90,4 +99,4 @@ if st.button("Highlight Geo-Entities"):
|
|
| 90 |
# Display the highlighted text with HTML support
|
| 91 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
| 92 |
else:
|
| 93 |
-
st.error("Please
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
| 51 |
st.title("SpaGAN Demo")
|
| 52 |
st.write("Enter a text, and the system will highlight the geo-entities within it.")
|
| 53 |
|
|
|
|
| 65 |
st.markdown(f"- **{label}**: <span style='color:{color}'>{color}</span> - {description}", unsafe_allow_html=True)
|
| 66 |
|
| 67 |
# Text input
|
| 68 |
+
#user_input = st.text_area("Input Text", height=200)
|
| 69 |
+
|
| 70 |
+
# Define example reviews for testing
|
| 71 |
+
example_reviews = {
|
| 72 |
+
"Review 1": "I visited the Empire State Building in New York last summer, and it was amazing!",
|
| 73 |
+
"Review 2": "Google, headquartered in Mountain View, is a leading tech company in the United States.",
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
# Dropdown for selecting an example review
|
| 77 |
+
user_input = st.selectbox("Select an example review", options=list(example_reviews.keys()))
|
| 78 |
+
|
| 79 |
+
# Get the selected review text
|
| 80 |
+
selected_review = example_reviews[user_input]
|
| 81 |
|
| 82 |
# Process the text when the button is clicked
|
| 83 |
if st.button("Highlight Geo-Entities"):
|
| 84 |
+
if selected_review.strip():
|
| 85 |
# Process the text using spaCy
|
| 86 |
+
doc = nlp(selected_review)
|
| 87 |
|
| 88 |
# Highlight geo-entities with different colors
|
| 89 |
+
highlighted_text = selected_review
|
| 90 |
for ent in reversed(doc.ents):
|
| 91 |
if ent.label_ in COLOR_MAP:
|
| 92 |
color = COLOR_MAP[ent.label_][0]
|
|
|
|
| 99 |
# Display the highlighted text with HTML support
|
| 100 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
| 101 |
else:
|
| 102 |
+
st.error("Please select a review.")
|