Spaces:
Running
Running
Update app.py
Browse files150 unmodified lines15115215315415415515615715815916016116216316416516616716816917017117217317415817517617717823 unmodified lines2022032041882052062077 unmodified lines215216217202218219220221222223209224225226227228229230231232233234235236237214215238239240241242150 unmodified linesdef upload_file(file_path): if file_path is not None: shutil.copy(file_path, dict_path) return "โ
์๋ ๋ฐฑ์
๋ณต๊ตฌ ์๋ฃ!" return "โ
ํ์ผ ๋ณต๊ตฌ ์๋ฃ!" return "โ ๏ธ ํ์ผ์ด ์์ต๋๋ค."
# โ
์๋ก ์ถ๊ฐ๋ ๋ถ์ฌ๋ฃ๊ธฐ ์ ์ฉ ํจ์ โ
def apply_json_text(json_string): if not json_string or not json_string.strip(): return "โ ๏ธ ๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์." try: # ํ
์คํธ๊ฐ ์ ์์ ์ธ JSON์ธ์ง ํ์ธ data = json.loads(json_string) if "items" not in data: return "โ ๏ธ ์ฌ๋ฐ๋ฅธ ์ฌ์ ํ์์ด ์๋๋๋ค. ('items' ํค๊ฐ ์์ต๋๋ค)" # ์ ์์ ์ด๋ฉด ํ์ผ๋ก ์ ์ฅ with open(dict_path, "w", encoding="utf-8") as f: json.dump(data, f, ensure_ascii=False, indent=2) return "โ
๋ณต์ฌ/๋ถ์ฌ๋ฃ๊ธฐ๋ก ๋๋ ๋จ์ด ์ฌ์ ์ ์ฉ ์๋ฃ!" except Exception as e: return f"โ JSON ํ์ฑ ์๋ฌ (๊ดํธ๋ ์ผํ๊ฐ ๋น ์ก๋์ง ํ์ธํด์ฃผ์ธ์): {e}"
with gr.Blocks(theme="default") as iface: gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ (์ค๋งํธ ๋ถ์ผ์น ๊ฐ์งํ)") gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ") with gr.Tabs(): with gr.Tab("๐๏ธ ๋ฉ์ธ ํ๋ฉด"):23 unmodified lines nw = gr.Textbox(label="๊ธฐ์กด ๋จ์ด ๋๋ ๋ฌธ์ฅ (โ
๋ฐ๋์ 1๋ฒ ์ฐฝ์์ ๋ณต์ฌํด์ค์ธ์โ
)") np = gr.Textbox(label="์ํ๋ ๋ฐ์") # ๋ฒํผ ๋ ๊ฐ๋ฅผ ์์๋๋ก ๊น๋ํ๊ฒ ๋ฐฐ์น with gr.Column(min_width=200): btn_add = gr.Button("๐พ ์ฌ์ ์ ์ถ๊ฐํ๊ณ ์ฆ์ ๋๋ณธ ๋ณํํ๊ธฐ", variant="primary") btn_clear_dict_inputs = gr.Button("๐งน ๋จ์ด ์
๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary")7 unmodified lines api_name=False ) # โ
์๋ก ์ถ๊ฐ๋ ๋์: ์ค์ง ๋จ์ด ์
๋ ฅ์นธ 2๊ฐ๋ง ๊น๋ํ๊ฒ ๋น์์ค! โ
btn_clear_dict_inputs.click( fn=lambda: ("", ""), outputs=[nw, np], api_name=False )
with gr.Tab("๐ฅ ์๋ ๋ฐฑ์
/๋ณต๊ตฌ"): with gr.Tab("๐ฅ ์๋ ๋ฐฑ์
/๋ณต๊ตฌ (๋๋ ๋ฑ๋ก)"): dl_btn = gr.DownloadButton("๐ฅ 1. ํ์ฌ ์์ฑ๋ ์ฌ์ ๋ฐฑ์
ํ๊ธฐ (PC ๋ค์ด๋ก๋)") dl_btn.click(fn=get_file, outputs=[dl_btn], api_name=False) gr.Markdown("---") gr.Markdown("### ๐ 2. ์ฝ๋๋ฅผ ๋ณต์ฌํด์ ์ง์ ๋ถ์ฌ๋ฃ๊ธฐ (์ถ์ฒ)") json_input = gr.Textbox(lines=10, label="์ฌ๊ธฐ์ JSON ์ฝ๋๋ฅผ ๋ถ์ฌ๋ฃ์ผ์ธ์") btn_apply_json = gr.Button("๐ ๋ถ์ฌ๋ฃ์ ์ฝ๋๋ก ์ฌ์ ๋ฎ์ด์ฐ๊ธฐ", variant="primary") json_stat = gr.Textbox(label="๋ณต๊ตฌ ์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) btn_apply_json.click(fn=apply_json_text, inputs=[json_input], outputs=[json_stat], api_name=False)
gr.Markdown("---") gr.Markdown("### ๐ค 3. ํ์ผ๋ก ์
๋ก๋ํ๊ธฐ (๊ธฐ์กด ๋ฐฉ์)") up_file = gr.File(label="๐ค 2. ๋ฐฑ์
ํ์ผ ๋ณต๊ตฌํ๊ธฐ (์
๋ก๋)", type="filepath") up_stat = gr.Textbox(label="๋ณต๊ตฌ ์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) up_file = gr.File(label="๋ฐฑ์
ํ์ผ ๋ณต๊ตฌํ๊ธฐ (์
๋ก๋)", type="filepath") up_stat = gr.Textbox(label="ํ์ผ ๋ณต๊ตฌ ์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) up_file.upload(fn=upload_file, inputs=[up_file], outputs=[up_stat], api_name=False)
if __name__ == "__main__":app.py+31-7