Spaces:
Running
Running
Update app.py
Browse files90 unmodified lines919293949495969724 unmodified lines1221231241251251261271284 unmodified lines1331341351361361371381391401411421431441451461471481498 unmodified lines15815916015416116216329 unmodified lines19319419519019619719890 unmodified lines return text
# ==========================================# โ
1. ์ค๋งํธ ์ ๊ท์ ๋ก์ง๋ง ์กฐ์ฌ์ค๋ฝ๊ฒ ์ถ๊ฐ โ
# โ
์ค๋งํธ ์ ๊ท์ ๋ก์ง (๋จ์ ๋ณํ ์ถ๊ฐ) โ
# ==========================================def number_to_korean(num_str): num_str = num_str.replace(',', '')24 unmodified lines
def 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 lines size_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) # โ
์๋ฌธ ๋จ์ ์๋ ๋ณํ ์ถ๊ฐ (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 lines len_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 lines seq = 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)app.py+10-5