Spaces:
Running
Running
Update app.py
Browse files164 unmodified lines16516616716816816917017180 unmodified lines25225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328498 unmodified lines3833843853593863873883895 unmodified lines39539639739839940040140221 unmodified lines4244254263984274284294309 unmodified lines440441442414443444445446170 unmodified lines61761861962062162262362462562662762820 unmodified lines6496506516176526536546552 unmodified lines658659660626661662628663664665666164 unmodified lines return re.sub(r'[\s,\.ยท]', '', s)
def _build_pattern(keys): """ํค์ ๊ณต๋ฐฑ์ \s* ๋ก ๋ฐ๊พผ ์ ์ฐ ํจํด. (์ปดํ์ผ๋ ํจํด, ๊ทธ๋ฃน๋ฒํธ->ํค ๋ชฉ๋ก) ๋ฐํ.""" """ํค์ ๊ณต๋ฐฑ์ \\s* ๋ก ๋ฐ๊พผ ์ ์ฐ ํจํด. (์ปดํ์ผ๋ ํจํด, ๊ทธ๋ฃน๋ฒํธ->ํค ๋ชฉ๋ก) ๋ฐํ.""" ordered = sorted(keys, key=lambda x: len(x.replace(" ", "")), reverse=True) if not ordered: return None, []80 unmodified lines 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 text eojeols = [e for e in text.split() if e.strip()] groups, cur, cur_len = [], [], 0 for 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].tag except Exception: tag = None if (tag in _BREATH_TAGS and cur_len >= _BREATH_MIN) or cur_len >= _BREATH_MAX: groups.append(" ".join(cur)) cur, cur_len = [], 0 if cur: groups.append(" ".join(cur)) return " / ".join(groups)
# ---------- G2P ๋ชจ๋ ----------_KIWI_PROTECT_TAGS = ("NNP", "SL", "SH", "SN", "SW") # ๊ณ ์ ๋ช
์ฌยท์ธ๋์ดยทํ์ยท์ซ์ยท๊ธฐํธ
98 unmodified lines return text
# ---------- ๋ฉ์ธ ๋ณํ ----------def process_text(input_text, ai_mode, auto_break, smart_pause, spacing_fix, font_size, user_temp_dict):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', '')5 unmodified lines 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) if smart_pause: final_text = re.sub(r',\s*', ', / ', final_text) if auto_break:21 unmodified linesdef get_file(): return dict_path if os.path.exists(dict_path) else None
def add_and_update(word, pronun, user_role, current_input, ai_mode, auto_break, smart_pause, spacing_fix, font_size, user_temp_dict):def 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_dict word, pronun = word.strip(), pronun.strip()9 unmodified lines user_temp_dict[word] = pronun status_msg = f"๐ค [๊ฒ์คํธ] '{word}' -> '{pronun}' ์์ ์ ์ฅ ์๋ฃ! (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ - ์๊ตฌ ๋ฑ๋ก์ ์ด๋๋ฏผ์๊ฒ ์์ฒญ)" if current_input.strip(): ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, spacing_fix, font_size, user_temp_dict) 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_dict return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict
170 unmodified lines else "๐ ๋์ด์ฐ๊ธฐ ๊ต์ ํ ๋งค์นญ (Kiwi, ์คํ์ ) โ โ ๏ธ Kiwi ๋ฏธ์ค์น (requirements.txt์ kiwipiepy ์ถ๊ฐ ํ์)"), value=False, interactive=(kiwi is not None)) breath_groups = gr.Checkbox( label=("๐ฌ๏ธ ์๋ฏธ ๋์ด์ฝ๊ธฐ (Kiwi ํธํก๊ตฌ, ์คํ์ ) โ โ
Kiwi ๋ก๋๋จ" if kiwi is not None else "๐ฌ๏ธ ์๋ฏธ ๋์ด์ฝ๊ธฐ (Kiwi ํธํก๊ตฌ, ์คํ์ ) โ โ ๏ธ Kiwi ๋ฏธ์ค์น (requirements.txt์ kiwipiepy ์ถ๊ฐ ํ์)"), value=False, interactive=(kiwi is not None)) btn_insert_marker = gr.Button("๐จ ๋ง์ปค(@@) ์ฝ์
", variant="secondary", size="sm") font_size = gr.Slider(minimum=16, maximum=40, value=22, step=2, label="๐ ๊ธ์ ํฌ๊ธฐ")
20 unmodified lines btn_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, font_size, user_temp_dict] 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 lines btn_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, font_size, user_temp_dict], outputs=[status, output_text, output_html, char_count, marker_collection, user_temp_dict], 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]: 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 ๋ค์ด๋ก๋)")app.py+42-7