Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,12 +99,12 @@ def create_mask_dict(entities, additional_masks=None):
|
|
| 99 |
|
| 100 |
for entity in entities:
|
| 101 |
if entity['entity_group'] not in ['CARDINAL', 'EVENT', 'PERCENT', 'QUANTITY']:
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
|
| 109 |
if additional_masks:
|
| 110 |
for word, replacement in additional_masks.items():
|
|
@@ -112,6 +112,7 @@ def create_mask_dict(entities, additional_masks=None):
|
|
| 112 |
|
| 113 |
return mask_dict
|
| 114 |
|
|
|
|
| 115 |
def replace_words_in_text(input_text, entities):
|
| 116 |
replace_dict = create_mask_dict(entities)
|
| 117 |
for word, replacement in replace_dict.items():
|
|
|
|
| 99 |
|
| 100 |
for entity in entities:
|
| 101 |
if entity['entity_group'] not in ['CARDINAL', 'EVENT', 'PERCENT', 'QUANTITY']:
|
| 102 |
+
if entity['word'] not in mask_dict: # Corrected indentation
|
| 103 |
+
if entity['entity_group'] not in entity_counters:
|
| 104 |
+
entity_counters[entity['entity_group']] = 1
|
| 105 |
+
else:
|
| 106 |
+
entity_counters[entity['entity_group']] += 1
|
| 107 |
+
mask_dict[entity['word']] = f"{entity['entity_group']}_{entity_counters[entity['entity_group']]}"
|
| 108 |
|
| 109 |
if additional_masks:
|
| 110 |
for word, replacement in additional_masks.items():
|
|
|
|
| 112 |
|
| 113 |
return mask_dict
|
| 114 |
|
| 115 |
+
|
| 116 |
def replace_words_in_text(input_text, entities):
|
| 117 |
replace_dict = create_mask_dict(entities)
|
| 118 |
for word, replacement in replace_dict.items():
|