Spaces:
Running
Running
Update app.py
Browse files3 unmodified lines4567891029 unmodified lines404142434445464748495051525354555657585960616263646560 unmodified lines12612712812913013113213313413513 unmodified lines14915015115215315415515615715815916016110 unmodified lines17217317417517617717820 unmodified lines1992002012022032042052062072082092102112122132142152162172182192202212222232243 unmodified linesimport difflibimport shutilimport refrom huggingface_hub import HfApitry:from g2pk import G2p29 unmodified linespassreturn 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()try:with open(dict_path, "r", encoding="utf-8") as f:13 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("ποΈ λ©μΈ νλ©΄"):20 unmodified linesgr.Markdown("---")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],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("π₯ μλ λ°±μ /볡ꡬ (λΉμμ©)"):dl_btn = gr.DownloadButton("π₯ 1. νμ¬ μ¬μ λ°±μ νκΈ° (PC λ€μ΄λ‘λ)")dl_btn.click(fn=get_file, outputs=[dl_btn], api_name=False)gr.Markdown("---")3 unmodified lines45678929 unmodified lines3940414243444560 unmodified lines10610710810911011111211311411513 unmodified lines12913013113213313413513613713813914010 unmodified lines15115215315415515615720 unmodified lines1781791801811821831841851861871881891901911921931941951961971981992002013 unmodified linesimport difflibimport shutilimport retry:from g2pk import G2p29 unmodified linespassreturn flat_dict# λ³ν ν΅μ¬ λ‘μ§ (μλ³Έμ 보νΈνλ©° λ±λ‘λ λ¨μ΄λ§ μ νν μΉν)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()try:with open(dict_path, "r", encoding="utf-8") as f:13 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("ποΈ λ©μΈ νλ©΄"):20 unmodified linesgr.Markdown("---")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],outputs=[status, output_text, output_html, char_count],api_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)gr.Markdown("---")
app.py+13-36