dejanseo commited on
Commit
266743a
1 Parent(s): d598c67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -87,20 +87,22 @@ def process_text(inputs: str, confidence_threshold: float):
87
  for word_start in sorted(word_info.keys()):
88
  word_data = word_info[word_start]
89
  for subtoken_start, subtoken_end, subtoken_text in word_data['subtokens']:
 
90
  if last_end < subtoken_start:
91
  reconstructed_text += chunk[last_end:subtoken_start]
92
  if word_data['prediction'] == 1:
93
- reconstructed_text += f"<span style='background-color: rgba(0, 255, 0); display: inline;'>{subtoken_text.replace('$', '\\$')}</span>"
94
  else:
95
- reconstructed_text += subtoken_text.replace('$', '\\$')
96
  last_end = subtoken_end
97
 
98
- df_data['Word'].append(subtoken_text.replace('$', '\\$'))
99
  df_data['Prediction'].append(word_data['prediction'])
100
  df_data['Confidence'].append(word_info[word_start]['confidence'])
101
  df_data['Start'].append(subtoken_start + original_position_offset)
102
  df_data['End'].append(subtoken_end + original_position_offset)
103
 
 
104
  original_position_offset += len(chunk) + 1
105
 
106
  reconstructed_text += chunk[last_end:].replace('$', '\\$')
 
87
  for word_start in sorted(word_info.keys()):
88
  word_data = word_info[word_start]
89
  for subtoken_start, subtoken_end, subtoken_text in word_data['subtokens']:
90
+ escaped_subtoken_text = subtoken_text.replace('$', '\\$') # Perform replacement outside f-string
91
  if last_end < subtoken_start:
92
  reconstructed_text += chunk[last_end:subtoken_start]
93
  if word_data['prediction'] == 1:
94
+ reconstructed_text += f"<span style='background-color: rgba(0, 255, 0); display: inline;'>{escaped_subtoken_text}</span>"
95
  else:
96
+ reconstructed_text += escaped_subtoken_text
97
  last_end = subtoken_end
98
 
99
+ df_data['Word'].append(escaped_subtoken_text)
100
  df_data['Prediction'].append(word_data['prediction'])
101
  df_data['Confidence'].append(word_info[word_start]['confidence'])
102
  df_data['Start'].append(subtoken_start + original_position_offset)
103
  df_data['End'].append(subtoken_end + original_position_offset)
104
 
105
+
106
  original_position_offset += len(chunk) + 1
107
 
108
  reconstructed_text += chunk[last_end:].replace('$', '\\$')