Spaces:
Running
Running
Update app.py
Browse files79 unmodified lines8081828383848586878889908591929332 unmodified lines1261271281241251291301311321301331341351341361371381395 unmodified lines1451461471461481491501517 unmodified lines15916016116016216316416520 unmodified lines18618718818718919019119227 unmodified lines220221222221223224225226142 unmodified lines3693703713703723733743755 unmodified lines38138238338238438538679 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์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." # โ
์ ํํ ๊ธ์ ์ ๊ณ์ฐ ๋ก์ง clean_text = input_text.replace('\r', '') len_with_spaces = len(clean_text) len_without_spaces = len(clean_text.replace(' ', '').replace('\n', '')) char_count = f"๊ณต๋ฐฑ ํฌํจ: {len_with_spaces}์ / ๊ณต๋ฐฑ ์ ์ธ: {len_without_spaces}์" char_count = f"์
๋ ฅ ๊ธ์ ์: {len(input_text)}์" flat_dict = load_dict() if not flat_dict:32 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<]*@@[^\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'[^\s]*@@[^\s]*', input_text) unique_markers =[] for m in markers: clean_m = m.strip('.,!?\n') # ๋์ ๋ถ์ ์ผํ๋ ๋ง์นจํ๋ ์ ๊ฑฐํด์ ๊น๋ํ๊ฒ ํ์ clean_m = m.strip('.,!?\n') if clean_m and clean_m not in unique_markers: unique_markers.append(clean_m) 5 unmodified lines return final_text, html_output, char_count, marker_result
def clear_all(): return "", "", "", "์
๋ ฅ ๊ธ์ ์: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." return "", "", "", "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
def add_and_update(word, pronun, current_input, ai_mode, auto_break, smart_pause, font_size): if not word or not pronun:7 unmodified lines if current_input and current_input.strip(): 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์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." return error_msg, "", "", "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." try: with open(dict_path, "r", encoding="utf-8") as f:20 unmodified lines if current_input and current_input.strip(): 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์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." return status_msg, "", "", "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
def load_current_json_to_text(): try:27 unmodified lines with open(dict_path, "w", encoding="utf-8") as f: json.dump(final_data, f, ensure_ascii=False, indent=2) return f"๐จ [๋ฎ์ด์ฐ๊ธฐ ์๋ฃ] ์์ ํ ๋ด์ฉ({len(new_items)}๊ฐ)์ผ๋ก ์ฌ์ ์ ์๋ฒฝํ ๊ต์ฒดํ์ต๋๋ค!" return f"๐จ[๋ฎ์ด์ฐ๊ธฐ ์๋ฃ] ์์ ํ ๋ด์ฉ({len(new_items)}๊ฐ)์ผ๋ก ์ฌ์ ์ ์๋ฒฝํ ๊ต์ฒดํ์ต๋๋ค!" except Exception as e: return f"โ JSON ํ์ฑ ์๋ฌ (๋ฐ์ดํ๋ ์ผํ๊ฐ ๋น ์ก๋์ง ํ์ธํ์ธ์): {e}"
142 unmodified lines 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) char_count = gr.Textbox(label="๊ธ์ ์ ํ์ธ", value="๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", interactive=False) with gr.Row(): btn_conv = gr.Button("โจ ๋ณํํ๊ธฐ", variant="primary") btn_copy = gr.Button("๐ ๋ณํ๋ณต์ฌ", variant="secondary")5 unmodified lines 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("---")app.py+13-12