IS361Group4 commited on
Commit
184f4f7
·
verified ·
1 Parent(s): 47b84e2

Update personal_info_identifier.py

Browse files
Files changed (1) hide show
  1. personal_info_identifier.py +3 -3
personal_info_identifier.py CHANGED
@@ -11,14 +11,14 @@ pii_detector = pipeline(
11
  def highlight_pii(text):
12
  entities = pii_detector(text)
13
  highlighted_text = text
14
- offset = 0 # For shifting positions when inserting tags
15
 
16
  for entity in sorted(entities, key=lambda x: x['start']):
17
  start = entity['start'] + offset
18
  end = entity['end'] + offset
19
  label = entity['entity_group']
20
 
21
- # wrap entity with a span tag with color (red for demo, can be better)
22
  span = f'<span style="background-color:#ffcccc; padding:2px 4px; border-radius:4px;">{text[entity["start"]:entity["end"]]} <b style="color:red;">[{label}]</b></span>'
23
  highlighted_text = highlighted_text[:start] + span + highlighted_text[end:]
24
  offset += len(span) - (end - start)
@@ -35,7 +35,7 @@ def create_personal_info_tab():
35
 
36
  submit_button.click(fn=highlight_pii, inputs=input_text, outputs=output_html)
37
 
38
- # Optional: Add example
39
  gr.Examples(
40
  examples=[
41
  "Hugging Face is a company based in Paris and New York City that acquired Gradio in 2021."
 
11
  def highlight_pii(text):
12
  entities = pii_detector(text)
13
  highlighted_text = text
14
+ offset = 0
15
 
16
  for entity in sorted(entities, key=lambda x: x['start']):
17
  start = entity['start'] + offset
18
  end = entity['end'] + offset
19
  label = entity['entity_group']
20
 
21
+
22
  span = f'<span style="background-color:#ffcccc; padding:2px 4px; border-radius:4px;">{text[entity["start"]:entity["end"]]} <b style="color:red;">[{label}]</b></span>'
23
  highlighted_text = highlighted_text[:start] + span + highlighted_text[end:]
24
  offset += len(span) - (end - start)
 
35
 
36
  submit_button.click(fn=highlight_pii, inputs=input_text, outputs=output_html)
37
 
38
+
39
  gr.Examples(
40
  examples=[
41
  "Hugging Face is a company based in Paris and New York City that acquired Gradio in 2021."