Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -47,29 +47,27 @@ if text_input:
|
|
47 |
def get_entity_description(entity_link, combined_entity_info_dictionary):
|
48 |
return combined_entity_info_dictionary[entity_link][1]
|
49 |
|
50 |
-
annotations = []
|
51 |
-
for wikidata_link, entity in entities_map.items():
|
52 |
-
description = get_entity_description(wikidata_link, combined_entity_info_dictionary)
|
53 |
-
annotations.append((entity, description, "#8ef"))
|
54 |
-
|
55 |
-
# Annotate text with entities
|
56 |
if submit_button:
|
57 |
-
# Split the input text into words
|
58 |
-
words = nltk.word_tokenize(text_input)
|
59 |
-
|
60 |
# Prepare a list to hold the final output
|
61 |
final_text = []
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
else:
|
69 |
-
final_text.append(
|
70 |
|
71 |
# Pass the final_text to the annotated_text function
|
72 |
-
annotated_text(final_text)
|
73 |
-
|
74 |
-
with st.expander("See annotations"):
|
75 |
-
st.write(final_text)
|
|
|
47 |
def get_entity_description(entity_link, combined_entity_info_dictionary):
|
48 |
return combined_entity_info_dictionary[entity_link][1]
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
if submit_button:
|
|
|
|
|
|
|
51 |
# Prepare a list to hold the final output
|
52 |
final_text = []
|
53 |
|
54 |
+
# Replace each entity in the text with its annotated version
|
55 |
+
for wikidata_link, entity in entities_map.items():
|
56 |
+
description = get_entity_description(wikidata_link, combined_entity_info_dictionary)
|
57 |
+
entity_annotation = (entity, description, "#8ef")
|
58 |
+
text_input = text_input.replace(entity, f'{{{str(entity_annotation)}}}', 1)
|
59 |
+
|
60 |
+
# Split the modified text_input into a list
|
61 |
+
text_list = text_input.split("{")
|
62 |
+
|
63 |
+
for item in text_list:
|
64 |
+
if "}" in item:
|
65 |
+
item_list = item.split("}")
|
66 |
+
final_text.append(eval(item_list[0]))
|
67 |
+
if len(item_list[1]) > 0:
|
68 |
+
final_text.append(item_list[1])
|
69 |
else:
|
70 |
+
final_text.append(item)
|
71 |
|
72 |
# Pass the final_text to the annotated_text function
|
73 |
+
annotated_text(*final_text)
|
|
|
|
|
|