Spaces:
Running
Running
Update app.py
Browse files20 unmodified lines21222324242526272829303117 unmodified lines49505149505253525354555455565758595859606113 unmodified lines7576777978798030 unmodified lines1111121131161171181191201141151161221231171181191201 unmodified line12212312413113212512612712811 unmodified lines14014114215015114315214414514614714814915916015015115215323 unmodified lines1771781791901911801811821941831841961971981991851861872012021881892042051901911921932091941952122132142151961972171981992202212002012022242252032042282052062302312322072082092102112122362372382392132142152412422162172182192201 unmodified line2222232242502512252262272532282292302562572582592602312322332342353 unmodified lines2392402412702422432442732742752762452462472782482492502512522832842532542552566 unmodified lines26326426529729826626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030131131231331431531631731831932032132232330230330430530630730830931031131231331431531631731831932032132532632732832932232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835933133233333433533633733833934034134234334434534634734834935035135235335435536036136236335735835936036136236336436536636736836937037137237336436536636736836937537637737837938037037137237337420 unmodified lines
dict_path = "custom_dict.json"
# ํ๊น
ํ์ด์ค Secrets์์ ์ด๋๋ฏผ ๋น๋ฐ๋ฒํธ ๊ฐ์ ธ์ค๊ธฐ (์์ผ๋ฉด admin1234)# ํ๊น
ํ์ด์ค Secrets์์ ์์ด๋/๋น๋ฐ๋ฒํธ ๊ฐ์ ธ์ค๊ธฐADMIN_ID = os.environ.get("ADMIN_ID", "admin")ADMIN_PW = os.environ.get("ADMIN_PW", "admin1234")GUEST_ID = os.environ.get("GUEST_ID", "guest")GUEST_PW = os.environ.get("GUEST_PW", "guest1234")
# ==========================================# โ
๊ธฐ์กด ์์ง 100% ์๋ณธ ์ ์ง17 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: json.dump({"items":[], "meta": {"count": 0}}, f) with open(dict_path, "w", encoding="utf-8") as f: json.dump({"items":[], "meta": {"count": 0}}, f) try: with open(dict_path, "r", encoding="utf-8") as f: existing_data = json.load(f) except: existing_data = {"items":[], "meta": {"count": 0}} 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 w in AUTO_MERGE_WORDS: dict_map[w[0]] = w[1] for w in AUTO_MERGE_WORDS: dict_map[w[0]] = w[1] merged_items = [[k, v] for k, v in dict_map.items()] existing_data["items"] = merged_items13 unmodified lines for item in data.get("items",[]): if len(item) == 2: flat_dict[item[0].strip()] = item[1].strip() except: pass if user_temp_dict: flat_dict.update(user_temp_dict) return flat_dict
30 unmodified lines try: n = int(num_str) except: return num_str if n == 0: return "์" digits = ["", "์ผ", "์ด", "์ผ", "์ฌ", "์ค", "์ก", "์น ", "ํ", "๊ตฌ"] units = ["", "์ญ", "๋ฐฑ", "์ฒ"] large_units = ["", "๋ง", "์ต", "์กฐ"] res = [] str_n = str(n)[::-1] digits, units, large_units = ["", "์ผ", "์ด", "์ผ", "์ฌ", "์ค", "์ก", "์น ", "ํ", "๊ตฌ"], ["", "์ญ", "๋ฐฑ", "์ฒ"], ["", "๋ง", "์ต", "์กฐ"] res, str_n = [], str(n)[::-1] for i in range(0, len(str_n), 4): chunk = str_n[i:i+4] chunk_res = [] chunk, chunk_res = str_n[i:i+4], [] for j, char in enumerate(chunk): d = int(char) if d > 0:1 unmodified line if d == 1 and j == 0 and len(chunk) == 1 and i == 0: word = "์ผ" chunk_res.append(word + units[j]) if chunk_res: res.append("".join(chunk_res[::-1]) + large_units[i//4]) final_str = "".join(res[::-1]) return final_str if final_str else num_str return "".join(res[::-1]) or num_str
def apply_smart_regex(text): if not text: return text11 unmodified lines return text
def process_text(input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict): if not input_text or not input_text.strip(): return "", f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ</div><div id="prompter_output_div" style="font-size:{font_size}px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." if not input_text or not input_text.strip(): return "", f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ</div><div id="prompter_output_div" style="font-size:{font_size}px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค." clean_text = input_text.replace('\r', '') char_count = f"๊ณต๋ฐฑ ํฌํจ: {len(clean_text)}์ / ๊ณต๋ฐฑ ์ ์ธ: {len(clean_text.replace(' ', '').replace(chr(10), ''))}์" text_for_processing = apply_smart_regex(input_text) flat_dict = load_dict(user_temp_dict) if not flat_dict: final_text = apply_g2p(text_for_processing, ai_mode) if not flat_dict: final_text = apply_g2p(text_for_processing, ai_mode) else: sorted_keys = sorted(flat_dict.keys(), key=len, reverse=True) pattern = re.compile("|".join(map(re.escape, sorted_keys)))23 unmodified lines unique_markers = list(dict.fromkeys([m.strip('.,!?\n') for m in markers if m.strip('.,!?\n')])) return final_text, html_output, char_count, " / ".join(unique_markers) if unique_markers else "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
def clear_all(): return "", "", '<div id="prompter_output_div" style="font-size:22px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."def clear_all(): return "", "", '<div id="prompter_output_div" style="font-size:22px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
# ==========================================# โ
์๋ฌ ์๋ ํ๋ฉด ๋ด ๋น๋ฐ๋ฒํธ ๊ฒ์ฆ ๋ก์ง# โ
์ฌ์ ๊ถํ ๋ถ๋ฆฌ ๋ก์ง (user_role ๋ณ์ ์ฌ์ฉ)# ==========================================def add_and_update(word, pronun, pw_input, current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict): if not word or not pronun: return "โ ๏ธ ๊ธฐ์กด ๋จ์ด์ ์ํ๋ ๋ฐ์์ ๋ชจ๋ ์
๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict def add_and_update(word, pronun, user_role, current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict): if not word or not pronun: return "โ ๏ธ ๋จ์ด์ ๋ฐ์์ ์
๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict word, pronun = word.strip(), pronun.strip() if len(word) == 1: return f"๐ซ [๋ฑ๋ก ์คํจ] 1๊ธ์๋ง ๋ฑ๋กํ๋ฉด ์๋ณธ์ด ํผ์๋ฉ๋๋ค!", gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict if len(word) == 1: return f"๐ซ [๋ฑ๋ก ์คํจ] 1๊ธ์๋ ๋ฑ๋กํ ์ ์์ต๋๋ค.", gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict # ๐ ๋น๋ฐ๋ฒํธ ์ผ์น (์ด๋๋ฏผ ์๊ตฌ ์ ์ฅ) if pw_input == ADMIN_PW: if user_role == "admin": try: with open(dict_path, "r", encoding="utf-8") as f: j_struct = json.load(f) except: j_struct = {"items":[], "meta": {"count": 0}} found = False for item in j_struct.get("items",[]): if item[0].strip() == word: item[1] = pronun found = True break if item[0].strip() == word: item[1] = pronun; found = True; break if not found: j_struct["items"].append([word, pronun]) try: j_struct["meta"]["count"] = len(j_struct["items"]) with open(dict_path, "w", encoding="utf-8") as f: json.dump(j_struct, f, ensure_ascii=False, indent=2) 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}" # ๐ค ๋น๋ฐ๋ฒํธ ๋ถ์ผ์น/๊ณต๋ฐฑ (๊ฒ์คํธ ์์ ์ ์ฅ) else: user_temp_dict[word] = pronun status_msg = f"๐ค [๊ฒ์คํธ] '{word}' -> '{pronun}' ์์ ์ ์ฅ ์๋ฃ! (๋น๋ฐ๋ฒํธ ์์/ํ๋ฆผ)" status_msg = f"๐ค [๊ฒ์คํธ] '{word}' -> '{pronun}' ์์ ์ ์ฅ ์๋ฃ! (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ)"
if current_input and current_input.strip(): final_text, html_output, char_count, marker_result = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict) return status_msg, final_text, html_output, char_count, marker_result, user_temp_dict if current_input.strip(): ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict) return status_msg, ft, ho, cc, mr, user_temp_dict return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict
def load_current_json_to_text(user_temp_dict): try: flat_dict = load_dict(user_temp_dict) return json.dumps({"items": flat_dict}, ensure_ascii=False, indent=4), "โ
ํ์ฌ ์ฌ์ ์ ๋ถ๋ฌ์์ต๋๋ค!" except Exception as e: return "", f"โ ๋ถ๋ฌ์ค๊ธฐ ์คํจ: {e}" try: return json.dumps({"items": load_dict(user_temp_dict)}, ensure_ascii=False, indent=4), "โ
์ฌ์ ์ ๋ถ๋ฌ์์ต๋๋ค!" except Exception as e: return "", f"โ ์คํจ: {e}"
def overwrite_json_text(json_string, pw_input): if pw_input != ADMIN_PW: return "๐ซ [๊ถํ ์์] ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ฆฝ๋๋ค. ์ด๋๋ฏผ๋ง ๋ฎ์ด์ฐ๊ธฐ๊ฐ ๊ฐ๋ฅํฉ๋๋ค."def overwrite_json_text(json_string, user_role): if user_role != "admin": return "๐ซ [๊ถํ ์์] ์ด๋๋ฏผ๋ง ๋ฎ์ด์ฐ๊ธฐ๊ฐ ๊ฐ๋ฅํฉ๋๋ค." if not json_string.strip(): return "โ ๏ธ ๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์." try: new_data = json.loads(json_string)1 unmodified line with open(dict_path, "w", encoding="utf-8") as f: json.dump({"items": new_items, "meta": {"count": len(new_items)}}, f, ensure_ascii=False, indent=2) perform_auto_recovery_and_merge() return f"๐ [์ด๋๋ฏผ ์๋ฃ] ์๋ฒ ์ฌ์ ์ ์๋ฒฝํ ๊ต์ฒดํ์ต๋๋ค!" except Exception as e: return f"โ JSON ํ์ฑ ์๋ฌ: {e}" return f"๐ [์ด๋๋ฏผ] ์๋ฒ ์ฌ์ ์ ์๋ฒฝํ ๊ต์ฒดํ์ต๋๋ค!" except Exception as e: return f"โ ์๋ฌ: {e}"
def apply_json_text(json_string, pw_input, user_temp_dict):def apply_json_text(json_string, user_role, user_temp_dict): if not json_string.strip(): return "โ ๏ธ ๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์.", user_temp_dict try: new_data = json.loads(json_string) items = new_data.get("items", {}) parsed_items = items if isinstance(items, dict) else {i[0].strip(): i[1].strip() for i in items if len(i)==2} if pw_input == ADMIN_PW: parsed_items = {i[0].strip(): i[1].strip() for i in json.loads(json_string).get("items", []) if len(i)==2} if isinstance(json.loads(json_string).get("items"), list) else json.loads(json_string).get("items", {}) if user_role == "admin": try: with open(dict_path, "r", encoding="utf-8") as f: existing_data = json.load(f) except: existing_data = {"items":[], "meta": {"count": 0}}3 unmodified lines with open(dict_path, "w", encoding="utf-8") as f: json.dump({"items": merged_items, "meta": {"count": len(merged_items)}}, f, ensure_ascii=False, indent=2) perform_auto_recovery_and_merge() return f"๐ [์ด๋๋ฏผ ์๋ฃ] ์๋ฒ์ ์๊ตฌ ์ถ๊ฐํ์ต๋๋ค!", user_temp_dict return f"๐ [์ด๋๋ฏผ] ์๋ฒ์ ์๊ตฌ ์ถ๊ฐํ์ต๋๋ค!", user_temp_dict else: user_temp_dict.update(parsed_items) return f"๐ค [๊ฒ์คํธ ์๋ฃ] ๋ธ๋ผ์ฐ์ ์์ ๋จ์ด์ฅ์ ์ถ๊ฐ๋์์ต๋๋ค!", user_temp_dict except Exception as e: return f"โ JSON ํ์ฑ ์๋ฌ: {e}", user_temp_dict
def get_file(): return dict_path if os.path.exists(dict_path) else None return f"๐ค [๊ฒ์คํธ] ์์ ๋จ์ด์ฅ์ ์ถ๊ฐ๋์์ต๋๋ค!", user_temp_dict except Exception as e: return f"โ ์๋ฌ: {e}", user_temp_dict
def upload_file(file_path, pw_input, user_temp_dict):def upload_file(file_path, user_role, user_temp_dict): if file_path is None: return "โ ๏ธ ํ์ผ์ด ์์ต๋๋ค.", user_temp_dict try: with open(file_path, "r", encoding="utf-8") as f: uploaded_data = json.load(f) parsed_items = {item[0].strip(): item[1].strip() for item in uploaded_data.get("items", []) if len(item) == 2} if pw_input == ADMIN_PW: if user_role == "admin": try: with open(dict_path, "r", encoding="utf-8") as f: existing_data = json.load(f) except: existing_data = {"items":[], "meta": {"count": 0}}6 unmodified lines return "๐ [์ด๋๋ฏผ] ํ์ผ ๋ฐ์ดํฐ๋ฅผ ์๋ฒ์ ์๊ตฌ ๋ณํฉํ์ต๋๋ค!", user_temp_dict else: user_temp_dict.update(parsed_items) return "๐ค [๊ฒ์คํธ] ๋ด ๋ธ๋ผ์ฐ์ ์์ ๋จ์ด์ฅ์ ๋ณํฉ๋์์ต๋๋ค!", user_temp_dict except Exception as e: return f"โ ํ์ผ ์ฒ๋ฆฌ ์คํจ: {e}", user_temp_dict return "๐ค [๊ฒ์คํธ] ๋ด ์์ ๋จ์ด์ฅ์ ๋ณํฉ๋์์ต๋๋ค!", user_temp_dict except Exception as e: return f"โ ์๋ฌ: {e}", user_temp_dict
# ==========================================# โ
๋ก๊ทธ์ธ ๊ฒ์ฆ ํจ์# ==========================================def verify_login(uid, upw): if uid == ADMIN_ID and upw == ADMIN_PW: return gr.update(visible=False), gr.update(visible=True), "admin", "โ
๋ก๊ทธ์ธ ์ฑ๊ณต (์ด๋๋ฏผ ๋ชจ๋)" elif uid == GUEST_ID and upw == GUEST_PW: return gr.update(visible=False), gr.update(visible=True), "guest", "โ
๋ก๊ทธ์ธ ์ฑ๊ณต (๊ฒ์คํธ ๋ชจ๋)" else: return gr.update(visible=True), gr.update(visible=False), "none", "โ ์์ด๋ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ต๋๋ค."
custom_css = """#prompter_html_wrap, #prompter_html_wrap .prose { width: 100% !important; text-align: left !important; }#input_text_area textarea, #output_text_area textarea, #prompter_output_div { font-family: sans-serif !important; height: 500px !important; overflow-y: auto !important; padding: 16px !important; line-height: 1.8 !important; }#prompter_output_div { background-color: #333 !important; color: #fff !important; border-radius: 8px !important; white-space: pre-wrap !important; }.login-box { max-width: 400px; margin: 100px auto; padding: 30px; border: 1px solid #ddd; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }"""script_js = "function(){ setTimeout(function(){ document.querySelector('#input_text_area textarea').style.fontSize='22px'; document.querySelector('#output_text_area textarea').style.fontSize='22px'; }, 500); }"insert_marker_js = "(t) => { let ta = document.querySelector('#input_text_area textarea'); if (!ta) return t; let s = ta.selectionStart, e = ta.selectionEnd, v = ta.value; ta.value = v.substring(0, s) + '@@' + v.substring(e); ta.dispatchEvent(new Event('input', { bubbles: true })); ta.selectionStart = ta.selectionEnd = s + 2; ta.focus(); return ta.value; }"
with gr.Blocks(theme="default", css=custom_css) as iface: user_role = gr.State("none") user_temp_dict = gr.State(lambda: {})
# 1. ๋ก๊ทธ์ธ ํ๋ฉด UI (์ฒ์์ ์ด๊ฒ๋ง ๋ณด์) with gr.Column(visible=True, elem_classes="login-box") as login_screen: gr.Markdown("### ๐ ์์คํ
๋ก๊ทธ์ธ") login_id = gr.Textbox(label="์์ด๋") login_pw = gr.Textbox(label="๋น๋ฐ๋ฒํธ", type="password") login_btn = gr.Button("๋ก๊ทธ์ธ", variant="primary") login_msg = gr.Markdown("")
# 2. ๋ฉ์ธ ์ฑ ํ๋ฉด UI (์ฒ์์ ์จ๊ฒจ์ง) gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ") with gr.Tabs(): with gr.Tab("๐๏ธ ๋ฉ์ธ ํ๋ฉด"): with gr.Row(): with gr.Column(): input_text = gr.Textbox(label="1๏ธโฃ ์๋ณธ ํ
์คํธ ์
๋ ฅ", elem_id="input_text_area") with gr.Group(): ai_mode = gr.Radio(choices=["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", "์ค๊ฐ ๋ง (๋ช
์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)", "์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ - ๊ณผ๋ํ ์ฐ์ ๋ฐฉ์ง)", "๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก - ์์ฐ์ค๋ฌ์ด ์ฐ์)"], value="์ค๊ฐ ๋ง (๋ช
์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)", label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋") auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋ ์๋ ์ค๋ฐ๊ฟ", value=False) smart_pause = gr.Checkbox(label="โฑ๏ธ ์ผํ ๋ค ํธํก์ ( / ) ์ถ๊ฐ", value=False) btn_insert_marker = gr.Button("๐จ ๋ง์ปค(@@) ์ฝ์
", variant="secondary", size="sm") font_size = gr.Slider(minimum=16, maximum=40, value=22, step=2, label="๐ ๊ธ์ ํฌ๊ธฐ") with gr.Column(visible=False) as main_app: gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ") with gr.Tabs(): with gr.Tab("๐๏ธ ๋ฉ์ธ ํ๋ฉด"): with gr.Row(): with gr.Column(): input_text = gr.Textbox(label="1๏ธโฃ ์๋ณธ ํ
์คํธ ์
๋ ฅ", elem_id="input_text_area") with gr.Group(): ai_mode = gr.Radio(choices=["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", "์ค๊ฐ ๋ง (๋ช
์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)", "์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ - ๊ณผ๋ํ ์ฐ์ ๋ฐฉ์ง)", "๋งค์ด ๋ง (๋ฌธ์ฅ ํต์งธ๋ก - ์์ฐ์ค๋ฌ์ด ์ฐ์)"], value="์ค๊ฐ ๋ง (๋ช
์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)", label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋") auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋ ์๋ ์ค๋ฐ๊ฟ", value=False) smart_pause = gr.Checkbox(label="โฑ๏ธ ์ผํ ๋ค ํธํก์ ( / ) ์ถ๊ฐ", value=False) btn_insert_marker = gr.Button("๐จ ๋ง์ปค(@@) ์ฝ์
", variant="secondary", size="sm") font_size = gr.Slider(minimum=16, maximum=40, value=22, step=2, label="๐ ๊ธ์ ํฌ๊ธฐ") char_count = gr.Textbox(label="๊ธ์ ์ ํ์ธ", value="๊ณต๋ฐฑ ํฌํจ: 0์", interactive=False) with gr.Row(): btn_conv = gr.Button("โจ ๋ณํํ๊ธฐ", variant="primary") btn_copy = gr.Button("๐ ๋ณต์ฌ", variant="secondary") btn_clr = gr.Button("๐๏ธ ์ด๊ธฐํ", variant="stop") char_count = gr.Textbox(label="๊ธ์ ์ ํ์ธ", value="๊ณต๋ฐฑ ํฌํจ: 0์", interactive=False) with gr.Row(): btn_conv = gr.Button("โจ ๋ณํํ๊ธฐ", variant="primary") btn_copy = gr.Button("๐ ๋ณต์ฌ", variant="secondary") btn_clr = gr.Button("๐๏ธ ์ด๊ธฐํ", variant="stop") with gr.Column(): output_html = gr.HTML(value='<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ</div><div id="prompter_output_div" style="font-size:22px;"></div>', elem_id="prompter_html_wrap") with gr.Accordion("๐ ํ
์คํธ ๊ฒฐ๊ณผ (ํด๋ฆญํ์ฌ ํผ์น๊ธฐ)", open=False): output_text = gr.Textbox(lines=8, show_label=False, show_copy_button=True, elem_id="output_text_area") marker_collection = gr.Textbox(label="๐จ ์์ ํ์ ๋จ์ด (@@)", interactive=False, lines=2) gr.Markdown("---") gr.Markdown("**๐ก ๋๋ง์ ๋ฐ์ ์ฌ์ ์ถ๊ฐ**") with gr.Row(): nw = gr.Textbox(label="๋จ์ด (2๊ธ์ ์ด์)") np = gr.Textbox(label="์ํ๋ ๋ฐ์") with gr.Column(): btn_add = gr.Button("๐พ ์ ์ฉ ๋ฐ ๋ณํ", variant="primary") btn_clear_dict_inputs = gr.Button("๐งน ์
๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary") status = gr.Textbox(label="์ ์ฅ ์ํ", interactive=False) btn_insert_marker.click(fn=None, inputs=[input_text], outputs=[input_text], js=insert_marker_js, api_name=False) btn_insert_marker.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) btn_conv.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) btn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count, marker_collection], api_name=False) btn_copy.click(fn=None, inputs=[output_text], outputs=None, js="(t) => { if(t) { navigator.clipboard.writeText(t); alert('โ
๋ณต์ฌ ์๋ฃ!'); } }", api_name=False) btn_add.click(fn=add_and_update, inputs=[nw, np, user_role, input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[status, output_text, output_html, char_count, marker_collection, user_temp_dict], api_name=False) btn_clear_dict_inputs.click(fn=lambda: ("", ""), outputs=[nw, np], api_name=False) for evt in [font_size.change, ai_mode.change, auto_break.change, smart_pause.change]: evt(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[output_text, output_html, char_count, marker_collection], 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("---") btn_load_json = gr.Button("๐ 2. ๋ฑ๋ก๋ ๋จ์ด์ฅ ๋ถ๋ฌ์ค๊ธฐ", variant="secondary") json_input = gr.Textbox(lines=10, label="ํธ์ง์ฐฝ") with gr.Row(): btn_apply_json = gr.Button("๐ ํ๋ฌ์ค(+) ํ๊ธฐ", variant="primary") btn_overwrite_json = gr.Button("๐จ ์์ ํ ๋ฎ์ด์ฐ๊ธฐ (์ด๋๋ฏผ ์ ์ฉ)", variant="stop") json_stat = gr.Textbox(label="์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) with gr.Column(): output_html = gr.HTML(value='<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ</div><div id="prompter_output_div" style="font-size:22px;"></div>', elem_id="prompter_html_wrap") with gr.Accordion("๐ ํ
์คํธ ๊ฒฐ๊ณผ (ํด๋ฆญํ์ฌ ํผ์น๊ธฐ)", open=False): output_text = gr.Textbox(lines=8, show_label=False, show_copy_button=True, elem_id="output_text_area") marker_collection = gr.Textbox(label="๐จ ์์ ํ์ ๋จ์ด (@@)", interactive=False, lines=2) gr.Markdown("---") gr.Markdown("**๐ก ๋๋ง์ ๋ฐ์ ์ฌ์ ์ถ๊ฐ**") with gr.Row(): nw = gr.Textbox(label="๋จ์ด (2๊ธ์ ์ด์)") np = gr.Textbox(label="์ํ๋ ๋ฐ์") admin_pw_input1 = gr.Textbox(label="๐ ๊ด๋ฆฌ์ ๋น๋ฐ๋ฒํธ (๊ฒ์คํธ๋ ๊ณต๋ฐฑ)", type="password") with gr.Column(): btn_add = gr.Button("๐พ ์ ์ฉ ๋ฐ ๋ณํ", variant="primary") btn_clear_dict_inputs = gr.Button("๐งน ์
๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary") status = gr.Textbox(label="์ ์ฅ ์ํ", interactive=False) btn_insert_marker.click(fn=None, inputs=[input_text], outputs=[input_text], js=insert_marker_js, api_name=False) btn_insert_marker.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) btn_conv.click(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) btn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count, marker_collection], api_name=False) btn_copy.click(fn=None, inputs=[output_text], outputs=None, js="(t) => { if(t) { navigator.clipboard.writeText(t); alert('โ
๋ณต์ฌ ์๋ฃ!'); } }", api_name=False) btn_add.click(fn=add_and_update, inputs=[nw, np, admin_pw_input1, input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[status, output_text, output_html, char_count, marker_collection, user_temp_dict], api_name=False) btn_clear_dict_inputs.click(fn=lambda: ("", ""), outputs=[nw, np], api_name=False) for evt in [font_size.change, ai_mode.change, auto_break.change, smart_pause.change]: evt(fn=process_text, inputs=[input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict], outputs=[output_text, output_html, char_count, marker_collection], api_name=False) btn_load_json.click(fn=load_current_json_to_text, inputs=[user_temp_dict], outputs=[json_input, json_stat], api_name=False) btn_apply_json.click(fn=apply_json_text, inputs=[json_input, user_role, user_temp_dict], outputs=[json_stat, user_temp_dict], api_name=False) btn_overwrite_json.click(fn=overwrite_json_text, inputs=[json_input, user_role], outputs=[json_stat], 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("---") btn_load_json = gr.Button("๐ 2. ๋ฑ๋ก๋ ๋จ์ด์ฅ ๋ถ๋ฌ์ค๊ธฐ", variant="secondary") json_input = gr.Textbox(lines=10, label="ํธ์ง์ฐฝ") admin_pw_input2 = gr.Textbox(label="๐ ๊ด๋ฆฌ์ ๋น๋ฐ๋ฒํธ (๊ฒ์คํธ๋ ๊ณต๋ฐฑ)", type="password") with gr.Row(): btn_apply_json = gr.Button("๐ ํ๋ฌ์ค(+) ํ๊ธฐ", variant="primary") btn_overwrite_json = gr.Button("๐จ ์์ ํ ๋ฎ์ด์ฐ๊ธฐ (์ด๋๋ฏผ ์ ์ฉ)", variant="stop") json_stat = gr.Textbox(label="์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) btn_load_json.click(fn=load_current_json_to_text, inputs=[user_temp_dict], outputs=[json_input, json_stat], api_name=False) btn_apply_json.click(fn=apply_json_text, inputs=[json_input, admin_pw_input2, user_temp_dict], outputs=[json_stat, user_temp_dict], api_name=False) btn_overwrite_json.click(fn=overwrite_json_text, inputs=[json_input, admin_pw_input2], outputs=[json_stat], api_name=False) gr.Markdown("---") with gr.Accordion("๐ค 3. ๋ฐฑ์
ํ์ผ๋ก ์ฌ์ ์ ๋ณํฉํ๊ธฐ", open=False): up_file = gr.File(label="๋ฐฑ์
ํ์ผ ์
๋ก๋", type="filepath") up_stat = gr.Textbox(label="์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) up_file.upload(fn=upload_file, inputs=[up_file, user_role, user_temp_dict], outputs=[up_stat, user_temp_dict], api_name=False)
gr.Markdown("---") with gr.Accordion("๐ค 3. ๋ฐฑ์
ํ์ผ๋ก ์ฌ์ ์ ๋ณํฉํ๊ธฐ", open=False): admin_pw_input3 = gr.Textbox(label="๐ ๊ด๋ฆฌ์ ๋น๋ฐ๋ฒํธ (๊ฒ์คํธ๋ ๊ณต๋ฐฑ)", type="password") up_file = gr.File(label="๋ฐฑ์
ํ์ผ ์
๋ก๋", type="filepath") up_stat = gr.Textbox(label="์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False) up_file.upload(fn=upload_file, inputs=[up_file, admin_pw_input3, user_temp_dict], outputs=[up_stat, user_temp_dict], api_name=False) # ๋ก๊ทธ์ธ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ (ํ๋ฉด ์ ํ) login_btn.click(fn=verify_login, inputs=[login_id, login_pw], outputs=[login_screen, main_app, user_role, login_msg], api_name=False)
iface.load(None, js=script_js)
app.py+130-139