Spaces:
Running
Running
Update app.py
Browse files2 unmodified lines345678910111213141516179181920218 unmodified lines30313224333435361 unmodified line383940414233434445464748495037515253545539565758597 unmodified lines6768695370717273577475767722 unmodified lines100101102861031041051063 unmodified lines110111112961131149811511611711827 unmodified lines1461471481321331491501511521538 unmodified lines1621631641481651661671682 unmodified linesimport osimport difflibimport shutilfrom g2pk import G2p
# 1. G2P μλ λ°μ λ³ν AI λ€μ μμ νκ² λ‘λ©print("G2P λͺ¨λΈ λ‘λ© μ€...")try: g2p = G2p()except Exception as e: print(f"G2P λ‘λ© μ€ν¨: {e}") g2p = None
dict_path = "custom_dict.json"
# 1. μ¬μ λ‘λ©# 2. μ¬μ λ‘λ©def load_dict(): flat_dict = {} if os.path.exists(dict_path):8 unmodified lines pass return flat_dict
# 2. ν
μ€νΈ λ³ν λ° νκ΄ν μ²λ¦¬# 3. ν
μ€νΈ λ³ν (μ¬μ μ μ© ν -> G2P μλ λ³ν -> νκ΄ν)def process_text(input_text): if not input_text or not input_text.strip(): return "", "", "μ
λ ₯ κΈμ μ: 0μ"1 unmodified line char_count = f"μ
λ ₯ κΈμ μ: {len(input_text)}μ (곡백 ν¬ν¨)" processed = input_text # 1λ¨κ³: μ¬μ©μκ° λ±λ‘ν μ¬μ λ¨μ΄/λ¬Έμ₯ λ¨Όμ μΉν flat_dict = load_dict() # μ¬μ μ λ±λ‘λ λ¨μ΄/λ¬Έμ₯μ μ°Ύμ μΉν for word, pronun in flat_dict.items(): processed = processed.replace(word, pronun) # 2λ¨κ³: G2P μΈκ³΅μ§λ₯ μλ λ³ν μ μ© (볡ꡬλ¨!) if g2p is not None: try: final_text = g2p(processed) except Exception as e: final_text = processed final_text = processed print(f"G2P λ³ν μλ¬: {e}") else: final_text = processed
# νκ΄ν ν¨κ³Ό (λ³κ²½λ λΆλΆλ§ λ
Έλμ μ²λ¦¬) # 3λ¨κ³: νκ΄ν ν¨κ³Ό (λ³κ²½λ λΆλΆλ§ λ
Έλμ μ²λ¦¬) seq = difflib.SequenceMatcher(None, input_text, final_text) html_parts =[] for tag, i1, i2, j1, j2 in seq.get_opcodes():7 unmodified lines return final_text, html_output, char_count
# 3. μ΄κΈ°ν# 4. μ΄κΈ°νdef clear_all(): return "", "", "", "μ
λ ₯ κΈμ μ: 0μ"
# 4. λ¨μ΄/λ¬Έμ₯ μ¬μ μΆκ°# 5. λ¨μ΄/λ¬Έμ₯ μ¬μ μΆκ°def add_dict(word, pronun): if not word or not pronun: return "β οΈ κΈ°μ‘΄ λ¨μ΄μ μνλ λ°μμ λͺ¨λ μ
λ ₯νμΈμ."22 unmodified lines except Exception as e: return f"β μ μ₯ μ€ν¨: {e}"
# 5. λ°±μ
λ° λ³΅κ΅¬# 6. λ°±μ
λ° λ³΅κ΅¬def get_file(): return dict_path if os.path.exists(dict_path) else None
3 unmodified lines return "β
λ°±μ
νμΌ λ³΅κ΅¬ μλ£! μ΄μ μ¬μ μ΄ μ μ μ μ©λ©λλ€." return "β οΈ νμΌμ΄ μμ΅λλ€."
# 6. UI νλ©΄ ꡬμ±# UI νλ©΄ ꡬμ±with gr.Blocks(theme="default") as iface: gr.Markdown("## ποΈ λλ§μ TTS μ μ²λ¦¬ λ³νκΈ° (PRO λ²μ )") gr.Markdown("## ποΈ λλ§μ TTS μ μ²λ¦¬ λ³νκΈ° (PRO μμ±λ³Έ)") with gr.Tabs(): # --- 첫 λ²μ§Έ ν: λ©μΈ μμ
---27 unmodified lines gr.Markdown("---") gr.Markdown("### π οΈ μ¬μ μ λ¨μ΄/λ¬Έμ₯ μ¦μ λ±λ‘") with gr.Row(): nw = gr.Textbox(label="κΈ°μ‘΄ λ¨μ΄ λλ λ¬Έμ₯ (μ: μ±μ§νΌν° λͺ¨λΈμ)", scale=1) np = gr.Textbox(label="μνλ λ°μ (μ: μ±μ°νΌν° λͺ¨λΈμ)", scale=1) nw = gr.Textbox(label="κΈ°μ‘΄ λ¨μ΄ λλ λ¬Έμ₯", scale=1) np = gr.Textbox(label="μνλ λ°μ", scale=1) btn_add = gr.Button("πΎ μ¬μ μ μΆκ°", variant="primary", scale=1) status = gr.Textbox(label="μ μ₯ μν κ²°κ³Όμ°½", interactive=False) btn_add.click(fn=add_dict, inputs=[nw, np], outputs=[status])8 unmodified lines gr.Markdown("---") gr.Markdown("### 2. λ°±μ
νμΌ λ³΅κ΅¬νκΈ° (μ
λ‘λ)") gr.Markdown("μλ²κ° 리μ€ννΈ λμ΄ μ¬μ μ΄ μ΄κΈ°νλμλ€λ©΄, λ€μ΄λ‘λ ν΄λμλ `custom_dict.json` νμΌμ μλμ λλκ·Έ μ€ λλ‘ νμΈμ.") gr.Markdown("μλ²κ° 리μ€ννΈ λμ΄ μ¬μ μ΄ μ΄κΈ°νλμλ€λ©΄, λ€μ΄λ‘λ ν΄λμλ `custom_dict.json` νμΌμ μλμ μ
λ‘λ νμΈμ.") up_file = gr.File(label="λ°±μ
νμΌ μ
λ‘λ") up_stat = gr.Textbox(label="볡ꡬ μν κ²°κ³Όμ°½", interactive=False) up_file.upload(fn=upload_file, inputs=[up_file], outputs=[up_stat])app.py+30-13