Spaces:
Running
Running
Update app.py
Browse files187 unmodified lines18818919019119219310 unmodified lines20420520620720820913 unmodified lines2232242252262272282294 unmodified lines2342352362372382392408 unmodified lines24925025125225325425527 unmodified lines2832842852862872882892902912922932942952962972982993003013023033043053063073083093107 unmodified lines318319320321322323187 unmodified linesreturn ft, f'<div id="prompter_output_div" style="font-size:{font_size}px;">{rh}</div>', build_count_text(input_text, ft), extract_markers(input_text), input_text, ftexcept Exception as e: return input_text, f'<div id="prompter_output_div">์ค๋ฅ: {e}</div>', "์ค๋ฅ", "์ค๋ฅ", input_text, input_textdef validate_word(w):w = (w or "").strip()return (False, "๋จ์ด ์ ๋ ฅ ์๋ง") if not w else (False, "1๊ธ์ ๋ถ๊ฐ") if len(w)==1 else (False, "๋ฒ์ฉ๋จ์ด ๋ถ๊ฐ") if w in BLOCK_WORDS else (True, "")10 unmodified linesdef app_json(j): dict_store.save_pairs([[k, v] for i in json.loads(j)["items"] for k, v in (i.items() if isinstance(json.loads(j)["items"], dict) else [i])], True); return "ํ๋ฌ์ค ์๋ฃ!"def over_json(j): dict_store.save_pairs([[k, v] for i in json.loads(j)["items"] for k, v in (i.items() if isinstance(json.loads(j)["items"], dict) else [i])], False); return "๋ฎ์ด์ฐ๊ธฐ ์๋ฃ!"# =========================================================# CSS / JS# =========================================================13 unmodified linesgr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ")# ---------------------------------------------------------# 1. ์ปค์คํ ๋ก๊ทธ์ธ ํ๋ฉด (์๋ฌ ๋ฐฉ์ง 100%)# ---------------------------------------------------------with gr.Column(visible=True) as login_view:gr.Markdown("### ๐ ์ฌ์ฉ์ ์ํด ๋ก๊ทธ์ธํด ์ฃผ์ธ์.")4 unmodified lineslogin_msg = gr.Textbox(label="์๋ฆผ", interactive=False)# ---------------------------------------------------------# 2. ๋ฉ์ธ ์ฑ ํ๋ฉด (๋ก๊ทธ์ธ ์ฑ๊ณต ์ ๋ณด์)# ---------------------------------------------------------with gr.Column(visible=False) as main_view:last_o, last_f = gr.State(""), gr.State("")8 unmodified linesbtn_mk = gr.Button("๐จ ๋ง์ปค(@@) ์ฝ์ ", size="sm")fs = gr.Slider(16, 40, 22, step=2, label="๐ ๊ธ์ ํฌ๊ธฐ")# ๊ด๋ฆฌ์ ์ ์ฉ ์์ฝ๋์ธ (๊ธฐ๋ณธ ์จ๊น)with gr.Accordion("โ๏ธ ๊ด๋ฆฌ์ ์ ์ฉ ๊ณ ๊ธ ์ค์ ", open=False, visible=False) as admin_acc:ai_m = gr.Radio(["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", "์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ)", "๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก)"], value="๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", label="๐ค AI ๊ฐ๋")27 unmodified lineswith gr.Tab("๐ฅ ๋ฐฑ์ /์กฐํ"):dl_btn = gr.DownloadButton("๐ฅ ๋ฐฑ์ ํ๊ธฐ")dl_btn.click(get_file, None, dl_btn)json_in, j_stat = gr.Textbox(lines=10, label="๋ฐ์ดํฐ"), gr.Textbox(label="์ํ")with gr.Row():btn_ld, btn_ap, btn_ov = gr.Button("๐ ๋ถ๋ฌ์ค๊ธฐ"), gr.Button("๐ ํ๋ฌ์ค"), gr.Button("๐จ ๋ฎ์ด์ฐ๊ธฐ")btn_ld.click(load_json, None, [json_in, j_stat])btn_ap.click(app_json, json_in, j_stat)btn_ov.click(over_json, json_in, j_stat)# ---------------------------------------------------------# 3. ๋ก๊ทธ์ธ ์ฒ๋ฆฌ ๋ก์ง# ---------------------------------------------------------def check_login(user_id, user_pw):# 1. ํ๊น ํ์ด์ค ์ํฌ๋ฆฟ์์ ๋น๋ฐ๋ฒํธ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐsecret_str = os.getenv("AUTH_USERS")users_dict = {"a": "1", "User1": "1111"} # ๊ธฐ๋ณธ๊ฐif secret_str:try: users_dict = json.loads(secret_str)except: pass# 2. ๋น๋ฒ ํ์ธif users_dict.get(user_id) == user_pw:# ์ฑ๊ณต! (๋ง์ฝ ์์ด๋๊ฐ a ๋ผ๋ฉด ๊ด๋ฆฌ์ ๋ฉ๋ด ๋ณด์ฌ์ฃผ๊ธฐ)is_admin = (user_id == "a")return gr.update(visible=False), gr.update(visible=True), "โ ๋ก๊ทธ์ธ ์ฑ๊ณต!", gr.update(visible=is_admin)else:7 unmodified linesiface.load(None, js=js_sync)# ํด ์คํ (Gradio ๊ธฐ๋ณธ auth ๊ธฐ๋ฅ์ ๊บผ๋ - ์๋ฌ ์์ ์ฐจ๋จ)if __name__ == "__main__":iface.launch()187 unmodified lines18818919019119219319419519610 unmodified lines20720820921021121221321421521621721821922022122222322422513 unmodified lines2392402412422432442454 unmodified lines2502512522532542552568 unmodified lines26526626726826927027 unmodified lines2982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283297 unmodified lines337338339340341187 unmodified linesreturn ft, f'<div id="prompter_output_div" style="font-size:{font_size}px;">{rh}</div>', build_count_text(input_text, ft), extract_markers(input_text), input_text, ftexcept Exception as e: return input_text, f'<div id="prompter_output_div">์ค๋ฅ: {e}</div>', "์ค๋ฅ", "์ค๋ฅ", input_text, input_text# =========================================================# ์ฌ์ ๊ด๋ฆฌ API (๋๋ฝ๋์๋ ํจ์ ํฌํจ ๋ณต๊ตฌ ์๋ฃ!)# =========================================================def validate_word(w):w = (w or "").strip()return (False, "๋จ์ด ์ ๋ ฅ ์๋ง") if not w else (False, "1๊ธ์ ๋ถ๊ฐ") if len(w)==1 else (False, "๋ฒ์ฉ๋จ์ด ๋ถ๊ฐ") if w in BLOCK_WORDS else (True, "")10 unmodified linesdef app_json(j): dict_store.save_pairs([[k, v] for i in json.loads(j)["items"] for k, v in (i.items() if isinstance(json.loads(j)["items"], dict) else [i])], True); return "ํ๋ฌ์ค ์๋ฃ!"def over_json(j): dict_store.save_pairs([[k, v] for i in json.loads(j)["items"] for k, v in (i.items() if isinstance(json.loads(j)["items"], dict) else [i])], False); return "๋ฎ์ด์ฐ๊ธฐ ์๋ฃ!"# โ ๋๋ฝ๋์๋ 2๊ฐ์ง ํต์ฌ ํจ์ ๋ณต๊ตฌdef get_file():return dict_path if os.path.exists(dict_path) else Nonedef upload_file(file_path):try:with open(file_path, "r", encoding="utf-8") as f:data = json.load(f)dict_store.save_pairs([[k, v] for i in data["items"] for k, v in (i.items() if isinstance(data["items"], dict) else [i])], False)return "โ ํ์ผ ๋ณต๊ตฌ ์๋ฃ!"except Exception as e:return f"โ ํ์ผ ๋ณต๊ตฌ ์คํจ: {e}"# =========================================================# CSS / JS# =========================================================13 unmodified linesgr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ")# ---------------------------------------------------------# 1. ์ปค์คํ ๋ก๊ทธ์ธ ํ๋ฉด# ---------------------------------------------------------with gr.Column(visible=True) as login_view:gr.Markdown("### ๐ ์ฌ์ฉ์ ์ํด ๋ก๊ทธ์ธํด ์ฃผ์ธ์.")4 unmodified lineslogin_msg = gr.Textbox(label="์๋ฆผ", interactive=False)# ---------------------------------------------------------# 2. ๋ฉ์ธ ์ฑ ํ๋ฉด# ---------------------------------------------------------with gr.Column(visible=False) as main_view:last_o, last_f = gr.State(""), gr.State("")8 unmodified linesbtn_mk = gr.Button("๐จ ๋ง์ปค(@@) ์ฝ์ ", size="sm")fs = gr.Slider(16, 40, 22, step=2, label="๐ ๊ธ์ ํฌ๊ธฐ")with gr.Accordion("โ๏ธ ๊ด๋ฆฌ์ ์ ์ฉ ๊ณ ๊ธ ์ค์ ", open=False, visible=False) as admin_acc:ai_m = gr.Radio(["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", "์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ)", "๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก)"], value="๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", label="๐ค AI ๊ฐ๋")27 unmodified lineswith gr.Tab("๐ฅ ๋ฐฑ์ /์กฐํ"):dl_btn = gr.DownloadButton("๐ฅ ๋ฐฑ์ ํ๊ธฐ")dl_btn.click(get_file, None, dl_btn)json_in, j_stat = gr.Textbox(lines=10, label="๋ฐ์ดํฐ"), gr.Textbox(label="์ํ")with gr.Row():btn_ld, btn_ap, btn_ov = gr.Button("๐ ๋ถ๋ฌ์ค๊ธฐ"), gr.Button("๐ ํ๋ฌ์ค"), gr.Button("๐จ ๋ฎ์ด์ฐ๊ธฐ")btn_ld.click(load_json, None, [json_in, j_stat])btn_ap.click(app_json, json_in, j_stat)btn_ov.click(over_json, json_in, j_stat)# โ ๋๋ฝ๋์๋ ์ ๋ก๋ UI ๋ณต๊ตฌup_file = gr.File(label="๋ฐฑ์ ํ์ผ ์ ๋ก๋")up_stat = gr.Textbox(label="์ํ")up_file.upload(upload_file, up_file, up_stat)# ---------------------------------------------------------# 3. ๋ก๊ทธ์ธ ์ฒ๋ฆฌ ๋ก์ง# ---------------------------------------------------------def check_login(user_id, user_pw):secret_str = os.getenv("AUTH_USERS")users_dict = {"a": "1", "User1": "1111"}if secret_str:try: users_dict = json.loads(secret_str)except: passif users_dict.get(user_id) == user_pw:is_admin = (user_id == "a")return gr.update(visible=False), gr.update(visible=True), "โ ๋ก๊ทธ์ธ ์ฑ๊ณต!", gr.update(visible=is_admin)else:7 unmodified linesiface.load(None, js=js_sync)if __name__ == "__main__":iface.launch()
app.py+26-8