Spaces:
Running
Running
Update app.py
Browse files104 unmodified lines1051061071081091101111121131141156 unmodified lines122123124125126127128155 unmodified lines2842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343356 unmodified lines34234334434534634734834935012 unmodified lines363364365366367368369370371372373104 unmodified linesif tail: parts.append(apply_g2p(tail, ai_mode))final_text = "".join(parts)# โ 1. ์ค๋งํธ ํธํก์ ์ถ๊ฐ (์ผํ ๋ค์ ์๊ฐ์ ๋์ด์ฝ๊ธฐ ๊ธฐํธ ์ฝ์ )if smart_pause:final_text = re.sub(r',\s*', ', / ', final_text)# โ 2. ๋ฌธ์ฅ ๋ ์ค๋ฐ๊ฟif auto_break:final_text = final_text.replace(". ", ".\n\n").replace("? ", "?\n\n")6 unmodified lineselif tag in['replace', 'insert']:html_parts.append(f'<span style="background-color: #ffe066; font-weight: bold; padding: 2px; border-radius: 3px; color: #000;">{chunk}</span>')html_output = f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div><div id="prompter_output_div" style="font-size:{font_size}px;">{"".join(html_parts)}</div>'return final_text, html_output, char_countdef clear_all():155 unmodified linesif (target === ta1) {if (isSyncing1) { isSyncing1 = false; return; }if (ta1.scrollHeight - ta1.clientHeight <= 0) return;isSyncing2 = true;isSyncing3 = true;let percentage = ta1.scrollTop / (ta1.scrollHeight - ta1.clientHeight);if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) {ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight);}if (div3.scrollHeight - div3.clientHeight > 0) {div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight);}}else if (target === ta2) {if (isSyncing2) { isSyncing2 = false; return; }if (ta2 && ta2.scrollHeight - ta2.clientHeight <= 0) return;isSyncing1 = true;isSyncing3 = true;let percentage = ta2.scrollTop / (ta2.scrollHeight - ta2.clientHeight);if (ta1.scrollHeight - ta1.clientHeight > 0) {ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight);}if (div3.scrollHeight - div3.clientHeight > 0) {div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight);}}else if (target === div3) {if (isSyncing3) { isSyncing3 = false; return; }if (div3.scrollHeight - div3.clientHeight <= 0) return;isSyncing1 = true;isSyncing2 = true;let percentage = div3.scrollTop / (div3.scrollHeight - div3.clientHeight);if (ta1.scrollHeight - ta1.clientHeight > 0) {ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight);}if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) {ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight);}}}, true);}"""with gr.Blocks(theme="default", css=custom_css) as iface:gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ (ํ๋กฌํํฐ ๋ชจ๋)")6 unmodified linesgr.Markdown("**โ๏ธ ๋ณํ ๋ฐ ํ๋ฉด ์ค์ **")ai_mode = gr.Radio(choices=["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", "์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ - ๊ณผ๋ํ ์ฐ์ ๋ฐฉ์ง)", "๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก - ์์ฐ์ค๋ฌ์ด ์ฐ์)"], value="๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋ ์ ํ")auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋์์ ์๋์ผ๋ก ์ค๋ฐ๊ฟ ํ๊ธฐ", value=False)# โ ์๋ก ์ถ๊ฐ๋ ํธํก์ ์ต์ ์ฒดํฌ๋ฐ์คsmart_pause = gr.Checkbox(label="โฑ๏ธ ์ค๋งํธ ํ๋กฌํํฐ ํธํก์ ( / ) ์ถ๊ฐํ๊ธฐ (์ผํ ๋ค)", value=False)font_size = gr.Slider(minimum=16, maximum=40, value=22, step=2, label="๐ ๊ฒฐ๊ณผ์ฐฝ ๊ธ์ ํฌ๊ธฐ ์กฐ์ ")char_count = gr.Textbox(label="๊ธ์ ์ ํ์ธ", value="์ ๋ ฅ ๊ธ์ ์: 0์", interactive=False)with gr.Row():btn_conv = gr.Button("โจ ๋ณํํ๊ธฐ", variant="primary")12 unmodified linesnw = gr.Textbox(label="๊ธฐ์กด ๋จ์ด ๋๋ ๋ฌธ์ฅ (2๊ธ์ ์ด์)")np = gr.Textbox(label="์ํ๋ ๋ฐ์")with gr.Column(min_width=200):btn_add = gr.Button("๐พ ์ฌ์ ์ ์ถ๊ฐํ๊ณ ์ฆ์ ๋๋ณธ ๋ณํํ๊ธฐ", variant="primary")btn_clear_dict_inputs = gr.Button("๐งน ๋จ์ด ์ ๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary")status = gr.Textbox(label="์ ์ฅ ์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False)# โ smart_pause ๋ณ์๊ฐ ํ๋ผ๋ฏธํฐ๋ก ์ถ๊ฐ๋จbtn_conv.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count], api_name=False)btn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count], api_name=False)btn_copy.click(fn=None, inputs=[output_text], outputs=None, js="(text) => { if(text) { navigator.clipboard.writeText(text); alert('โ ๋ณต์ฌ ์๋ฃ!'); } }", api_name=False)104 unmodified lines1051061071081091101111121136 unmodified lines120121122123124125126127128129130131155 unmodified lines2872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453466 unmodified lines35335435535635735835936036136236336436512 unmodified lines378379380381382383384385386387388389390391104 unmodified linesif tail: parts.append(apply_g2p(tail, ai_mode))final_text = "".join(parts)if smart_pause:final_text = re.sub(r',\s*', ', / ', final_text)if auto_break:final_text = final_text.replace(". ", ".\n\n").replace("? ", "?\n\n")6 unmodified lineselif tag in['replace', 'insert']:html_parts.append(f'<span style="background-color: #ffe066; font-weight: bold; padding: 2px; border-radius: 3px; color: #000;">{chunk}</span>')raw_html = "".join(html_parts)# โ ์๋ก ์ถ๊ฐ๋ ๋ถ๋ถ: @@๊ฐ ๋ถ์ ๋จ์ด๋ฅผ ๋นจ๊ฐ์์ผ๋ก ๊ฐ๋ ฅํ๊ฒ ํ์ด๋ผ์ดํธ!raw_html = re.sub(r'(@@[^\s<]+)', r'<span style="background-color: #ff4d4d; color: white; font-weight: bold; padding: 2px 6px; border-radius: 4px; box-shadow: 0 0 5px #ff4d4d;">\1</span>', raw_html)html_output = f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div><div id="prompter_output_div" style="font-size:{font_size}px;">{raw_html}</div>'return final_text, html_output, char_countdef clear_all():155 unmodified linesif (target === ta1) {if (isSyncing1) { isSyncing1 = false; return; }if (ta1.scrollHeight - ta1.clientHeight <= 0) return;isSyncing2 = true; isSyncing3 = true;let percentage = ta1.scrollTop / (ta1.scrollHeight - ta1.clientHeight);if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); }if (div3.scrollHeight - div3.clientHeight > 0) { div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight); }}else if (target === ta2) {if (isSyncing2) { isSyncing2 = false; return; }if (ta2 && ta2.scrollHeight - ta2.clientHeight <= 0) return;isSyncing1 = true; isSyncing3 = true;let percentage = ta2.scrollTop / (ta2.scrollHeight - ta2.clientHeight);if (ta1.scrollHeight - ta1.clientHeight > 0) { ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight); }if (div3.scrollHeight - div3.clientHeight > 0) { div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight); }}else if (target === div3) {if (isSyncing3) { isSyncing3 = false; return; }if (div3.scrollHeight - div3.clientHeight <= 0) return;isSyncing1 = true; isSyncing2 = true;let percentage = div3.scrollTop / (div3.scrollHeight - div3.clientHeight);if (ta1.scrollHeight - ta1.clientHeight > 0) { ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight); }if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); }}}, true);}"""# โ ์ ๋ ฅ์ฐฝ ์ปค์ ์์น์ @@ ์ฝ์ ํ๋ ์๋ฐ์คํฌ๋ฆฝํธ ํจ์insert_marker_js = """(current_text) => {let ta = document.querySelector('#input_text_area textarea');if (!ta) return current_text;let start = ta.selectionStart;let end = ta.selectionEnd;let text = ta.value;// @@ ์ฝ์let before = text.substring(0, start);let after = text.substring(end, text.length);let new_text = before + "@@" + after;ta.value = new_text;// Gradio๊ฐ ๋ณ๊ฒฝ์ฌํญ์ ์ธ์ํ๋๋ก ์ด๋ฒคํธ ๋ฐ์let event = new Event('input', { bubbles: true });ta.dispatchEvent(event);// ํฌ์ปค์ค ์ ์งta.selectionStart = ta.selectionEnd = start + 2;ta.focus();return new_text;}"""with gr.Blocks(theme="default", css=custom_css) as iface:gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ (ํ๋กฌํํฐ ๋ชจ๋)")6 unmodified linesgr.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")font_size = gr.Slider(minimum=16, maximum=40, value=22, step=2, label="๐ ๊ฒฐ๊ณผ์ฐฝ ๊ธ์ ํฌ๊ธฐ ์กฐ์ ")char_count = gr.Textbox(label="๊ธ์ ์ ํ์ธ", value="์ ๋ ฅ ๊ธ์ ์: 0์", interactive=False)with gr.Row():btn_conv = gr.Button("โจ ๋ณํํ๊ธฐ", variant="primary")12 unmodified linesnw = gr.Textbox(label="๊ธฐ์กด ๋จ์ด ๋๋ ๋ฌธ์ฅ (2๊ธ์ ์ด์)")np = gr.Textbox(label="์ํ๋ ๋ฐ์")with gr.Column(min_width=200):btn_add = ๊ฒ= gr.Button("๐พ ์ฌ์ ์ ์ถ๊ฐํ๊ณ ์ฆ์ ๋๋ณธ ๋ณํํ๊ธฐ", variant="primary")btn_clear_dict_inputs = gr.Button("๐งน ๋จ์ด ์ ๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary")status = gr.Textbox(label="์ ์ฅ ์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False)# ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ๋คbtn_insert_marker.click(fn=None, inputs=[input_text], outputs=[input_text], js=insert_marker_js, api_name=False)btn_insert_marker.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count], api_name=False)btn_conv.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count], api_name=False)btn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count], api_name=False)btn_copy.click(fn=None, inputs=[output_text], outputs=None, js="(text) => { if(text) { navigator.clipboard.writeText(text); alert('โ ๋ณต์ฌ ์๋ฃ!'); } }", api_name=False)
app.py+54-36