Spaces:
Running
Running
Update app.py
Browse files90 unmodified lines9192939495969724 unmodified lines1221231241251261271284 unmodified lines1331341351361371381391401411428 unmodified lines15115215315415515615729 unmodified lines18718818919019119219390 unmodified linesreturn text# ==========================================# β 1. μ€λ§νΈ μ κ·μ λ‘μ§λ§ μ‘°μ¬μ€λ½κ² μΆκ° β# ==========================================def number_to_korean(num_str):num_str = num_str.replace(',', '')24 unmodified linesdef apply_smart_regex(text):if not text: return text# μ μ°ν λμ΄μ°κΈ° ν¨ν΄text = re.sub(r'\b1\s*λ§\s*μ\s*λ\b', "λ§μλ", text)text = re.sub(r'\b1\s*λ§μ\s*λ\b', "λ§μλ", text)text = re.sub(r'\b1\s*λ§μλ\b', "λ§μλ", text)4 unmodified linessize_dict = {"55":"μ€μ€", "66":"μ΅μ‘", "77":"μΉ μΉ ", "88":"νν"}text = re.sub(r'\b(55|66|77|88)\s*μ¬μ΄μ¦\b', lambda m: f"{size_dict[m.group(1)]} μΈμ΄μ¦", text)# 12,900μ λ± λ²μ© κ°κ²©text = re.sub(r'(\d{1,3}(?:,\d{3})+|\d+)\s*λ§\s*μ\s*λ\b', lambda m: f"{number_to_korean(m.group(1))}λ§μλ", text)text = re.sub(r'(\d{1,3}(?:,\d{3})+|\d+)\s*μ\b', lambda m: f"{number_to_korean(m.group(1))} μ", text)return text# ==========================================8 unmodified lineslen_without_spaces = len(clean_text.replace(' ', '').replace('\n', ''))char_count = f"곡백 ν¬ν¨: {len_with_spaces}μ / 곡백 μ μΈ: {len_without_spaces}μ"# μ¬κΈ°μ λ¨Όμ μ κ·μμ ν λ² λλ €μ€λλ€ (μ΄ ν μ€λ§ μλ³Έμ μΆκ°)text_for_processing = apply_smart_regex(input_text)flat_dict = load_dict()29 unmodified linesseq = difflib.SequenceMatcher(None, input_text, final_text)html_parts = []for tag, i1, i2, j1, j2 in seq.get_opcodes():# HTML λ λλ§ μλ¬ λ°©μ§ (보μ μΆκ°)chunk = html.escape(final_text[j1:j2]).replace('\n', '<br>')if tag == 'equal':html_parts.append(chunk)90 unmodified lines9192939495969724 unmodified lines1221231241251261271284 unmodified lines1331341351361371381391401411421431441451461471481498 unmodified lines15815916016116216329 unmodified lines19319419519619719890 unmodified linesreturn text# ==========================================# β μ€λ§νΈ μ κ·μ λ‘μ§ (λ¨μ λ³ν μΆκ°) β# ==========================================def number_to_korean(num_str):num_str = num_str.replace(',', '')24 unmodified linesdef apply_smart_regex(text):if not text: return texttext = re.sub(r'\b1\s*λ§\s*μ\s*λ\b', "λ§μλ", text)text = re.sub(r'\b1\s*λ§μ\s*λ\b', "λ§μλ", text)text = re.sub(r'\b1\s*λ§μλ\b', "λ§μλ", text)4 unmodified linessize_dict = {"55":"μ€μ€", "66":"μ΅μ‘", "77":"μΉ μΉ ", "88":"νν"}text = re.sub(r'\b(55|66|77|88)\s*μ¬μ΄μ¦\b', lambda m: f"{size_dict[m.group(1)]} μΈμ΄μ¦", text)text = re.sub(r'(\d{1,3}(?:,\d{3})+|\d+)\s*λ§\s*μ\s*λ\b', lambda m: f"{number_to_korean(m.group(1))}λ§μλ", text)text = re.sub(r'(\d{1,3}(?:,\d{3})+|\d+)\s*μ\b', lambda m: f"{number_to_korean(m.group(1))} μ", text)# β μλ¬Έ λ¨μ μλ λ³ν μΆκ° (mm, cm, kg λ±)unit_dict = {"mm": "λ°λ¦¬λ―Έν°", "cm": "μΌν°λ―Έν°", "m": "λ―Έν°", "km": "ν¬λ‘λ―Έν°","g": "κ·Έλ¨", "kg": "ν¬λ‘κ·Έλ¨", "ml": "λ°λ¦¬λ¦¬ν°", "L": "리ν°"}# λμλ¬Έμ κ΅¬λΆ μμ΄ μ‘κΈ° μν΄ re.IGNORECASE νλκ·Έ μ μ©text = re.sub(r'(\d+)\s*(mm|cm|m|km|g|kg|ml|L)\b', lambda m: f"{number_to_korean(m.group(1))} {unit_dict[m.group(2).lower() if m.group(2).lower() != 'l' else 'L']}", text, flags=re.IGNORECASE)return text# ==========================================8 unmodified lineslen_without_spaces = len(clean_text.replace(' ', '').replace('\n', ''))char_count = f"곡백 ν¬ν¨: {len_with_spaces}μ / 곡백 μ μΈ: {len_without_spaces}μ"text_for_processing = apply_smart_regex(input_text)flat_dict = load_dict()29 unmodified linesseq = difflib.SequenceMatcher(None, input_text, final_text)html_parts = []for tag, i1, i2, j1, j2 in seq.get_opcodes():chunk = html.escape(final_text[j1:j2]).replace('\n', '<br>')if tag == 'equal':html_parts.append(chunk)
app.py+10-5