Spaces:
Running
Running
Update app.py
Browse files33 unmodified lines3435363738394015 unmodified lines56575859606144 unmodified lines1061071081091101111121131141151162 unmodified lines1191201211221231241253 unmodified lines12913013113213313413513613713813914010 unmodified lines15115215315415515615722 unmodified lines1801811821831841851861871881891901911 unmodified line19319419519619719819920033 unmodified linesdata = json.load(f)for item in data.get("items",[]):if len(item) == 2:flat_dict[item[0]] = item[1]except:passreturn flat_dict15 unmodified linespasselse:sorted_keys = sorted(flat_dict.keys(), key=len, reverse=True)pattern = re.compile("|".join(map(re.escape, sorted_keys)))parts =[]44 unmodified linesdef clear_all():return "", "", "", "μ λ ₯ κΈμ μ: 0μ"# [ν΅μ¬] λ¨μ΄ μΆκ°μ λμμ ν μ€νΈλ₯Ό μ¦μ μ¬λ³ννλ μλ²½ν μ¬μΈμ ν¨μdef add_and_update(word, pronun, current_input):if not word or not pronun:return "β οΈ κΈ°μ‘΄ λ¨μ΄μ μνλ λ°μμ λͺ¨λ μ λ ₯νμΈμ.", gr.update(), gr.update(), gr.update()try:with open(dict_path, "r", encoding="utf-8") as f:j_struct = json.load(f)2 unmodified linesfound = Falsefor item in j_struct.get("items",[]):if item[0] == word:item[1] = pronunfound = Truebreak3 unmodified linestry:with open(dict_path, "w", encoding="utf-8") as f:json.dump(j_struct, f, ensure_ascii=False, indent=2)# μλ² μ¬μμ λ‘μ§ μμ μμ , μ€μ§ μ μ₯λ§ μνstatus_msg = f"β '{word}' -> '{pronun}' μ μ₯ μλ£ λ° μ¦μ μ¬λ³ν μ μ©!"except Exception as e:status_msg = f"β μ μ₯ μ€ν¨: {e}"# μ¦μ νλ©΄ κ°±μ (μλ³Έ λλ³Έ current_inputμ κ·Έλλ‘ μ½μ΄μμ μ¬λ³ν)if current_input and current_input.strip():final_text, html_output, char_count = process_text(current_input)return status_msg, final_text, html_output, char_count10 unmodified linesreturn "β οΈ νμΌμ΄ μμ΅λλ€."with gr.Blocks(theme="default") as iface:gr.Markdown("## ποΈ λλ§μ TTS μ μ²λ¦¬ λ³νκΈ° (μ¦μ μ μ© μλ²½ μμ λ³Έ)")with gr.Tabs():with gr.Tab("ποΈ λ©μΈ νλ©΄"):22 unmodified lineswith gr.Row():nw = gr.Textbox(label="κΈ°μ‘΄ λ¨μ΄ λλ λ¬Έμ₯ (μλ³Έμ μλ κΈμ)")np = gr.Textbox(label="μνλ λ°μ")# νΌλμ μ£Όλ λ²νΌλ€ μΉ λ€ μμ κ³ μ΄ λ²νΌ νλλ‘ ν΅μΌνμ΅λλ€!btn_add = gr.Button("πΎ μ¬μ μ μΆκ°νκ³ μ¦μ λλ³Έ λ³ννκΈ°", variant="primary")status = gr.Textbox(label="μ μ₯ μν κ²°κ³Όμ°½", interactive=False)# μ΄ λ²νΌ νλλ§ λλ₯΄λ©΄ μλ³Έ μ μ§ + λ¨μ΄ μ μ₯ + μ¦μ κ²°κ³Όμ°½ μ¬λ³νμ΄ νλ°©μ μΌμ΄λ©λλ€.btn_add.click(fn=add_and_update,inputs=[nw, np, input_text],1 unmodified lineapi_name=False)with gr.Tab("π₯ μλ λ°±μ /볡ꡬ (λΉμμ©)"):gr.Markdown("π‘ μλ²κ° μμ ν μ λ€μ΄μ μ΄κΈ°νλμμ λλ§ μ¬μ©νλ μλ λ°±μ νμ λλ€.")dl_btn = gr.DownloadButton("π₯ 1. νμ¬ μμ±λ μ¬μ λ°±μ νκΈ° (PC λ€μ΄λ‘λ)")dl_btn.click(fn=get_file, outputs=[dl_btn], api_name=False)33 unmodified lines343536373839404115 unmodified lines5758596061626344 unmodified lines1081091101111121131141151161171181191201211222 unmodified lines1251261271281291301313 unmodified lines13513613713813914014114214314414510 unmodified lines15615715815916016116222 unmodified lines1851861871881891901911921931941 unmodified line19619719819920020120233 unmodified linesdata = json.load(f)for item in data.get("items",[]):if len(item) == 2:# 무쑰건 μμ 곡백μ μ κ±°νμ¬ λ‘λ©flat_dict[item[0].strip()] = item[1].strip()except:passreturn flat_dict15 unmodified linespasselse:sorted_keys = sorted(flat_dict.keys(), key=len, reverse=True)# λμ΄μ°κΈ°κ° μ¬λ¬ κ° λ€μ΄κ° κ²½μ°λ λ°©μ΄pattern = re.compile("|".join(map(re.escape, sorted_keys)))parts =[]44 unmodified linesdef clear_all():return "", "", "", "μ λ ₯ κΈμ μ: 0μ"# [ν΅μ¬] λ¨μ΄ μΆκ°μ λμμ ν μ€νΈλ₯Ό μ¦μ μ¬λ³νdef add_and_update(word, pronun, current_input):if not word or not pronun:return "β οΈ κΈ°μ‘΄ λ¨μ΄μ μνλ λ°μμ λͺ¨λ μ λ ₯νμΈμ.", gr.update(), gr.update(), gr.update()# μ€μλ‘ λ€μ΄κ° 곡백 μλ²½ μ κ±°word = word.strip()pronun = pronun.strip()try:with open(dict_path, "r", encoding="utf-8") as f:j_struct = json.load(f)2 unmodified linesfound = Falsefor item in j_struct.get("items",[]):if item[0].strip() == word:item[1] = pronunfound = Truebreak3 unmodified linestry:with open(dict_path, "w", encoding="utf-8") as f:json.dump(j_struct, f, ensure_ascii=False, indent=2)status_msg = f"β '{word}' -> '{pronun}' μ μ₯ λ° μ¦μ μ¬λ³ν μ μ© μλ£!"except Exception as e:status_msg = f"β μ μ₯ μ€ν¨: {e}"# μ¦μ νλ©΄ κ°±μif current_input and current_input.strip():final_text, html_output, char_count = process_text(current_input)return status_msg, final_text, html_output, char_count10 unmodified linesreturn "β οΈ νμΌμ΄ μμ΅λλ€."with gr.Blocks(theme="default") as iface:gr.Markdown("## ποΈ λλ§μ TTS μ μ²λ¦¬ λ³νκΈ° (곡백/μ€λ₯ μλ²½ 보μ ν)")with gr.Tabs():with gr.Tab("ποΈ λ©μΈ νλ©΄"):22 unmodified lineswith gr.Row():nw = gr.Textbox(label="κΈ°μ‘΄ λ¨μ΄ λλ λ¬Έμ₯ (μλ³Έμ μλ κΈμ)")np = gr.Textbox(label="μνλ λ°μ")btn_add = gr.Button("πΎ μ¬μ μ μΆκ°νκ³ μ¦μ λλ³Έ λ³ννκΈ°", variant="primary")status = gr.Textbox(label="μ μ₯ μν κ²°κ³Όμ°½", interactive=False)btn_add.click(fn=add_and_update,inputs=[nw, np, input_text],1 unmodified lineapi_name=False)with gr.Tab("π₯ μλ λ°±μ /볡ꡬ"):dl_btn = gr.DownloadButton("π₯ 1. νμ¬ μμ±λ μ¬μ λ°±μ νκΈ° (PC λ€μ΄λ‘λ)")dl_btn.click(fn=get_file, outputs=[dl_btn], api_name=False)
app.py+13-11