Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,23 +88,30 @@ with st.form(key='my_form'):
|
|
| 88 |
if text_input:
|
| 89 |
if selected_language == "German":
|
| 90 |
doc_de = model(text_input)
|
| 91 |
-
|
| 92 |
-
|
| 93 |
else:
|
| 94 |
-
|
| 95 |
entities = refined_model.process_text(text_input)
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
single_entity_list = str(entity).strip('][').replace("\'", "").split(', ')
|
| 101 |
-
if len(single_entity_list) >= 2 and "wikidata" in single_entity_list[1]:
|
| 102 |
entities_map[single_entity_list[0].strip()] = get_wikidata_id(single_entity_list[1])
|
| 103 |
entity_data = get_entity_data(entities_map[single_entity_list[0].strip()]["link"])
|
| 104 |
if entity_data is not None:
|
| 105 |
entities_data[single_entity_list[0].strip()] = entity_data
|
| 106 |
-
|
| 107 |
-
|
| 108 |
|
| 109 |
if submit_button:
|
| 110 |
# Prepare a list to hold the final output
|
|
|
|
| 88 |
if text_input:
|
| 89 |
if selected_language == "German":
|
| 90 |
doc_de = model(text_input)
|
| 91 |
+
# Map entities to a format similar to English output
|
| 92 |
+
entities = [(ent.text, ent.label_, ent._.kb_qid, ent._.url_wikidata) for ent in doc_de.ents]
|
| 93 |
else:
|
|
|
|
| 94 |
entities = refined_model.process_text(text_input)
|
| 95 |
+
|
| 96 |
+
# Logic for English language processing
|
| 97 |
+
entities_map = {}
|
| 98 |
+
entities_data = {}
|
| 99 |
+
for entity in entities:
|
| 100 |
+
if selected_language == "German":
|
| 101 |
+
entity_string, entity_type, wikidata_id, wikidata_url = entity
|
| 102 |
+
entities_map[entity_string] = {"id": wikidata_id, "link": wikidata_url}
|
| 103 |
+
entity_data = get_entity_data(wikidata_url)
|
| 104 |
+
if entity_data is not None:
|
| 105 |
+
entities_data[entity_string] = entity_data
|
| 106 |
+
else:
|
| 107 |
single_entity_list = str(entity).strip('][').replace("\'", "").split(', ')
|
| 108 |
+
if len(single_entity_list) >= 2 and "wikidata" in single_entity_list[1]:
|
| 109 |
entities_map[single_entity_list[0].strip()] = get_wikidata_id(single_entity_list[1])
|
| 110 |
entity_data = get_entity_data(entities_map[single_entity_list[0].strip()]["link"])
|
| 111 |
if entity_data is not None:
|
| 112 |
entities_data[single_entity_list[0].strip()] = entity_data
|
| 113 |
+
|
| 114 |
+
combined_entity_info_dictionary = dict([(k, [entities_map[k], entities_data[k] if k in entities_data else None]) for k in entities_map])
|
| 115 |
|
| 116 |
if submit_button:
|
| 117 |
# Prepare a list to hold the final output
|