Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,13 +66,13 @@ model = load_model(selected_language, selected_model_name, selected_entity_set)
|
|
| 66 |
def get_wikidata_id(entity_string):
|
| 67 |
entity_list = entity_string.split("=")
|
| 68 |
entity_id = str(entity_list[1])
|
| 69 |
-
entity_link = "http
|
| 70 |
return {"id": entity_id, "link": entity_link}
|
| 71 |
|
| 72 |
def get_entity_data(entity_link):
|
| 73 |
try:
|
| 74 |
-
#
|
| 75 |
-
formatted_link = entity_link.replace("
|
| 76 |
response = requests.get(f'https://api.wordlift.io/id/{formatted_link}')
|
| 77 |
return response.json()
|
| 78 |
except Exception as e:
|
|
@@ -87,6 +87,17 @@ with st.form(key='my_form'):
|
|
| 87 |
# When processing the text, check the language and adjust processing accordingly
|
| 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]
|
|
|
|
| 66 |
def get_wikidata_id(entity_string):
|
| 67 |
entity_list = entity_string.split("=")
|
| 68 |
entity_id = str(entity_list[1])
|
| 69 |
+
entity_link = "http://www.wikidata.org/entity/" + entity_id
|
| 70 |
return {"id": entity_id, "link": entity_link}
|
| 71 |
|
| 72 |
def get_entity_data(entity_link):
|
| 73 |
try:
|
| 74 |
+
# Format the entity_link
|
| 75 |
+
formatted_link = entity_link.replace("http://", "http/")
|
| 76 |
response = requests.get(f'https://api.wordlift.io/id/{formatted_link}')
|
| 77 |
return response.json()
|
| 78 |
except Exception as e:
|
|
|
|
| 87 |
# When processing the text, check the language and adjust processing accordingly
|
| 88 |
if text_input:
|
| 89 |
if selected_language == "German":
|
| 90 |
+
doc_de = model(text_input)
|
| 91 |
+
entities = [(ent.text, ent.label_, ent._.kb_qid, ent._.url_wikidata) for ent in doc_de.ents]
|
| 92 |
+
for entity in entities:
|
| 93 |
+
entity_string, entity_type, wikidata_id, wikidata_url = entity
|
| 94 |
+
# Ensure correct format for the German model
|
| 95 |
+
formatted_wikidata_url = wikidata_url.replace("https://", "http://")
|
| 96 |
+
entities_map[entity_string] = {"id": wikidata_id, "link": formatted_wikidata_url}
|
| 97 |
+
entity_data = get_entity_data(formatted_wikidata_url)
|
| 98 |
+
if entity_data is not None:
|
| 99 |
+
entities_data[entity_string] = entity_data
|
| 100 |
+
|
| 101 |
doc_de = model(text_input)
|
| 102 |
# Map entities to a format similar to English output
|
| 103 |
entities = [(ent.text, ent.label_, ent._.kb_qid, ent._.url_wikidata) for ent in doc_de.ents]
|