blueradiance commited on
Commit
8122ec3
·
verified ·
1 Parent(s): 52c1652

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -39
app.py CHANGED
@@ -190,61 +190,47 @@ def sanitize_sensitive_info(text, keyword_string, replace_word):
190
  text = re.sub(r"([가-힣]+(대로|로|길))\s?(\d+)(호|번길|가)?", r"\1 ***", text)
191
  return text
192
 
193
- def apply_masking(text, keywords, replace_word):
 
 
 
 
 
 
 
 
 
 
194
  names = extract_names(text)
195
- masked, mapping = refactored_mask_names(text, names)
196
- sanitized = sanitize_sensitive_info(masked, keywords, replace_word)
197
- sanitized = final_name_remask_exact_only(sanitized, mapping)
198
- mapping_table = "\n".join([f"{k} → {v}" for k, v in mapping.items()])
199
- return sanitized, mapping_table
200
 
 
 
201
 
 
202
 
203
- def apply_masking(text, keyword_str, replacement_str):
204
- # 키워드 전처리
205
- keywords = [kw.strip() for kw in keyword_str.split(",") if kw.strip()]
206
-
207
- # 기관명 치환 먼저 실행
208
- for kw in keywords:
209
- text = text.replace(kw, replacement_str)
210
 
211
- # 이후 기존 NER 처리 + 민감정보 후처리
212
- ner_results = ner_pipeline(text)
213
- # ... (이름 치환 등 기존 마스킹 로직 계속)
214
 
215
- return masked_text, name_entity_map
216
-
217
-
218
- # UI
219
  with gr.Blocks() as demo:
220
  gr.Markdown("""
221
  🛡️ **민감정보 마스킹 [ver2]**
222
  이름 + 민감정보 + 초/중/고 마스킹기 (초성 기반 + 예외 필터 + 후처리 강화)
223
  """)
 
224
  input_text = gr.Textbox(lines=15, label="📅 원본 텍스트 입력")
225
  keyword_input = gr.Textbox(lines=1, label="기관 키워드 (쉼표 구분)", value="굿네이버스, 사회복지법인 굿네이버스")
226
  replace_input = gr.Textbox(lines=1, label="치환할 텍스트", value="우리기관")
 
227
  run_button = gr.Button("🚀 마스킹 실행")
228
  masked_output = gr.Textbox(lines=15, label="🔐 마스킹 결과")
229
  mapping_output = gr.Textbox(lines=10, label="🏷️ 이름 태그 매핑", interactive=False)
230
 
231
- run_button.click(fn=apply_masking, inputs=[input_text, keyword_input, replace_input], outputs=[masked_output, mapping_output])
232
-
233
- def apply_masking(text, keyword_str, replacement_str):
234
- # 👉 키워드 치환
235
- keywords = [kw.strip() for kw in keyword_str.split(",") if kw.strip()]
236
- for kw in keywords:
237
- text = text.replace(kw, replacement_str)
238
-
239
- # 👉 간단한 민감정보 마스킹 (이메일 앞부분)
240
- text = re.sub(r"\b[\w\.-]+@", "******@", text)
241
-
242
- # 👉 이름 태깅 예시 출력 (NER 연결 전 임시 값)
243
- name_entity_map = "※ 이름 태깅 예시: 홍길동 → N001"
244
-
245
- return text, name_entity_map
246
-
247
-
248
-
249
 
250
- demo.launch()
 
190
  text = re.sub(r"([가-힣]+(대로|로|길))\s?(\d+)(호|번길|가)?", r"\1 ***", text)
191
  return text
192
 
193
+ # 🔹 마스킹 함수 (정리된 최종본)
194
+ def apply_masking(text, keyword_str, replace_word):
195
+ """
196
+ - 키워드 문자열 처리
197
+ - 이름 태깅
198
+ - 민감정보 및 키워드 마스킹
199
+ - 이름 보정
200
+ - 매핑 테이블 반환
201
+ """
202
+ keywords = [kw.strip() for kw in keyword_str.split(",") if kw.strip()]
203
+
204
  names = extract_names(text)
205
+ masked_text, name_mapping = refactored_mask_names(text, names)
 
 
 
 
206
 
207
+ sanitized_text = sanitize_sensitive_info(masked_text, keywords, replace_word)
208
+ final_text = final_name_remask_exact_only(sanitized_text, name_mapping)
209
 
210
+ mapping_table = "\n".join(f"{k} → {v}" for k, v in name_mapping.items())
211
 
212
+ return final_text, mapping_table
 
 
 
 
 
 
213
 
 
 
 
214
 
215
+ # 🔹 Gradio UI
 
 
 
216
  with gr.Blocks() as demo:
217
  gr.Markdown("""
218
  🛡️ **민감정보 마스킹 [ver2]**
219
  이름 + 민감정보 + 초/중/고 마스킹기 (초성 기반 + 예외 필터 + 후처리 강화)
220
  """)
221
+
222
  input_text = gr.Textbox(lines=15, label="📅 원본 텍스트 입력")
223
  keyword_input = gr.Textbox(lines=1, label="기관 키워드 (쉼표 구분)", value="굿네이버스, 사회복지법인 굿네이버스")
224
  replace_input = gr.Textbox(lines=1, label="치환할 텍스트", value="우리기관")
225
+
226
  run_button = gr.Button("🚀 마스킹 실행")
227
  masked_output = gr.Textbox(lines=15, label="🔐 마스킹 결과")
228
  mapping_output = gr.Textbox(lines=10, label="🏷️ 이름 태그 매핑", interactive=False)
229
 
230
+ run_button.click(
231
+ fn=apply_masking,
232
+ inputs=[input_text, keyword_input, replace_input],
233
+ outputs=[masked_output, mapping_output]
234
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
+ demo.launch()