umarigan commited on
Commit
2c380a0
1 Parent(s): 5f73d00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -92,7 +92,18 @@ def entity_comb(output):
92
  else:
93
  output_comb.append(entity)
94
  return output_comb
95
-
 
 
 
 
 
 
 
 
 
 
 
96
  def create_masked_text(input_text, entities):
97
  # Create the mask dictionary
98
  mask_dict = create_mask_dict(entities)
@@ -107,13 +118,6 @@ def create_masked_text(input_text, entities):
107
  masked_text[entity['end']:]
108
  )
109
  return masked_text
110
- def create_masked_text(input_text, entities, mask_dict):
111
- masked_text = input_text
112
- for entity in sorted(entities, key=lambda x: x['start'], reverse=True):
113
- if entity['entity_group'] not in ['CARDINAL', 'EVENT']:
114
- masked_text = masked_text[:entity['start']] + mask_dict[entity['word']] + masked_text[entity['end']:]
115
- return masked_text
116
-
117
 
118
  Run_Button = st.button("Run")
119
 
 
92
  else:
93
  output_comb.append(entity)
94
  return output_comb
95
+ def create_mask_dict(entities):
96
+ mask_dict = {}
97
+ entity_counters = {}
98
+ for entity in entities:
99
+ if entity['entity_group'] not in ['CARDINAL', 'EVENT']:
100
+ if entity['word'] not in mask_dict:
101
+ if entity['entity_group'] not in entity_counters:
102
+ entity_counters[entity['entity_group']] = 1
103
+ else:
104
+ entity_counters[entity['entity_group']] += 1
105
+ mask_dict[entity['word']] = f"{entity['entity_group']}_{entity_counters[entity['entity_group']]}"
106
+ return mask_dict
107
  def create_masked_text(input_text, entities):
108
  # Create the mask dictionary
109
  mask_dict = create_mask_dict(entities)
 
118
  masked_text[entity['end']:]
119
  )
120
  return masked_text
 
 
 
 
 
 
 
121
 
122
  Run_Button = st.button("Run")
123