Spaces:
Running
Running
Update app.py
Browse files22 unmodified lines2324252627284 unmodified lines33343536373839404131 unmodified lines737475767778798081828384852 unmodified lines888990919293949596979837 unmodified lines136137138139140141142143144145146147148149150151152153154286 unmodified lines44144244344444544644722 unmodified linesdict_path = "custom_dict.json"AUTO_MERGE_WORDS = [["GS๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"],["GS ๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"],["GS์ต", "์ง์์ค์ต"],["GS ์ต", "์ง์์ค์ต"],["26SS", "์ด์ญ์ก ์์ค์์ค"],["26 SS", "์ด์ญ์ก ์์ค์์ค"],["26S/S", "์ด์ญ์ก ์์ค์์ค"],["26 S/S", "์ด์ญ์ก ์์ค์์ค"],4 unmodified lines["100%", "๋ฐฑํ๋ก"],["100 %", "๋ฐฑํ๋ก"],["100ํ๋ก", "๋ฐฑํ๋ก"],["59,900์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["59,900 ์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["59900์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["59900 ์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["5๋ง 9์ฒ 9๋ฐฑ ์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["3๊ฐ์", "์ผ๊ฐ์"],["3 ๊ฐ์", "์ผ๊ฐ์"],["1๋ง์๋", "๋ง์๋"],["1๋ง ์๋", "๋ง์๋"],["1๋ง ์ ๋", "๋ง์๋"],["1๋ง์ ๋", "๋ง์๋"]]def perform_auto_recovery_and_merge():if not os.path.exists(dict_path):with open(dict_path, "w", encoding="utf-8") as f:31 unmodified linespassreturn flat_dictdef apply_g2p(text, mode):if g2p is None or mode == "๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)":return textif mode == "๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก - ์์ฐ์ค๋ฌ์ด ์ฐ์)":try: return g2p(text)except: return textif mode == "์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ - ๊ณผ๋ํ ์ฐ์ ๋ฐฉ์ง)":words = re.split(r'(\s+)', text)res =[]for w in words:2 unmodified linesexcept: res.append(w)else: res.append(w)return "".join(res)return text# ==========================================# โ ์ค๋งํธ ์ ๊ท์ ๋ก์ง (๋จ์ ๋ณํ ์ถ๊ฐ) โ# ==========================================def number_to_korean(num_str):num_str = num_str.replace(',', '')try: n = int(num_str)37 unmodified linestext = 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# ==========================================# โ ์์ ์๋ ์์ ๋ก์ง 100% ๋ณต๊ตฌ โ# ==========================================def process_text(input_text, ai_mode, auto_break, smart_pause, font_size):if not input_text or not input_text.strip():return "", f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div><div id="prompter_output_div" style="font-size:{font_size}px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."286 unmodified linesinput_text = gr.Textbox(label="1๏ธโฃ ์๋ณธ ํ ์คํธ ์ ๋ ฅ", elem_id="input_text_area")with gr.Group():gr.Markdown("**โ๏ธ ๋ณํ ๋ฐ ํ๋ฉด ์ค์ **")ai_mode = gr.Radio(choices=["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", "์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ - ๊ณผ๋ํ ์ฐ์ ๋ฐฉ์ง)", "๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก - ์์ฐ์ค๋ฌ์ด ์ฐ์)"], value="๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋ ์ ํ")auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋์์ ์๋์ผ๋ก ์ค๋ฐ๊ฟ ํ๊ธฐ", value=False)smart_pause = gr.Checkbox(label="โฑ๏ธ ์ค๋งํธ ํ๋กฌํํฐ ํธํก์ ( / ) ์ถ๊ฐํ๊ธฐ (์ผํ ๋ค)", value=False)btn_insert_marker = gr.Button("๐จ ์ปค์ ์์น์ ๋ง์ปค(@@) ์ฝ์ ํ๊ธฐ", variant="secondary", size="sm")22 unmodified lines2324252627282930314 unmodified lines3637383940414243444546474849505131 unmodified lines83848586878889909192939495969798991002 unmodified lines10310410510610710810911011111211311411511611711811912012112212312412512612712812937 unmodified lines167168169170171172173174175176177178179180286 unmodified lines46746846947047147247347447547647747847948048148248322 unmodified linesdict_path = "custom_dict.json"# ==========================================# โ 1. G2P ๋ฉด์ ๊ถ ๋จ์ด ์ถ๊ฐ (๊ธฐ์กด ๋ก์ง 100% ์ ์ง)# ==========================================AUTO_MERGE_WORDS = [["GS๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"],["GS ๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"],["GS์ต", "์ง์์ค์ต"],["GS ์ต", "์ง์์ค์ต"],["26SS", "์ด์ญ์ก ์์ค์์ค"],["26 SS", "์ด์ญ์ก ์์ค์์ค"],["26S/S", "์ด์ญ์ก ์์ค์์ค"],["26 S/S", "์ด์ญ์ก ์์ค์์ค"],4 unmodified lines["100%", "๋ฐฑํ๋ก"],["100 %", "๋ฐฑํ๋ก"],["100ํ๋ก", "๋ฐฑํ๋ก"],["59,900์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["59,900 ์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["59900์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["59900 ์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["5๋ง 9์ฒ 9๋ฐฑ ์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["3๊ฐ์", "์ผ๊ฐ์"],["3 ๊ฐ์", "์ผ๊ฐ์"],["1๋ง์๋", "๋ง์๋"],["1๋ง ์๋", "๋ง์๋"],["1๋ง ์ ๋", "๋ง์๋"],["1๋ง์ ๋", "๋ง์๋"],# G2P๊ฐ ํผ์ํ์ง ๋ชปํ๊ฒ ๋ง๋ ๊ณ ์ ๋ช ์ฌ๋ค (๋ฉด์ ๊ถ)["~์ ๋๋ค", "~์ต๋๋ค"], ["์์ ์ ๋๋ค", "์์ ์ ๋๋ค"], ["๊ฒฐ๊ณผ์ ์ผ๋ก", "๊ฒฐ๊ณผ์ ์ผ๋ก"],["์ผ์ฑ", "์ผ์ฑ"], ["LG", "์์ง"], ["SK", "์์ค์ผ์ด"],["์ํ", "์ํ"], ["์ ํ", "์ ํ"], ["๊ฐ๊ฒฉ", "๊ฐ๊ฒฉ"],["๋ฐฐ์ก", "๋ฐฐ์ก"], ["ํ ์ธ", "ํ ์ธ"], ["์ด๋ฒคํธ", "์ด๋ฒคํธ"]]# ์๋ณธ์ ์์ ํ ์ฌ์ ๋ณต๊ตฌ ํจ์ ๊ทธ๋๋ก ์ ์ง!def perform_auto_recovery_and_merge():if not os.path.exists(dict_path):with open(dict_path, "w", encoding="utf-8") as f:31 unmodified linespassreturn flat_dict# ==========================================# โ 2. 4๋จ๊ณ ํ์ด๋ธ๋ฆฌ๋ G2P ์ ์ฉ (์์ ํ๊ฒ ๋์ด์ฐ๊ธฐ ๋ณด์กด)# ==========================================def apply_g2p(text, mode):if g2p is None or mode.startswith("๋๊ธฐ"):return textif mode.startswith("๋งค์ด ๋ง"):try: return g2p(text)except: return textif mode.startswith("์ํ ๋ง"):words = re.split(r'(\s+)', text)res =[]for w in words:2 unmodified linesexcept: res.append(w)else: res.append(w)return "".join(res)if mode.startswith("์ค๊ฐ ๋ง"):# ๋์ด์ฐ๊ธฐ์ ๊ธฐํธ๋ฅผ ์์ ํ๊ฒ ๋ถ๋ฆฌํ์ฌ ๋ณด์กดtokens = re.split(r'([๊ฐ-ํฃ]+|[a-zA-Z]+|\d+|[^\w\s]+|\s+)', text)particles = {'์ด', '๊ฐ', '์', '๋ฅผ', '์', '๋', '์', '๋ก', '์ผ๋ก', '๊ณ ', '๋ค', '์ด', '์', '๋ค', '์ ๋๋ค', '์ต๋๋ค'}res = []for t in tokens:if not t: continue# ๊ณต๋ฐฑ, ์กฐ์ฌ, ํ๊ธ์ ๋จ์ด๋ ์๋ณธ ์ ์ง (G2P ์ ๊ฑฐ์นจ)if t.isspace() or t in particles or len(t) == 1:res.append(t)# 2๊ธ์ ์ด์ ํ๊ธ๋ง G2P ์๋elif re.match(r'^[๊ฐ-ํฃ]{2,}$', t):try: res.append(g2p(t))except: res.append(t)else:res.append(t)return "".join(res)return textdef number_to_korean(num_str):num_str = num_str.replace(',', '')try: n = int(num_str)37 unmodified linestext = 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)unit_dict = {"mm": "๋ฐ๋ฆฌ๋ฏธํฐ", "cm": "์ผํฐ๋ฏธํฐ", "m": "๋ฏธํฐ", "km": "ํฌ๋ก๋ฏธํฐ","g": "๊ทธ๋จ", "kg": "ํฌ๋ก๊ทธ๋จ", "ml": "๋ฐ๋ฆฌ๋ฆฌํฐ", "L": "๋ฆฌํฐ"}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 textdef process_text(input_text, ai_mode, auto_break, smart_pause, font_size):if not input_text or not input_text.strip():return "", f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div><div id="prompter_output_div" style="font-size:{font_size}px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."286 unmodified linesinput_text = gr.Textbox(label="1๏ธโฃ ์๋ณธ ํ ์คํธ ์ ๋ ฅ", elem_id="input_text_area")with gr.Group():gr.Markdown("**โ๏ธ ๋ณํ ๋ฐ ํ๋ฉด ์ค์ **")# โ 3. UI 4๋จ๊ณ๋ก ๋ณ๊ฒฝ (๊ธฐ์กด ๋ก์ง 100% ์ ์ง)ai_mode = gr.Radio(choices=["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)","์ค๊ฐ ๋ง (๋ช ์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)","์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ - ๊ณผ๋ํ ์ฐ์ ๋ฐฉ์ง)","๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก - ์์ฐ์ค๋ฌ์ด ์ฐ์)"],value="์ค๊ฐ ๋ง (๋ช ์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)",label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋ ์ ํ")auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋์์ ์๋์ผ๋ก ์ค๋ฐ๊ฟ ํ๊ธฐ", value=False)smart_pause = gr.Checkbox(label="โฑ๏ธ ์ค๋งํธ ํ๋กฌํํฐ ํธํก์ ( / ) ์ถ๊ฐํ๊ธฐ (์ผํ ๋ค)", value=False)btn_insert_marker = gr.Button("๐จ ์ปค์ ์์น์ ๋ง์ปค(@@) ์ฝ์ ํ๊ธฐ", variant="secondary", size="sm")
app.py+49-13