Spaces:
Running
Running
Update app.py
Browse files3 unmodified lines456778929 unmodified lines39404143444546474849505152535455565758596061624243444560 unmodified lines10610710812910911011113211211311411513 unmodified lines12913013115215315415513213313413513613713813914010 unmodified lines15115215317515415515615720 unmodified lines1781791802021811821832041841851861872081881891901911921931942152162172181951961972211981992002013 unmodified linesimport difflibimport shutilimport refrom huggingface_hub import HfApi
try: from g2pk import G2p29 unmodified lines pass return flat_dict
# ν΄λΌμ°λ μλ λ°±μ
ν¨μ (λ²νΌ λλ₯Ό λλ§ μλ)def backup_to_space(): space_id = os.environ.get("SPACE_ID") hf_token = os.environ.get("HF_TOKEN") if space_id and hf_token: try: api = HfApi() api.upload_file( path_or_fileobj=dict_path, path_in_repo=dict_path, repo_id=space_id, repo_type="space", token=hf_token ) return "βοΈ ν΄λΌμ°λ μꡬ μ μ₯ μλ£! (β» μ μ ν μλ²κ° λ°±μ
μ μν΄ μλμΌλ‘ μλ‘κ³ μΉ¨ λ μ μμ΅λλ€)" except Exception as e: return f"β λ°±μ
μ€ν¨: {e}" return "β οΈ HF_TOKENμ΄ μ€μ λμ§ μμ ν΄λΌμ°λ μ μ₯μ ν μ μμ΅λλ€."
# λ³ν ν΅μ¬ λ‘μ§ (μλ³Έμ 보νΈνλ©° λ±λ‘λ λ¨μ΄λ§ μ νν μΉν)def process_text(input_text): if not input_text or not input_text.strip(): return "", "", "μ
λ ₯ κΈμ μ: 0μ"60 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() return "β οΈ κΈ°μ‘΄ λ¨μ΄μ μνλ λ°μμ λͺ¨λ μ
λ ₯νμΈμ.", gr.update(), gr.update(), gr.update() try: with open(dict_path, "r", encoding="utf-8") as f:13 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("ποΈ λ©μΈ νλ©΄"):20 unmodified lines gr.Markdown("---") with gr.Row(): nw = gr.Textbox(label="κΈ°μ‘΄ λ¨μ΄ λλ λ¬Έμ₯") nw = gr.Textbox(label="κΈ°μ‘΄ λ¨μ΄ λλ λ¬Έμ₯ (μλ³Έμ μλ κΈμ)") np = gr.Textbox(label="μνλ λ°μ") # νΌλμ μ£Όλ λ²νΌλ€ μΉ λ€ μμ κ³ μ΄ λ²νΌ νλλ‘ ν΅μΌνμ΅λλ€! btn_add = gr.Button("πΎ μ¬μ μ μΆκ° (λλ³Έ μ μ§λ¨)", variant="primary") btn_add = gr.Button("πΎ μ¬μ μ μΆκ°νκ³ μ¦μ λλ³Έ λ³ννκΈ°", variant="primary") status = gr.Textbox(label="μ μ₯ μν κ²°κ³Όμ°½", interactive=False) # λ¨μ΄ μΆκ° μ μ¬μμ μμ΄ νλ©΄λ§ κ°±μ # μ΄ λ²νΌ νλλ§ λλ₯΄λ©΄ μλ³Έ μ μ§ + λ¨μ΄ μ μ₯ + μ¦μ κ²°κ³Όμ°½ μ¬λ³νμ΄ νλ°©μ μΌμ΄λ©λλ€. btn_add.click( fn=add_and_update, inputs=[nw, np, input_text], outputs=[status, output_text, output_html, char_count], api_name=False ) gr.Markdown("---") btn_sync = gr.Button("βοΈ μμ
μ΄ λλλ©΄ μ¬κΈ°λ₯Ό λλ¬ ν΄λΌμ°λμ μꡬ λ°±μ
νμΈμ (μλ² μλ‘κ³ μΉ¨ λ¨)") btn_sync.click(fn=backup_to_space, outputs=[status], api_name=False)
with gr.Tab("π₯ μλ λ°±μ
/볡ꡬ (λΉμμ©)"): gr.Markdown("π‘ μλ²κ° μμ ν μ λ€μ΄μ μ΄κΈ°νλμμ λλ§ μ¬μ©νλ μλ λ°±μ
νμ
λλ€.") dl_btn = gr.DownloadButton("π₯ 1. νμ¬ μ¬μ λ°±μ
νκΈ° (PC λ€μ΄λ‘λ)") dl_btn = gr.DownloadButton("π₯ 1. νμ¬ μμ±λ μ¬μ λ°±μ
νκΈ° (PC λ€μ΄λ‘λ)") dl_btn.click(fn=get_file, outputs=[dl_btn], api_name=False) gr.Markdown("---")app.py+13-36