Spaces:
Running
Running
Update app.py
Browse files9 unmodified lines1011121314151611 unmodified lines28293031323334130 unmodified lines16516616716816917017159 unmodified lines2312322332342352362372382392402412422432442 unmodified lines24724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228399 unmodified lines3833843853863873883893 unmodified lines39339439539639739839924 unmodified lines4244254264274284294309 unmodified lines440441442443444445446164 unmodified lines61161261361461561661761861962062162226 unmodified lines6496506516526536546552 unmodified lines6586596606616626636646656669 unmodified lines# - P0: ์ฌ์ ์๊ตฌ ์ ์ฅ (HF Dataset ์๋ ์ปค๋ฐ) + AUTO_MERGE ๋นํ๊ดดํ# - P1: ๋งค์นญ ์์ง ๊ต์ฒด (2๋จ๊ณ: ํ๊ธฐ ์ ๊ทํ -> ๋ฐ์ ์นํ, ๊ณต๋ฐฑ ๋ฌด์ ๋งค์นญ)# - G2P ์๋ ์ ํ: g2pk -> g2pk2 -> g2pkk# - Kiwi: "์ค๊ฐ ๋ง 2.0" ๋ชจ๋(ํ์ฌ ๊ธฐ๋ฐ ๋ณดํธ) + ๋์ด์ฐ๊ธฐ ๊ต์ ๋งค์นญ(์ต์ )# - TTS ๋ฏธ๋ฆฌ๋ฃ๊ธฐ ๋ฒํผ (๋ธ๋ผ์ฐ์ ๋ด์ฅ ์์ฑ)# * ์๋ฌธ์ ์ ๋ ์์ ํ์ง ์๊ณ ๋ณํ ์ถ๋ ฅ๋ง ์์ฑํ๋ค๋ ์์น ์ ์ง# =====================================================================11 unmodified linesexcept Exception as _e:print(f"G2P {_mod} ๋ก๋ฉ ์คํจ: {_e}")# ---------- Kiwi ๋ก๋ฉ (์ ํ ๊ธฐ๋ฅ: ์ค๊ฐ ๋ง 2.0 / ๋์ด์ฐ๊ธฐ ๊ต์ ) ----------kiwi = Nonetry:from kiwipiepy import Kiwi130 unmodified linesreturn re.sub(r'[\s,\.ยท]', '', s)def _build_pattern(keys):"""ํค์ ๊ณต๋ฐฑ์ \\s* ๋ก ๋ฐ๊พผ ์ ์ฐ ํจํด. (์ปดํ์ผ๋ ํจํด, ๊ทธ๋ฃน๋ฒํธ->ํค ๋ชฉ๋ก) ๋ฐํ."""ordered = sorted(keys, key=lambda x: len(x.replace(" ", "")), reverse=True)if not ordered:return None, []59 unmodified linesres.append(apply_g2p(chunk[last:], mode))return "".join(res)def convert_text(text, mode, flat_dict, spacing_fix=False):"""์ ์ฒด ๋ณํ ํ์ดํ๋ผ์ธ: (์ต์ Kiwi ๋์ด์ฐ๊ธฐ ๊ต์ ) -> ํ๊ธฐ ์ ๊ทํ -> ๋ฐ์ ์นํ-> ๋จ์ ๊ตฌ๊ฐ์ ์ซ์ ์ ๊ท์ -> ๋ฐ์ ์นํ 2์ฐจ -> g2p(๋ณดํธ ๊ตฌ๊ฐ ์ ์ธ)"""if spacing_fix and kiwi is not None:try:text = kiwi.space(text)except Exception:passeng = get_engine(flat_dict)t = _sub_phase1(text, eng)out = []2 unmodified linesout.append(chunk)continuechunk = apply_smart_regex(chunk)# ์ซ์ ๋ณํ ๊ฒฐ๊ณผ์ ๋ฐ์ ๊ท์น์ ํ ๋ฒ ๋ (์: 100% -> ๋ฐฑํ๋ก -> ๋ฐฑํผ์ผํธ)for fixed2, c2 in _segments_phase2(chunk, eng):out.append(c2 if fixed2 else _g2p_shielded(c2, mode, eng))return "".join(out)# ---------- ์๋ฏธ ๋์ด์ฝ๊ธฐ (Kiwi ํธํก๊ตฌ) ----------_BREATH_TAGS = {"JKS", "JKC", "JKG", "JKO", "JKB", "JKV", "JX", "JC","EF", "EC", "ETN", "ETM", "SF", "SP", "SE", "SY"}_BREATH_MIN = 5 # ์ต์ ์ด๋งํผ์ ๋ถ์ฌ ์ฝ๋๋ค (๊ธฐ๋ณธ 5: 4๋ ์ฅ๋ฌธ ๊ณผ๋ถํ , 6์ ์ด์ฅ๋ฌธ ๊ณผ๋ฌถ์)_BREATH_MAX = 14 # ํธํก ๊ธธ์ด ์ํ (์ด๊ณผ ์ ๊ฐ์ ๋ถํ )def add_breath_groups(text):"""Kiwi ํ์ฌ ๊ธฐ๋ฐ '์๋ฏธ ๋์ด์ฝ๊ธฐ': ์กฐ์ฌ(J*)/์ด๋ฏธ(E*)/๋ฌธ์ฅ๋ถํธ ๋ค์์ ' / ' ์ฝ์ .์ฌ๋์ด ๋๋ณธ์ ๋์ด ์ฝ๋ ๋จ์(์ด์จ๊ตฌ/ํธํก๊ตฌ)๋ฅผ ํ๋ด๋ด์ด TTS์ ์์ฐ์ค๋ฌ์ด ํธํก์ ์ค๋ค."""if kiwi is None or not text or not text.strip():return texteojeols = [e for e in text.split() if e.strip()]groups, cur, cur_len = [], [], 0for e in eojeols:cur.append(e)cur_len += len(re.sub(r"[^๊ฐ-ํฃa-zA-Z0-9]", "", e)) or len(e)try:tag = kiwi.tokenize(e)[-1].tagexcept Exception:tag = Noneif (tag in _BREATH_TAGS and cur_len >= _BREATH_MIN) or cur_len >= _BREATH_MAX:groups.append(" ".join(cur))cur, cur_len = [], 0if cur:groups.append(" ".join(cur))return " / ".join(groups)# ---------- G2P ๋ชจ๋ ----------_KIWI_PROTECT_TAGS = ("NNP", "SL", "SH", "SN", "SW") # ๊ณ ์ ๋ช ์ฌยท์ธ๋์ดยทํ์ยท์ซ์ยท๊ธฐํธ99 unmodified linesreturn text# ---------- ๋ฉ์ธ ๋ณํ ----------def process_text(input_text, ai_mode, auto_break, smart_pause, spacing_fix, breath_groups, font_size, user_temp_dict):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์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."clean_text = input_text.replace('\r', '')3 unmodified linesif not flat_dict:final_text = apply_g2p(apply_smart_regex(input_text), ai_mode)else:final_text = convert_text(input_text, ai_mode, flat_dict, spacing_fix)if breath_groups and kiwi is not None:final_text = add_breath_groups(final_text)24 unmodified linesdef get_file():return dict_path if os.path.exists(dict_path) else Nonedef add_and_update(word, pronun, user_role, current_input, ai_mode, auto_break, smart_pause, spacing_fix, breath_groups, font_size, user_temp_dict):if not word or not pronun:return "โ ๏ธ ๋จ์ด์ ๋ฐ์์ ์ ๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dictword, pronun = word.strip(), pronun.strip()9 unmodified linesuser_temp_dict[word] = pronunstatus_msg = f"๐ค [๊ฒ์คํธ] '{word}' -> '{pronun}' ์์ ์ ์ฅ ์๋ฃ! (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ - ์๊ตฌ ๋ฑ๋ก์ ์ด๋๋ฏผ์๊ฒ ์์ฒญ)"if current_input.strip():ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, spacing_fix, breath_groups, font_size, user_temp_dict)return status_msg, ft, ho, cc, mr, user_temp_dictreturn status_msg, gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict164 unmodified linesai_mode = gr.Radio(choices=_mode_choices, value="์ค๊ฐ ๋ง (๋ช ์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)", label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋")auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋ ์๋ ์ค๋ฐ๊ฟ", value=False)smart_pause = gr.Checkbox(label="โฑ๏ธ ์ผํ ๋ค ํธํก์ ( / ) ์ถ๊ฐ", value=False)spacing_fix = gr.Checkbox(label=("๐ ๋์ด์ฐ๊ธฐ ๊ต์ ํ ๋งค์นญ (Kiwi, ์คํ์ ) โ โ Kiwi ๋ก๋๋จ"if kiwi is not Noneelse "๐ ๋์ด์ฐ๊ธฐ ๊ต์ ํ ๋งค์นญ (Kiwi, ์คํ์ ) โ โ ๏ธ Kiwi ๋ฏธ์ค์น (requirements.txt์ kiwipiepy ์ถ๊ฐ ํ์)"),value=False,interactive=(kiwi is not None))breath_groups = gr.Checkbox(label=("๐ฌ๏ธ ์๋ฏธ ๋์ด์ฝ๊ธฐ (Kiwi ํธํก๊ตฌ, ์คํ์ ) โ โ Kiwi ๋ก๋๋จ"if kiwi is not None26 unmodified linesbtn_clear_dict_inputs = gr.Button("๐งน ์ ๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary")status = gr.Textbox(label="์ ์ฅ ์ํ", interactive=False)proc_inputs = [input_text, ai_mode, auto_break, smart_pause, spacing_fix, breath_groups, font_size, user_temp_dict]proc_outputs = [output_text, output_html, char_count, marker_collection]btn_insert_marker.click(fn=None, inputs=[input_text], outputs=[input_text], js=insert_marker_js, api_name=False)2 unmodified linesbtn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count, marker_collection], api_name=False)btn_copy.click(fn=None, inputs=[output_text], outputs=None, js="(t) => { if(t) { navigator.clipboard.writeText(t); alert('โ ๋ณต์ฌ ์๋ฃ!'); } }", api_name=False)btn_tts.click(fn=None, inputs=[output_text], outputs=None, js=tts_js, api_name=False)btn_add.click(fn=add_and_update, inputs=[nw, np, user_role, input_text, ai_mode, auto_break, smart_pause, spacing_fix, breath_groups, font_size, user_temp_dict], outputs=[status, output_text, output_html, char_count, marker_collection, user_temp_dict], api_name=False)btn_clear_dict_inputs.click(fn=lambda: ("", ""), outputs=[nw, np], api_name=False)for evt in [font_size.change, ai_mode.change, auto_break.change, smart_pause.change, spacing_fix.change, breath_groups.change]:evt(fn=process_text, inputs=proc_inputs, outputs=proc_outputs, api_name=False)with gr.Tab("๐ฅ ์๋ ๋ฐฑ์ /์กฐํ/์์ "):dl_btn = gr.DownloadButton("๐ฅ 1. ์ฌ์ ๋ฐฑ์ (PC ๋ค์ด๋ก๋)")9 unmodified lines1011121314151611 unmodified lines28293031323334130 unmodified lines16516616716816917017159 unmodified lines2312322332342352362372382392402412422432 unmodified lines24624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537699 unmodified lines4764774784794804814823 unmodified lines48648748848949049149224 unmodified lines5175185195205215225239 unmodified lines533534535536537538539164 unmodified lines70470570670770870971026 unmodified lines7377387397407417427432 unmodified lines7467477487497507517527537549 unmodified lines# - P0: ์ฌ์ ์๊ตฌ ์ ์ฅ (HF Dataset ์๋ ์ปค๋ฐ) + AUTO_MERGE ๋นํ๊ดดํ# - P1: ๋งค์นญ ์์ง ๊ต์ฒด (2๋จ๊ณ: ํ๊ธฐ ์ ๊ทํ -> ๋ฐ์ ์นํ, ๊ณต๋ฐฑ ๋ฌด์ ๋งค์นญ)# - G2P ์๋ ์ ํ: g2pk -> g2pk2 -> g2pkk# - Kiwi: "์ค๊ฐ ๋ง 2.0" ๋ชจ๋(ํ์ฌ ๊ธฐ๋ฐ ๋ณดํธ) + ํธํก๊ตฌ ๋ฆฌ์คํ์ด์ฑ(์ต์ )# - TTS ๋ฏธ๋ฆฌ๋ฃ๊ธฐ ๋ฒํผ (๋ธ๋ผ์ฐ์ ๋ด์ฅ ์์ฑ)# * ์๋ฌธ์ ์ ๋ ์์ ํ์ง ์๊ณ ๋ณํ ์ถ๋ ฅ๋ง ์์ฑํ๋ค๋ ์์น ์ ์ง# =====================================================================11 unmodified linesexcept Exception as _e:print(f"G2P {_mod} ๋ก๋ฉ ์คํจ: {_e}")# ---------- Kiwi ๋ก๋ฉ (์ ํ ๊ธฐ๋ฅ: ์ค๊ฐ ๋ง 2.0 / ํธํก๊ตฌ ๋ฆฌ์คํ์ด์ฑ) ----------kiwi = Nonetry:from kiwipiepy import Kiwi130 unmodified linesreturn re.sub(r'[\s,\.ยท]', '', s)def _build_pattern(keys):"""ํค์ ๊ณต๋ฐฑ์ \s* ๋ก ๋ฐ๊พผ ์ ์ฐ ํจํด. (์ปดํ์ผ๋ ํจํด, ๊ทธ๋ฃน๋ฒํธ->ํค ๋ชฉ๋ก) ๋ฐํ."""ordered = sorted(keys, key=lambda x: len(x.replace(" ", "")), reverse=True)if not ordered:return None, []59 unmodified linesres.append(apply_g2p(chunk[last:], mode))return "".join(res)def convert_text(text, mode, flat_dict):"""์ ์ฒด ๋ณํ ํ์ดํ๋ผ์ธ: ํ๊ธฐ ์ ๊ทํ -> ๋ฐ์ ์นํ -> ๋จ์ ๊ตฌ๊ฐ์ ์ซ์ ์ ๊ท์-> ๋ฐ์ ์นํ 2์ฐจ -> g2p(๋ณดํธ ๊ตฌ๊ฐ ์ ์ธ).(๋ฆฌ๋ทฐ 2026-08-29: kiwi.space ๊ธฐ๋ฐ '๋์ด์ฐ๊ธฐ ๊ต์ ํ ๋งค์นญ' ๊ธฐ๋ฅ์ ์ ๊ฑฐ.์๋ฌธ ๋น๊ณต๋ฐฑ ๋ฌธ์์ด์ 1๋ฐ์ดํธ๋ ๋ฐ๊พธ์ง ์๋๋ค๋ ๋ถ๋ณ์์ ๋ง์กฑ์ํค๊ธฐ ์ํด์ธํ ๊ต์ ์ ํธํก๊ตฌ ๋ฆฌ์คํ์ด์ฑ(add_breath_groups)์ผ๋ก ์ผ์ํํ๋ค.)๋ถ๋ณ์: re.sub(r'\s+', '', input) == re.sub(r'\s+', '', output)"""eng = get_engine(flat_dict)t = _sub_phase1(text, eng)out = []2 unmodified linesout.append(chunk)continuechunk = apply_smart_regex(chunk)for fixed2, c2 in _segments_phase2(chunk, eng):out.append(c2 if fixed2 else _g2p_shielded(c2, mode, eng))return "".join(out)# ===== BREATH-BLOCK-BEGIN =====# ---------- ํธํก๊ตฌ ๋ฆฌ์คํ์ด์ฑ (์๋ฌธ ๋ถ๋ณ + ์์ ๋ง ํฌํจ) ----------# [2026-08-29 v2] ์ ๊ฒฝ๊ณ ๋ถํ + ๋ฌธ๋์ฃผ์ ๋ถ๋ฆฌ + ๊ทธ๋ฃน ๋ด ๋ถ์ฌ์ฝ๊ธฐ + MAX9# ๋ถ๋ณ์: re.sub(r'[\s/]', '', ์ ๋ ฅ) == re.sub(r'[\s/]', '', ์ถ๋ ฅ)# - ํ๋ฝ: ๊ณต๋ฐฑ ์ฝ์ ยท์ญ์ , ํธํก๊ตฌ ์ฌ์ด ' / ' ๋ง์ปค ๋ถ์ฐฉ(=๊ณต๋ฐฑ ๋ณํ)# - ๊ธ์ง: ์กฐ์ฌ/์ด๋ฏธ ๋ถ๋ฆฌ, ๊ธ์ ๋จ์ ๋ณํ, ์ด์ ๋ณํฉยท๋ถํ , ์คํ์ ๊ต์ # โ๏ธ ๋ณํ์ด ์ด์ํด์ก์ ๋: ์ด ํ ์ค๋ง False ๋ก ๋ฐ๊พธ๋ฉด ๊ธฐ์กด(v1) ๋์์ผ๋ก ์ฆ์ ๋ณต๊ทUSE_NEW_BREATH = True_BREATH_TAGS = {"EC", "EF", "ETN", "ETM", "SF", "SP", "SE", "SY"} # ์ /๋ฌธ ๊ฒฝ๊ณ๋ง (๊ฒฉ์กฐ์ฌ X)_BREATH_MIN = 5 # ํ ํธํก ์ต์ ๊ธ์ (5 ๋ฏธ๋ง์ด๋ฉด ๋ถํ ์ ํจ)_BREATH_MAX = 9 # ํ ํธํก ์ํ ๊ธ์ (๊ฑฐ์ฌ๋ฆฌ๋ฉด 10~11๋ก ์ํ)_BREATH_JOIN = True # True: ๊ฐ์ ํธํก๊ตฌ ์ ๊ณต๋ฐฑ ์ ๊ฑฐ(๋ถ์ฌ ์ฝ๊ธฐ) / False: 1์นธ ์ ์ง_CODE_TAGS = ("SL", "SN", "SW") # ์๋ฌธยท์ซ์ยท๊ธฐํธ (์ฝ๋ ํด๋ฌ์คํฐ ๋ด๋ถ ๋ถํ ๊ธ์ง)_BREATH_TAGS_LEGACY = {"JKS", "JKC", "JKG", "JKO", "JKB", "JKV", "JX", "JC","EF", "EC", "ETN", "ETM", "SF", "SP", "SE", "SY"}_BREATH_MIN_LEGACY = 5_BREATH_MAX_LEGACY = 14def _breath_len(e):return len(re.sub(r"[^๊ฐ-ํฃa-zA-Z0-9]", "", e)) or len(e)def _breath_last_tag(e):try:toks = kiwi.tokenize(e)return toks[-1].tag if toks else Noneexcept Exception:return Nonedef add_breath_groups_legacy(text):"""[๋กค๋ฐฑ์ฉ] ๊ธฐ์กด v1 ํจ์ (๊ฒฉ์กฐ์ฌ ํฌํจ ํ๊ทธ + MIN5/MAX14 + ๊ทธ๋ฃน ๋ด 1์นธ ๊ณต๋ฐฑ)"""if kiwi is None or not text or not text.strip():return textorig_eojeols = text.split()if len(orig_eojeols) <= 1:return textgroups, cur, cur_len = [], [], 0for e in orig_eojeols:cur.append(e)cur_len += _breath_len(e)tag = _breath_last_tag(e)if (tag in _BREATH_TAGS_LEGACY and cur_len >= _BREATH_MIN_LEGACY) or cur_len >= _BREATH_MAX_LEGACY:groups.append(cur)cur, cur_len = [], 0if cur:groups.append(cur)return " / ".join(" ".join(g) for g in groups)def add_breath_groups_new(text):"""[v2] ์ ๊ฒฝ๊ณ ๋ถํ + ๋ฌธ๋์ฃผ์ ๋ถ๋ฆฌ + ๊ทธ๋ฃน ๋ด ๋ถ์ฌ์ฝ๊ธฐ + MAX9"""if kiwi is None or not text or not text.strip():return textes = text.split()n = len(es)if n <= 1:return textgroups, cur, cur_len = [], [], 0for i, e in enumerate(es):tag = _breath_last_tag(e)# โ ๋ฌธ๋ ์ฃผ์ (์/๋) = ๋ ๋ฆฝ ํธํก๊ตฌ โ "์ค๋์ / ..."if i == 0 and tag == "JX" and n > 1:groups.append([e])continue# โก ์๋ฌธยท์ซ์ยท๊ธฐํธ ํด๋ฌ์คํฐ๋ ๋ด๋ถ ๋ถํ ๊ธ์ง โ "GS๋ง์ด์ต 26SS" ์ ์งif cur and tag in _CODE_TAGS and _breath_last_tag(cur[-1]) in _CODE_TAGS:cur.append(e); cur_len += _breath_len(e)continuecur.append(e); cur_len += _breath_len(e)# โข ์ /๋ฌธ ๊ฒฝ๊ณ + ์ต์ยท์ต๋ ์ถฉ์กฑ ์ ๋ถํif tag in _BREATH_TAGS and _BREATH_MIN <= cur_len <= _BREATH_MAX:groups.append(cur); cur, cur_len = [], 0continue# โฃ ์ํ ์ด๊ณผ โ ๊ฐ์ ๋ถํ (๋ฐฉ๊ธ ๋ถ์ธ ์ด์ ์ด ์ฝ๋๋ฉด ์์ธ)if cur_len > _BREATH_MAX and tag not in _CODE_TAGS:if len(cur) >= 2 and cur_len - _breath_len(e) >= _BREATH_MIN:groups.append(cur[:-1]); cur = [cur[-1]]; cur_len = _breath_len(e)else:groups.append(cur); cur, cur_len = [], 0if cur:groups.append(cur)sep = "" if _BREATH_JOIN else " "return " / ".join(sep.join(g) for g in groups)def _invariant_ok(out, src):"""์๋ฌธ ๋น๊ณต๋ฐฑ(๊ณต๋ฐฑยท'/' ์ ๊ฑฐ) ๋ฌธ์์ด์ด ๊ทธ๋๋ก์ธ์ง ํ์ธ"""try:return re.sub(r'[\s/]', '', src) == re.sub(r'[\s/]', '', out)except Exception:return Falsedef _max_ok(out):"""ํธํก๊ตฌ๋ณ ๊ธ์ ์(๊ณต๋ฐฑยท'/' ์ ์ธ)๊ฐ _BREATH_MAX ์ดํ์ธ์ง ํ์ธ"""try:for g in out.split(" / "):if len(re.sub(r'[\s/]', '', g)) > _BREATH_MAX:return Falsereturn Trueexcept Exception:return Falsedef add_breath_groups(text):"""๋ฉ์ธ ์ํธ๋ฆฌ: ์ ํจ์ ์คํ โ ๋ถ๋ณ์ ๊ฒ์ฆ โ ์คํจ ์ ์๋์ผ๋ก ๊ธฐ์กด(v1) ๊ฒฐ๊ณผ ๋ฐํ.USE_NEW_BREATH = False ๋ก ๋ฐ๊พธ๋ฉด ์ฒ์๋ถํฐ v1(legacy)๋ฅผ ์ฌ์ฉํฉ๋๋ค."""if not USE_NEW_BREATH:return add_breath_groups_legacy(text)out = add_breath_groups_new(text)if _invariant_ok(out, text):return out# ์์ ๋ง: ์ ํจ์ ์ถ๋ ฅ์ด ๋ถ๋ณ์(๊ธ์ ์ ์คยท๋ณํ)์ ๊นจ๋ฉด ๊ธฐ์กด ํจ์๋ก ์๋ ๋ณต๊ท# (MAX ๊ธธ์ด ์ด๊ณผ๋ "๋ฌธ์ฒด" ๋ฌธ์ ์ด๋ฏ๋ก ํด๋ฐฑ ๋์์ด ์๋ โ _BREATH_MIN/MAX๋ก ํ๋)return add_breath_groups_legacy(text)# ===== BREATH-BLOCK-END =====# ---------- G2P ๋ชจ๋ ----------_KIWI_PROTECT_TAGS = ("NNP", "SL", "SH", "SN", "SW") # ๊ณ ์ ๋ช ์ฌยท์ธ๋์ดยทํ์ยท์ซ์ยท๊ธฐํธ99 unmodified linesreturn text# ---------- ๋ฉ์ธ ๋ณํ ----------def process_text(input_text, ai_mode, auto_break, smart_pause, breath_groups, font_size, user_temp_dict):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์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."clean_text = input_text.replace('\r', '')3 unmodified linesif not flat_dict:final_text = apply_g2p(apply_smart_regex(input_text), ai_mode)else:final_text = convert_text(input_text, ai_mode, flat_dict)if breath_groups and kiwi is not None:final_text = add_breath_groups(final_text)24 unmodified linesdef get_file():return dict_path if os.path.exists(dict_path) else Nonedef add_and_update(word, pronun, user_role, current_input, ai_mode, auto_break, smart_pause, breath_groups, font_size, user_temp_dict):if not word or not pronun:return "โ ๏ธ ๋จ์ด์ ๋ฐ์์ ์ ๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dictword, pronun = word.strip(), pronun.strip()9 unmodified linesuser_temp_dict[word] = pronunstatus_msg = f"๐ค [๊ฒ์คํธ] '{word}' -> '{pronun}' ์์ ์ ์ฅ ์๋ฃ! (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ - ์๊ตฌ ๋ฑ๋ก์ ์ด๋๋ฏผ์๊ฒ ์์ฒญ)"if current_input.strip():ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, breath_groups, font_size, user_temp_dict)return status_msg, ft, ho, cc, mr, user_temp_dictreturn status_msg, gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict164 unmodified linesai_mode = gr.Radio(choices=_mode_choices, value="์ค๊ฐ ๋ง (๋ช ์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)", label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋")auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋ ์๋ ์ค๋ฐ๊ฟ", value=False)smart_pause = gr.Checkbox(label="โฑ๏ธ ์ผํ ๋ค ํธํก์ ( / ) ์ถ๊ฐ", value=False)# [์ ๊ฑฐ๋จ 2026-08-29] "๐ ๋์ด์ฐ๊ธฐ ๊ต์ ํ ๋งค์นญ" ์ฒดํฌ๋ฐ์ค ์ ๊ฑฐ โ kiwi.space()๊ฐ ์กฐ์ฌ/์ด๋ฏธ๋ฅผ ๋ถ๋ฆฌํด ์๋ฌธ ๊ธ์๋ฅผ ํผ์ํ์breath_groups = gr.Checkbox(label=("๐ฌ๏ธ ์๋ฏธ ๋์ด์ฝ๊ธฐ (Kiwi ํธํก๊ตฌ, ์คํ์ ) โ โ Kiwi ๋ก๋๋จ"if kiwi is not None26 unmodified linesbtn_clear_dict_inputs = gr.Button("๐งน ์ ๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary")status = gr.Textbox(label="์ ์ฅ ์ํ", interactive=False)proc_inputs = [input_text, ai_mode, auto_break, smart_pause, breath_groups, font_size, user_temp_dict]proc_outputs = [output_text, output_html, char_count, marker_collection]btn_insert_marker.click(fn=None, inputs=[input_text], outputs=[input_text], js=insert_marker_js, api_name=False)2 unmodified linesbtn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count, marker_collection], api_name=False)btn_copy.click(fn=None, inputs=[output_text], outputs=None, js="(t) => { if(t) { navigator.clipboard.writeText(t); alert('โ ๋ณต์ฌ ์๋ฃ!'); } }", api_name=False)btn_tts.click(fn=None, inputs=[output_text], outputs=None, js=tts_js, api_name=False)btn_add.click(fn=add_and_update, inputs=[nw, np, user_role, input_text, ai_mode, auto_break, smart_pause, breath_groups, font_size, user_temp_dict], outputs=[status, output_text, output_html, char_count, marker_collection, user_temp_dict], api_name=False)btn_clear_dict_inputs.click(fn=lambda: ("", ""), outputs=[nw, np], api_name=False)for evt in [font_size.change, ai_mode.change, auto_break.change, smart_pause.change, breath_groups.change]:evt(fn=process_text, inputs=proc_inputs, outputs=proc_outputs, api_name=False)with gr.Tab("๐ฅ ์๋ ๋ฐฑ์ /์กฐํ/์์ "):dl_btn = gr.DownloadButton("๐ฅ 1. ์ฌ์ ๋ฐฑ์ (PC ๋ค์ด๋ก๋)")
app.py+132-44