Spaces:
Running
Running
Update app.py
Browse files44 unmodified lines45464748495051313 unmodified lines36536636736836937037137237337437537690 unmodified lines46746846947047147247368 unmodified lines54254354454554654754854955055144 unmodified lines["๋ฐฐ์ก", "๋ฐฐ์ก"], ["ํ ์ธ", "ํ ์ธ"], ["์ด๋ฒคํธ", "์ด๋ฒคํธ"]]# ์๋ณธ์ ์์ ํ ์ฌ์ ๋ณต๊ตฌ ํจ์ ๊ทธ๋๋ก ์ ์ง!def perform_auto_recovery_and_merge():if not os.path.exists(dict_path):with open(dict_path, "w", encoding="utf-8") as f:313 unmodified linesdef get_file():return dict_path if os.path.exists(dict_path) else Nonedef upload_file(file_path):if file_path is not None:shutil.copy(file_path, dict_path)perform_auto_recovery_and_merge()return "โ ํ์ผ ๋ณต๊ตฌ ์๋ฃ!"return "โ ๏ธ ํ์ผ์ด ์์ต๋๋ค."custom_css = """#prompter_html_wrap { width: 100% !important; max-width: 100% !important; margin: 0 !important; padding: 0 !important; }90 unmodified linesinput_text = gr.Textbox(label="1๏ธโฃ ์๋ณธ ํ ์คํธ ์ ๋ ฅ", elem_id="input_text_area")with gr.Group():gr.Markdown("**โ๏ธ ๋ณํ ๋ฐ ํ๋ฉด ์ค์ **")# โ 3. UI 4๋จ๊ณ๋ก ๋ณ๊ฒฝ (๊ธฐ์กด ๋ก์ง 100% ์ ์ง)ai_mode = gr.Radio(choices=["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)",68 unmodified linesbtn_overwrite_json.click(fn=overwrite_json_text, inputs=[json_input], outputs=[json_stat], api_name=False)gr.Markdown("---")gr.Markdown("### ๐ค 3. ๋ฐฑ์ ํ์ผ๋ก ๋ฎ์ด์ฐ๊ธฐ (โป ์ฃผ์: ๊ธฐ์กด ๋จ์ด ์ด๊ธฐํ๋จ)")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)iface.load(None, js=script_js)44 unmodified lines45464748495051313 unmodified lines36536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440590 unmodified lines49649749849950050168 unmodified lines57057157257357457557657757857958058144 unmodified lines["๋ฐฐ์ก", "๋ฐฐ์ก"], ["ํ ์ธ", "ํ ์ธ"], ["์ด๋ฒคํธ", "์ด๋ฒคํธ"]]# ์๋ณธ์ ์์ ํ ์ฌ์ ๋ณต๊ตฌ ํจ์ ๊ทธ๋๋ก ์ ์งdef perform_auto_recovery_and_merge():if not os.path.exists(dict_path):with open(dict_path, "w", encoding="utf-8") as f:313 unmodified linesdef get_file():return dict_path if os.path.exists(dict_path) else None# ==========================================# โ 3. ๋ฐฑ์ ํ์ผ ์ ๋ก๋ ์ ๊ธฐ์กด ๋ฐ์ดํฐ ๋ณดํธ (์์ ๋ณํฉ)# ==========================================def upload_file(file_path):if file_path is None: return "โ ๏ธ ํ์ผ์ด ์์ต๋๋ค."try:# ์ ๋ก๋๋ ํ์ผ ์ฝ๊ธฐwith open(file_path, "r", encoding="utf-8") as f:uploaded_data = json.load(f)# ๊ธฐ์กด ์ฌ์ ์ฝ๊ธฐtry:with open(dict_path, "r", encoding="utf-8") as f:existing_data = json.load(f)except:existing_data = {"items":[], "meta": {"count": 0}}# ๋ฐ์ดํฐ ๋ณํฉ (๊ธฐ์กด ๋จ์ด ์ด๋ฆฌ๊ณ ์ถ๊ฐ)dict_map = {item[0].strip(): item[1].strip() for item in existing_data.get("items",[]) if len(item) == 2}for item in uploaded_data.get("items", []):if len(item) == 2:dict_map[item[0].strip()] = item[1].strip()merged_items = [[k, v] for k, v in dict_map.items()]existing_data["items"] = merged_itemsexisting_data["meta"]["count"] = len(merged_items)with open(dict_path, "w", encoding="utf-8") as f:json.dump(existing_data, f, ensure_ascii=False, indent=2)perform_auto_recovery_and_merge()return "โ ๊ธฐ์กด ๋จ์ด๋ฅผ ๋ณดํธํ๋ฉฐ ํ์ผ ๋ฐ์ดํฐ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ(๋ณํฉ)ํ์ต๋๋ค!"except Exception as e:return f"โ ํ์ผ ์ฒ๋ฆฌ ์คํจ (์ฌ๋ฐ๋ฅธ ๋ฐฑ์ ํ์ผ์ธ์ง ํ์ธํ์ธ์): {e}"custom_css = """#prompter_html_wrap { width: 100% !important; max-width: 100% !important; margin: 0 !important; padding: 0 !important; }90 unmodified linesinput_text = gr.Textbox(label="1๏ธโฃ ์๋ณธ ํ ์คํธ ์ ๋ ฅ", elem_id="input_text_area")with gr.Group():gr.Markdown("**โ๏ธ ๋ณํ ๋ฐ ํ๋ฉด ์ค์ **")ai_mode = gr.Radio(choices=["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)",68 unmodified linesbtn_overwrite_json.click(fn=overwrite_json_text, inputs=[json_input], outputs=[json_stat], api_name=False)gr.Markdown("---")# โ ์ค์ ํด๋ฆญ ๋ฐฉ์ง๋ฅผ ์ํด ์์ฝ๋์ธ(์ ๊ธฐ/ํผ์น๊ธฐ)์ผ๋ก ์์ ํ๊ฒ ์จ๊น ์ฒ๋ฆฌ!with gr.Accordion("๐ค 3. ๋ฐฑ์ ํ์ผ๋ก ๊ธฐ์กด ์ฌ์ ์ ์ถ๊ฐํ๊ธฐ (์์ ๋ณํฉ)", open=False):gr.Markdown("โป ์ ๋ก๋ํ ํ์ผ์ ๋จ์ด๋ค์ด ๊ธฐ์กด ์ฌ์ ์ ์ถ๊ฐ๋ฉ๋๋ค. (๊ธฐ์กด ๋จ์ด๋ ์ญ์ ๋์ง ์๊ณ ์์ ํ๊ฒ ๋ณดํธ๋ฉ๋๋ค)")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)iface.load(None, js=script_js)
app.py+40-10