cyberandy commited on
Commit
5afeb06
·
verified ·
1 Parent(s): 014cdc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -154,12 +154,13 @@ entities_data = {}
154
 
155
  if text_input and model is not None:
156
  try:
 
157
  if selected_language in ["German", "English - spaCy"]:
158
- # Process the text with error handling for spaCy
159
  doc = model(text_input)
160
  entities = []
161
  for ent in doc.ents:
162
  try:
 
163
  kb_qid = getattr(ent._, 'kb_qid', None)
164
  url_wikidata = getattr(ent._, 'url_wikidata', None)
165
  entities.append((ent.text, ent.label_, kb_qid, url_wikidata))
@@ -175,14 +176,15 @@ if text_input and model is not None:
175
 
176
  else:
177
  # === CORRECTED ReFinED PROCESSING LOGIC ===
178
- entities = model.process_text(text_input)
179
-
180
- # Iterate through the entity objects directly and safely
181
- for entity in entities:
182
- # Check if the entity has a wikidata_id before processing
183
- if entity.wikidata_id:
184
- entity_text = entity.text
185
- entity_id = entity.wikidata_id
 
186
  entity_link = f"http://www.wikidata.org/entity/{entity_id}"
187
 
188
  # Populate your dictionaries
@@ -191,7 +193,6 @@ if text_input and model is not None:
191
  if entity_data is not None:
192
  entities_data[entity_text] = entity_data
193
 
194
-
195
  except Exception as e:
196
  st.error(f"Error processing text: {e}")
197
  if "entityfishing" in str(e).lower():
 
154
 
155
  if text_input and model is not None:
156
  try:
157
+ # This block for German/English spaCy is correct
158
  if selected_language in ["German", "English - spaCy"]:
 
159
  doc = model(text_input)
160
  entities = []
161
  for ent in doc.ents:
162
  try:
163
+ # Safely get the custom attributes from entity-fishing
164
  kb_qid = getattr(ent._, 'kb_qid', None)
165
  url_wikidata = getattr(ent._, 'url_wikidata', None)
166
  entities.append((ent.text, ent.label_, kb_qid, url_wikidata))
 
176
 
177
  else:
178
  # === CORRECTED ReFinED PROCESSING LOGIC ===
179
+ # The model processes the text and returns doc.ents, which is a tuple of Spans
180
+ spans = model.process_text(text_input)
181
+
182
+ # Iterate through the Span objects and use the correct custom attribute
183
+ for ent in spans:
184
+ # Safely check if the custom attribute exists and has a value
185
+ if hasattr(ent._, 'wikidata_id') and ent._.wikidata_id:
186
+ entity_text = ent.text
187
+ entity_id = ent._.wikidata_id # <-- THE FIX: Access via ._.
188
  entity_link = f"http://www.wikidata.org/entity/{entity_id}"
189
 
190
  # Populate your dictionaries
 
193
  if entity_data is not None:
194
  entities_data[entity_text] = entity_data
195
 
 
196
  except Exception as e:
197
  st.error(f"Error processing text: {e}")
198
  if "entityfishing" in str(e).lower():