blueradiance commited on
Commit
d1de249
·
verified ·
1 Parent(s): b27703e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -96,6 +96,17 @@ def mask_department(text):
96
  text = re.sub(r"([가-힣]{2,20}학과)", lambda m: to_chosung(m.group(1)[:-2]) + "학과", text)
97
  return text
98
 
 
 
 
 
 
 
 
 
 
 
 
99
  def sanitize_sensitive_info(text, keyword_string, replace_word):
100
  text = mask_school_names(text)
101
  text = mask_department(text)
@@ -109,16 +120,7 @@ def sanitize_sensitive_info(text, keyword_string, replace_word):
109
  pattern = rf"\b{re.escape(kw)}\b"
110
  text = re.sub(pattern, replace_word, text, flags=re.IGNORECASE)
111
 
112
- text = re.sub(r"(\d{3})-(\d{4})-(\d{4})", r"\1-****-\3", text)
113
- text = re.sub(r"(\d{4})년 (\d{1,2})월 (\d{1,2})일", r"19**년 \2월 *일", text)
114
- text = re.sub(r"(\d{1,3})번지", r"***번지", text)
115
- text = re.sub(r"(\d{1,3})동", r"***동", text)
116
- text = re.sub(r"(\d{1,4})호", r"****호", text)
117
- text = re.sub(r"[\w\.-]+@[\w\.-]+", r"******@****", text)
118
- text = re.sub(r"(\d{6})[-](\d)\d{6}", r"*******-\2*****", text)
119
- text = re.sub(r"([가-힣]+(대로|로|길))\s?(\d+)(호|번길|가)?", r"\1 ***", text)
120
- text = re.sub(r"(\d{4})[- ]?(\d{4})[- ]?(\d{4})[- ]?(\d{4})",
121
- lambda m: f"{m.group(1)}-****-****-{m.group(4)}", text)
122
  return text
123
 
124
  def final_name_remask_exact_only(text, mapping_dict):
@@ -167,16 +169,15 @@ def apply_masking(text, keywords, replace_word):
167
 
168
  with gr.Blocks() as demo:
169
  gr.Markdown("""
170
- 🛡️ **민감정보 마스킹 [땡땡이 마스킹]**
171
- 이름 + 민감정보 + 초/중/고 마스킹기 (초성 기반)
172
- ⚠️ *완벽하지 않을 수 있습니다. 반드시 직접 최종 점검하세요.*
173
  """)
174
- input_text = gr.Textbox(lines=15, label="📥 원본 텍스트 입력")
175
- keyword_input = gr.Textbox(lines=1, label="기관 키워드 (쉼표로 구분)", value="굿네이버스, good neighbors, gn, 사회복지법인 굿네이버스")
176
- replace_input = gr.Textbox(lines=1, label="치환할 텍스트", value="우리기관")
177
- run_button = gr.Button("🚀 마스킹 실행")
178
- masked_output = gr.Textbox(lines=15, label="🔐 마스킹된 텍스트")
179
- mapping_output = gr.Textbox(lines=10, label="🏷️ 이름 태그 매핑", interactive=False)
180
 
181
  run_button.click(fn=apply_masking, inputs=[input_text, keyword_input, replace_input], outputs=[masked_output, mapping_output])
182
 
 
96
  text = re.sub(r"([가-힣]{2,20}학과)", lambda m: to_chosung(m.group(1)[:-2]) + "학과", text)
97
  return text
98
 
99
+ def mask_sensitive_numbers(text):
100
+ text = re.sub(r"(\d{3})-(\d{4})-(\d{4})", r"\1-****-\3", text)
101
+ text = re.sub(r"(\d{6})[-](\d)\d{6}", r"*******-\2*****", text)
102
+ text = re.sub(r"(\d{4})[- ]?(\d{4})[- ]?(\d{4})[- ]?(\d{4})", lambda m: f"{m.group(1)}-****-****-{m.group(4)}", text)
103
+ text = re.sub(r"(\d{1,3})번지", r"***번지", text)
104
+ text = re.sub(r"(\d{1,3})동", r"***동", text)
105
+ text = re.sub(r"(\d{1,4})호", r"****호", text)
106
+ text = re.sub(r"[\w\.-]+@[\w\.-]+", r"******@****", text)
107
+ text = re.sub(r"(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})", lambda m: f"{m.group(1)}.{m.group(2)}.*.*", text)
108
+ return text
109
+
110
  def sanitize_sensitive_info(text, keyword_string, replace_word):
111
  text = mask_school_names(text)
112
  text = mask_department(text)
 
120
  pattern = rf"\b{re.escape(kw)}\b"
121
  text = re.sub(pattern, replace_word, text, flags=re.IGNORECASE)
122
 
123
+ text = mask_sensitive_numbers(text)
 
 
 
 
 
 
 
 
 
124
  return text
125
 
126
  def final_name_remask_exact_only(text, mapping_dict):
 
169
 
170
  with gr.Blocks() as demo:
171
  gr.Markdown("""
172
+ 🛡️ **반드웨어 문서 목적 매칭기**
173
+ 이름 + 민간정보 + 후역 목적을 캐치하여 목적에 따라 확장 및 매칭을 수행합니다.
 
174
  """)
175
+ input_text = gr.Textbox(lines=15, label="📅 원본 텍스트")
176
+ keyword_input = gr.Textbox(lines=1, label="기관 키워드", value="기업명, 구청명")
177
+ replace_input = gr.Textbox(lines=1, label="치환 문자", value="우리기관")
178
+ run_button = gr.Button("🚀 매칭 실행")
179
+ masked_output = gr.Textbox(lines=15, label="🔐 매칭된 텍스트")
180
+ mapping_output = gr.Textbox(lines=10, label="🏷️ 이름 태그 매칭", interactive=False)
181
 
182
  run_button.click(fn=apply_masking, inputs=[input_text, keyword_input, replace_input], outputs=[masked_output, mapping_output])
183