Spaces:
Running
Running
Update app.py
Browse files79 unmodified lines808182838384858634 unmodified lines1211221231241251241251261271281291301311321331341351361371291381391401321411421431441361451461471481 unmodified line15015115214414514615315415515615715818 unmodified lines177178179171172173180181182183184185135 unmodified lines3213223233153243253263 unmodified lines33033133232533333433533633733833233934034133634234334414 unmodified lines3593603613573583623603633643657 unmodified lines3733743753763773783793803811 unmodified line38338438538138638738838938539038739139238939039339439539239339439539639639739839940040140240379 unmodified lines
def process_text(input_text, ai_mode, auto_break, smart_pause, font_size): if not input_text or not input_text.strip(): return "", "", "์
๋ ฅ ๊ธ์ ์: 0์" return "", "", "์
๋ ฅ ๊ธ์ ์: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." char_count = f"์
๋ ฅ ๊ธ์ ์: {len(input_text)}์" flat_dict = load_dict()34 unmodified lines 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>' # โ
์๋ก ์ถ๊ฐ๋ ๋ถ๋ถ: @@ ๋ง์ปค ์ถ์ถํด์ ๋ชจ์๋ณด๊ธฐ # ํ๊ธ, ์๋ฌธ, ์ซ์๋ก ์ด๋ฃจ์ด์ง ๋จ์ด๋ง ๊น๋ํ๊ฒ ์ถ์ถ (๊ตฌ๋์ ์ ์ธ) markers = re.findall(r'@@([๊ฐ-ํฃa-zA-Z0-9]+)', input_text) unique_markers = list(dict.fromkeys(markers)) # ์ค๋ณต ์ ๊ฑฐ if unique_markers: marker_result = " / ".join(unique_markers) else: marker_result = "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
return final_text, html_output, char_count return final_text, html_output, char_count, marker_result
def clear_all(): return "", "", "", "์
๋ ฅ ๊ธ์ ์: 0์" return "", "", "", "์
๋ ฅ ๊ธ์ ์: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
def add_and_update(word, pronun, current_input, ai_mode, auto_break, smart_pause, font_size): if not word or not pronun: return "โ ๏ธ ๊ธฐ์กด ๋จ์ด์ ์ํ๋ ๋ฐ์์ ๋ชจ๋ ์
๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update() return "โ ๏ธ ๊ธฐ์กด ๋จ์ด์ ์ํ๋ ๋ฐ์์ ๋ชจ๋ ์
๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update() word = word.strip() pronun = pronun.strip()1 unmodified line if len(word) == 1: error_msg = f"๐ซ [๋ฑ๋ก ์คํจ] '{word}'์ฒ๋ผ 1๊ธ์๋ง ๋ฑ๋กํ๋ฉด ์๋ณธ์ด ํผ์๋ฉ๋๋ค! 2๊ธ์ ์ด์์ผ๋ก ๋ฑ๋กํด์ฃผ์ธ์." if current_input and current_input.strip(): final_text, html_output, char_count = process_text(current_input, ai_mode, auto_break, smart_pause, font_size) return error_msg, final_text, html_output, char_count return error_msg, "", "", "์
๋ ฅ ๊ธ์ ์: 0์" final_text, html_output, char_count, marker_result = process_text(current_input, ai_mode, auto_break, smart_pause, font_size) return error_msg, final_text, html_output, char_count, marker_result return error_msg, "", "", "์
๋ ฅ ๊ธ์ ์: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." try: with open(dict_path, "r", encoding="utf-8") as f:18 unmodified lines status_msg = f"โ ์ ์ฅ ์คํจ: {e}"
if current_input and current_input.strip(): final_text, html_output, char_count = process_text(current_input, ai_mode, auto_break, smart_pause, font_size) return status_msg, final_text, html_output, char_count return status_msg, "", "", "์
๋ ฅ ๊ธ์ ์: 0์" final_text, html_output, char_count, marker_result = process_text(current_input, ai_mode, auto_break, smart_pause, font_size) return status_msg, final_text, html_output, char_count, marker_result return status_msg, "", "", "์
๋ ฅ ๊ธ์ ์: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
def load_current_json_to_text(): try:135 unmodified lines}"""
# โ
์
๋ ฅ์ฐฝ ์ปค์ ์์น์ @@ ์ฝ์
ํ๋ ์๋ฐ์คํฌ๋ฆฝํธ ํจ์insert_marker_js = """(current_text) => { let ta = document.querySelector('#input_text_area textarea');3 unmodified lines 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(); 14 unmodified lines 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)7 unmodified lines output_html = gr.HTML(value=initial_html, elem_id="prompter_html_wrap") with gr.Accordion("๐ ์์ ํ
์คํธ ๊ฒฐ๊ณผ (๋ณต์ฌ์ฉ) - ํด๋ฆญํด์ ํผ์น๊ธฐ", open=False): output_text = gr.Textbox(lines=8, show_label=False, show_copy_button=True, elem_id="output_text_area") # โ
์๋ก ์ถ๊ฐ๋ ๋ง์ปค ๋ชจ์๋ณด๊ธฐ ์ฐฝ! marker_collection = gr.Textbox(label="๐จ ์์ ํ์ ๋จ์ด ๋ชจ์๋ณด๊ธฐ (@@)", interactive=False, lines=2) gr.Markdown("---") gr.Markdown("**๐ก ๋๋ง์ ๋ฐ์ ์ฌ์ ์ถ๊ฐ** (โป 1๊ธ์ ๋จ์ด๋ ์๋ณธ ํผ์์ ๋ง๊ธฐ ์ํด ๋ฑ๋ก ๋ถ๊ฐํฉ๋๋ค!)")1 unmodified line 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) # ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ๋ค 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_insert_marker.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count, marker_collection], 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_conv.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) 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="(text) => { if(text) { navigator.clipboard.writeText(text); alert('โ
๋ณต์ฌ ์๋ฃ!'); } }", api_name=False) font_size.change(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count], api_name=False) ai_mode.change(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count], api_name=False) auto_break.change(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count], api_name=False) smart_pause.change(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_add.click(fn=add_and_update, inputs=[nw, np, input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[status, output_text, output_html, char_count], api_name=False) font_size.change(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) ai_mode.change(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) auto_break.change(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) smart_pause.change(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) btn_add.click(fn=add_and_update, inputs=[nw, np, input_text, ai_mode, auto_break, smart_pause, font_size], outputs=[status, output_text, output_html, char_count, marker_collection], api_name=False) btn_clear_dict_inputs.click(fn=lambda: ("", ""), outputs=[nw, np], api_name=False)
with gr.Tab("๐ฅ ์๋ ๋ฐฑ์
/์กฐํ/์์ (๋๋ ๋ฑ๋ก)"):app.py+33-29