emanuelaboros commited on
Commit
d6100e0
·
1 Parent(s): bf5bc24
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -51,21 +51,20 @@ def prepare_entities_for_highlight(text, results):
51
  print("Results:", results)
52
  # it should look like:
53
  # [{'entity': 'org.ent.pressagency.Reuters', 'score': np.float32(98.47), 'index': 78, 'word': 'Reuters', 'start': 440, 'end': 447}]
54
- for category, entity_list in results.items():
55
- for entity in entity_list:
56
- entity_span = (entity["start"], entity["end"])
57
-
58
- # Only add non-overlapping entities
59
- if entity_span not in seen_spans:
60
- seen_spans.add(entity_span)
61
- entity_text = text[
62
- entity["start"] : entity["end"]
63
- ].strip() # Ensure we're working with the correct portion of the text
64
- entity["text"] = entity_text
65
- entity.pop("word")
66
- print(f"Entity text: {entity}")
67
-
68
- entities.append(entity)
69
 
70
  # Sort entities by their start position
71
  entities = sorted(entities, key=lambda x: x["start"])
 
51
  print("Results:", results)
52
  # it should look like:
53
  # [{'entity': 'org.ent.pressagency.Reuters', 'score': np.float32(98.47), 'index': 78, 'word': 'Reuters', 'start': 440, 'end': 447}]
54
+ for entity in results.items():
55
+ entity_span = (entity["start"], entity["end"])
56
+
57
+ # Only add non-overlapping entities
58
+ if entity_span not in seen_spans:
59
+ seen_spans.add(entity_span)
60
+ entity_text = text[
61
+ entity["start"] : entity["end"]
62
+ ].strip() # Ensure we're working with the correct portion of the text
63
+ entity["text"] = entity_text
64
+ entity.pop("word")
65
+ print(f"Entity text: {entity}")
66
+
67
+ entities.append(entity)
 
68
 
69
  # Sort entities by their start position
70
  entities = sorted(entities, key=lambda x: x["start"])