Spaces:
Running
Running
Update app.py
Browse files33 unmodified lines34353637373839404115 unmodified lines5758596061626344 unmodified lines1081091101091111121131141151161171181191201211222 unmodified lines1251261271221281291301313 unmodified lines13513613713213313813914014113714214314414510 unmodified lines15615715815415916016116222 unmodified lines1851861871831881891901911881921931941 unmodified line19619719819619719920020120233 unmodified lines data = json.load(f) for item in data.get("items",[]): if len(item) == 2: flat_dict[item[0]] = item[1] # 무쑰건 μμ 곡백μ μ κ±°νμ¬ λ‘λ© flat_dict[item[0].strip()] = item[1].strip() except: pass return flat_dict15 unmodified lines pass else: 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 lines found = False for item in j_struct.get("items",[]): if item[0] == word: if item[0].strip() == word: item[1] = pronun found = True break3 unmodified lines try: 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}' μ μ₯ μλ£ λ° μ¦μ μ¬λ³ν μ μ©!" 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 lines return "β οΈ νμΌμ΄ μμ΅λλ€."
with gr.Blocks(theme="default") as iface: gr.Markdown("## ποΈ λλ§μ TTS μ μ²λ¦¬ λ³νκΈ° (μ¦μ μ μ© μλ²½ μμ λ³Έ)") gr.Markdown("## ποΈ λλ§μ TTS μ μ²λ¦¬ λ³νκΈ° (곡백/μ€λ₯ μλ²½ 보μ ν)") with gr.Tabs(): with gr.Tab("ποΈ λ©μΈ νλ©΄"):22 unmodified lines with 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 line api_name=False )
with gr.Tab("π₯ μλ λ°±μ
/볡ꡬ (λΉμμ©)"): gr.Markdown("π‘ μλ²κ° μμ ν μ λ€μ΄μ μ΄κΈ°νλμμ λλ§ μ¬μ©νλ μλ λ°±μ
νμ
λλ€.") 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