Spaces:
Running
Running
Update app.py
Browse files29 unmodified lines303132333334353648 unmodified lines8586878888899069 unmodified lines1601611621641631641654 unmodified lines17017117217517617317417573 unmodified lines24925025125625225325415 unmodified lines2702712722782792732742756 unmodified lines28228328429228528628734 unmodified lines32232332433332532632717 unmodified lines34534634735734834935098 unmodified lines44945045146246345245345445545635 unmodified lines49249349450549549649739 unmodified lines53753853955154054154254354455654529 unmodified linesGUEST_PW = os.environ.get("GUEST_PW", "guest1234")
# ==========================================# โ
๊ธฐ์กด ์์ง 100% ์๋ณธ ์ ์ง (๊ฑด๋๋ฆฌ์ง ์์)# โ
๊ธฐ์กด ์์ง 100% ์๋ณธ ์ ์ง# ==========================================AUTO_MERGE_WORDS = [ ["GS๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"],["GS ๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"],["GS์ต", "์ง์์ค์ต"],["GS ์ต", "์ง์์ค์ต"],48 unmodified lines except: pass # โ
๊ฒ์คํธ์ ์์ ๋จ์ด์ฅ์ด ์๋ค๋ฉด ์๋ณธ ์ฌ์ ์ ๋ฎ์ด์์์ ์ ์ฉ (์๋ณธ ํ์ผ์ ๊ฑด๋๋ฆฌ์ง ์์) if user_temp_dict: flat_dict.update(user_temp_dict) 69 unmodified lines text = re.sub(r'(\d+)\s*(mm|cm|m|km|g|kg|ml|L)\b', lambda m: f"{number_to_korean(m.group(1))} {unit_dict[m.group(2).lower() if m.group(2).lower() != 'l' else 'L']}", text, flags=re.IGNORECASE) return text
# โ
ํ
์คํธ ์ฒ๋ฆฌ ์ user_temp_dict ์ธ์ ์ถ๊ฐdef process_text(input_text, ai_mode, auto_break, smart_pause, 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์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."4 unmodified lines char_count = f"๊ณต๋ฐฑ ํฌํจ: {len_with_spaces}์ / ๊ณต๋ฐฑ ์ ์ธ: {len_without_spaces}์" text_for_processing = apply_smart_regex(input_text) # ์๋ฒ ์ฌ์ + ๊ฐ์ธ ์์ ์ฌ์ ๋ณํฉํด์ ๋ถ๋ฌ์ค๊ธฐ flat_dict = load_dict(user_temp_dict) if not flat_dict:73 unmodified lines return error_msg, final_text, html_output, char_count, marker_result, user_temp_dict return error_msg, "", f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div><div id="prompter_output_div" style="font-size:{font_size}px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค.", user_temp_dict # ๐ ๊ด๋ฆฌ์ ๋ก๊ทธ์ธ ์: ์๋ฒ ํ์ผ์ ์๊ตฌ ์ ์ฅ if username == ADMIN_ID: try: with open(dict_path, "r", encoding="utf-8") as f: j_struct = json.load(f)15 unmodified lines status_msg = f"๐ [์ด๋๋ฏผ] '{word}' -> '{pronun}' ์๋ฒ ์๊ตฌ ์ ์ฅ ์๋ฃ!" except Exception as e: status_msg = f"โ ์ ์ฅ ์คํจ: {e}" # ๐ค ๊ฒ์คํธ ๋ก๊ทธ์ธ ์: ๋ธ๋ผ์ฐ์ ์ ์์ ์ ์ฅ else: user_temp_dict[word] = pronun status_msg = f"๐ค [๊ฒ์คํธ] '{word}' -> '{pronun}' ์์ ์ ์ฅ ์๋ฃ! (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ)"6 unmodified lines
def load_current_json_to_text(user_temp_dict): try: # ์๋ฒ ์ฌ์ + ๊ฐ์ธ ์ฌ์ ์ ๋ชจ๋ ๋ณด์ฌ์ค flat_dict = load_dict(user_temp_dict) pretty_json = json.dumps({"items": flat_dict}, ensure_ascii=False, indent=4) return pretty_json, "โ
ํ์ฌ ์ฌ์ ์ ์ฑ๊ณต์ ์ผ๋ก ๋ถ๋ฌ์์ต๋๋ค!"34 unmodified lines new_data = json.loads(json_string) if "items" not in new_data: return "โ ๏ธ ์ฌ๋ฐ๋ฅธ ์ฌ์ ํ์์ด ์๋๋๋ค.", user_temp_dict # ์ด๋๋ฏผ: ์๋ฒ์ ์ ์ฅ if username == ADMIN_ID: try: with open(dict_path, "r", encoding="utf-8") as f: existing_data = json.load(f)17 unmodified lines perform_auto_recovery_and_merge() return f"๐ [์ด๋๋ฏผ ์๋ฃ] ๊ธฐ์กด ๋จ์ด๋ฅผ ์ ์งํ๋ฉฐ ์๋ฒ์ ์๊ตฌ ์ถ๊ฐํ์ต๋๋ค!", user_temp_dict # ๊ฒ์คํธ: ์์ ์ฌ์ ์๋ง ์ถ๊ฐ else: if isinstance(new_data["items"], dict): for k, v in new_data["items"].items(): user_temp_dict[k.strip()] = v.strip()98 unmodified lines
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; 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: # ๊ฐ์ธ ์์ ์ฌ์ ์ ์ฅ์ ์ํ State (๊ฒ์คํธ์ฉ)# โ
์ฌ๊ธฐ์ ssr=False๋ฅผ ๋ฃ์ด์ผ ์๋ฌ๊ฐ ๋์ง ์์ต๋๋ค!with gr.Blocks(theme="default", css=custom_css, ssr=False) as iface: user_temp_dict = gr.State(lambda: {})
gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ (ํ๋กฌํํฐ ๋ชจ๋)")35 unmodified lines btn_clear_dict_inputs = gr.Button("๐งน ๋จ์ด ์
๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary") status = gr.Textbox(label="์ ์ฅ ์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) # ๋ชจ๋ ํ
์คํธ ์ฒ๋ฆฌ ์ด๋ฒคํธ์ user_temp_dict ์ฐ๋ 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, user_temp_dict], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) 39 unmodified lines iface.load(None, js=script_js)
if __name__ == "__main__": # โ
๋ก๊ทธ์ธ ๊ถํ ์ค์ ๋ฐ ์๋ฌ ๋ฐฉ์ง์ฉ ์๋ฒ ์ค์ ์ ์ฉ auth_list = [ (ADMIN_ID, ADMIN_PW), (GUEST_ID, GUEST_PW) ] # launch์๋ ๊น๋ํ๊ฒ auth๋ง ์ ๋ฌํฉ๋๋ค. iface.launch(auth=auth_list, server_name="0.0.0.0") iface.launch(auth=auth_list)app.py+5-16