Spaces:
Running
Running
Update app.py
Browse files104 unmodified lines1051061071081081091101121111121136 unmodified lines120121122123124125126127125128129130131155 unmodified lines2872882892872882892902912912922932942952962972922932942952962973023033042982993063073083093103113123003013023033043053173183193063073213223233243253263273083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453466 unmodified lines35335435534535635735835936036136236336436512 unmodified lines378379380366381382383384370385386387388389390391104 unmodified lines if 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 lines elif 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;">{"".join(html_parts)}</div>' 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_count
def clear_all():155 unmodified lines if (target === ta1) { if (isSyncing1) { isSyncing1 = false; return; } if (ta1.scrollHeight - ta1.clientHeight <= 0) return; isSyncing2 = true; isSyncing3 = true; 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); } 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; 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); } 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; 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); } 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 lines 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") 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 lines nw = gr.Textbox(label="๊ธฐ์กด ๋จ์ด ๋๋ ๋ฌธ์ฅ (2๊ธ์ ์ด์)") np = gr.Textbox(label="์ํ๋ ๋ฐ์") with gr.Column(min_width=200): btn_add = gr.Button("๐พ ์ฌ์ ์ ์ถ๊ฐํ๊ณ ์ฆ์ ๋๋ณธ ๋ณํํ๊ธฐ", variant="primary") btn_add = ๊ฒ= gr.Button("๐พ ์ฌ์ ์ ์ถ๊ฐํ๊ณ ์ฆ์ ๋๋ณธ ๋ณํํ๊ธฐ", variant="primary") btn_clear_dict_inputs = gr.Button("๐งน ๋จ์ด ์
๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary") status = gr.Textbox(label="์ ์ฅ ์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) # โ
smart_pause ๋ณ์๊ฐ ํ๋ผ๋ฏธํฐ๋ก ์ถ๊ฐ๋จ # ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ๋ค 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