Spaces:
Running
Running
Update app.py
Browse files22 unmodified lines23242526262728293031323334353637383940413031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430522 unmodified linesdict_path = "custom_dict.json"
# =====================================================================# โ
AI๊ฐ ์ง ๊ธฐ์ ์ ์๋ ๋ณต๊ตฌ & ๋ณํฉ ๋ก์ง (์ฌ์ฉ์๋ ์๋ฌด๊ฒ๋ ์ ํด๋ ๋จ) โ
# โ
AI๊ฐ ์ง ๊ธฐ์ ์ ์๋ ๋ณต๊ตฌ & ๋ณํฉ ๋ก์ง โ
# =====================================================================AUTO_MERGE_WORDS = [["GS๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"], ["์ง์์ค ๋ง์ด์ต", "์ง์์ค ๋ง์ด์ต"],["1+1", "์ํ๋ฌ์ค์"], ["2+1", "ํฌํ๋ฌ์ค์"],["F/W", "์ํ ๋๋ธ์ "], ["S/S", "์์ค ์์ค"],["VIP", "๋ธ์ด์์ดํผ"], ["ํ ์ธ๊ฐ", "ํ๋ฆฐ๊น"], ["ํน๊ฐ", "ํน๊น"],["์ต์ ๊ฐ", "์ต์ ๊น"], ["๋จ๋
๊ตฌ์ฑ", "๋จ๋
๊พธ์ฑ"],["์ญ๋๊ธ", "์ญ๋๋"], ["์ฑ๊ฒฐ์ ", "์ฑ๊ปผ์ "],["์ผ์๋ถ", "์ผ์จ๋ถ"], ["๋ฌด์ด์", "๋ฌด์ด์"],["๋งค์ง์๋ฐ", "๋งค์ง๋๋ฐ"], ["์๋์ฃผ๋ฌธ", "์๋์ฃผ๋ฌธ"],["์ฌ์ํ", "์ฌ์ํ"], ["ํ๋ฆฌํฐ๋ฅผ", "ํ๋ฆฌํฐ๋ฅผ"],["๋ํ
์ผ์ด", "๋ํ
์ด๋ฆฌ"], ["์ค๋ฃจ์ฃ์ด", "์ค๋ฃจ์์"],["์ปคํฐ์ค๋ฒ
", "์ปคํฐ์ค๋ฒ
"], ["์ธ๋ฅด์ฆ๋ธ๋์ฝ", "์ธ๋ฅด์ฆ๋ธ๋์ฝ"],["ํฌ๋จธํฐ๋ธ", "ํฌ๋จธํฐ๋ธ"], ["๋นํธ๋ฆด", "๋นํธ๋ฆด"],["๋ ๋ฏธ์ค๋ฅด๋ฃจ", "๋ ๋ฏธ์ค๋ฅด๋ฃจ"], ["์ญ๋ํด๋ผ์ฐ์ค", "์๋ํด๋ผ์ฐ์ค"],["ํธ๋ง๊ณจํ", "ํธ๋ง๊ณจํ"], ["์ปฌ๋ผ๋น์", "์ปฌ๋ผ๋น์"],["์์ค๊น๋ค์คํฌ์ธ ", "์์ค๊น๋ค์คํฌ์ธ "],["์์ค์นด๋ค์คํฌ์ธ ", "์์ค๊น๋ค์คํฌ์ธ "], ["์์ธ", "์์ธ"],["์๋ํ๋", "์๋ํ๋"], ["๋ผ์์ํ", "๋ผ์์ํ"], ["๋ชจ๋ฅด๊ฐ", "๋ชจ๋ฅด๊ฐ"], ["๋ง์ค์คํ๋์ค", "๋ง์ฐ์คํ๋์ค"], ["๋ฐ์ผ๋ฆฌ๋ธ๋ฃจ", "๋ฐ์ผ๋ฆฌ๋ธ๋ฃจ"],["ํธ๋ผ์ด์ํ", "ํธ๋ผ์ด์ํ"],["์์จ๋น ํด๋กํด๋ฝ", "์์จ๋น ํด๋กํด๋ฝ"], ["๊ธฐํ ", "๊ธฐํ "],["์ค๋ก ๋", "์ค๋ก ๋"], ["SJ์๋", "์์ค์ ์ด์๋"],["์ฝ์ด ์ด์ผํฑ", "์ฝ์ด ์ด์ผํฑ"], ["๋ฅด๋คํฌ๋ฃจ", "๋ฅด๋คํฌ๋ฃจ"],["๋ํ", "๋ํ"], ["1์ข
", "์ผ์ข
"], ["2์ข
", "์ด์ข
"],["3์ข
", "์ผ์ข
"], ["4์ข
", "์ฌ์ข
"], ["5์ข
", "์ค์ข
"],["10์ข
", "์ญ์ข
"], ["4in1", "ํฌ์ธ์"],["25FW", "์ด์ค ์ํ ๋๋ธ์ "],["25 F/W", "์ด์ค ์ํ ๋๋ธ์ "], ["์ด์ค ์ํ๋ ๋ธ์ ", "์ด์ค ์ํ ๋๋ธ์ "],["26SS", "์ด์ญ๋ต์์ค์์ค"],["2026 SS", "์ด์ฒ์ด์ญ๋ต ์์ค์์ค"], ["SS์์ฆ", "์์ค์์ค ์์ฆ"],["์
์
", "์ธ๋ฅ"], ["๋ฆฌ๋ฒ์๋ธ", "๋ฆฌ๋ฒ์๋ธ"], ["๋งจํฌ๋งจ", "๋งจํฌ๋งจ"], ["์ํฐํฌ์ธ ", "์ํฐํฌ์ธ "],["๋ณธ๋ฉํฌ์ธ ", "๋ณธ๋ฉํฌ์ธ "], ["์ค์์์ผ", "์ค์์์ผ"],["ํ์ด๋ธ๋ฆฌ๋", "ํ์ด๋ธ๋ฆฌ๋"], ["๋ ์ด์ด๋ง", "๋ ์ด์ด๋ง"], ["๋ ์ด์ด๋", "๋ ์ด์ด๋"], ["์์นด๋ผ", "์์นด๋ผ"], ["์ธํ์ค", "์ธํ์ค"],["๋๋ค์ดํจ๋ฉ", "๋๋ฐ์ดํจ๋ฉ"],["๋๋ค์ด์ค์ปคํธ", "๋๋ฐ์ด์ค์ปคํธ"], ["๊ทธ๋ ์ด์ง", "๊ทธ๋ ์ด์ง"], ["ํธ์", "ํธ์"],["ํ๊ฐ๋จผํธ", "ํ๊ฐ๋จผํธ"], ["ํ๋ฌํผ", "ํ๋ฌํผ"],["๋
ธ๋ฅด๋", "๋
ธ๋ฅด๋"], ["์ธ๋ธ๋ ๋", "์ธ๋ธ๋ ๋"],["๋ผ์ฟค ๋ธ๋ ๋", "๋ผ์ฟค ๋ธ๋ ๋"], ["์ธ์ด์ง๊ทธ๋ฆฐ", "์ธ์ด์ง๊ทธ๋ฆฐ"], ["๋ชจ๋ธ์์ธ", "๋ชจ๋ธ์์ธ"], ["ํฌ๋ก์", "ํฌ๋ก์
ฐ"],["๋ ์ด์ค ํจ์ง", "๋ ์ด์ค ํจ์ง"], ["์์ด์์ปค", "์์ด์์ปค"], ["ํธ๋ ์คํ์ผ๋ฌ", "ํธ๋ ์คํ์ผ๋ฌ"], ["์์ผ๋ ", "์์ผ๋ "], ["ํ ์ธ๊ฐ", "ํ๋ฆฐ๊น"],["ํน๊ฐ", "ํน๊น"], ["์ต์ ๊ฐ", "์ต์ ๊น"], ["๋จ๋
๊ตฌ์ฑ", "๋จ๋
๊พธ์ฑ"], ["์ญ๋๊ธ", "์ญ๋๋"], ["์ฑ๊ฒฐ์ ", "์ฑ๊ปผ์ "], ["์ผ์๋ถ", "์ผ์จ๋ถ"], ["๋ฌด์ด์", "๋ฌด์ด์"],["๋งค์ง์๋ฐ", "๋งค์ง๋๋ฐ"], ["์๋์ฃผ๋ฌธ", "์๋์ฃผ๋ฌธ"],["์ฌ์ํ", "์ฌ์ํ"], ["ํ๋ฆฌํฐ๋ฅผ", "ํ๋ฆฌํฐ๋ฅผ"],["๋ํ
์ผ์ด", "๋ํ
์ด๋ฆฌ"], ["์ค๋ฃจ์ฃ์ด", "์ค๋ฃจ์์"],["์ปคํฐ์ค๋ฒ
", "์ปคํฐ์ค๋ฒ
"], ["์ธ๋ฅด์ฆ๋ธ๋์ฝ", "์ธ๋ฅด์ฆ๋ธ๋์ฝ"],["ํฌ๋จธํฐ๋ธ", "ํฌ๋จธํฐ๋ธ"], ["๋นํธ๋ฆด", "๋นํธ๋ฆด"],["๋ ๋ฏธ์ค๋ฅด๋ฃจ", "๋ ๋ฏธ์ค๋ฅด๋ฃจ"], ["์ญ๋ํด๋ผ์ฐ์ค", "์๋ํด๋ผ์ฐ์ค"], ["ํธ๋ง๊ณจํ", "ํธ๋ง๊ณจํ"],["์ปฌ๋ผ๋น์", "์ปฌ๋ผ๋น์"], ["์์ค๊น๋ค์คํฌ์ธ ", "์์ค๊น๋ค์คํฌ์ธ "],["์์ค์นด๋ค์คํฌ์ธ ", "์์ค๊น๋ค์คํฌ์ธ "], ["์์ธ", "์์ธ"],["์๋ํ๋", "์๋ํ๋"], ["๋ผ์์ํ", "๋ผ์์ํ"],["๋ชจ๋ฅด๊ฐ", "๋ชจ๋ฅด๊ฐ"], ["๋ง์ค์คํ๋์ค", "๋ง์ฐ์คํ๋์ค"],["๋ฐ์ผ๋ฆฌ๋ธ๋ฃจ", "๋ฐ์ผ๋ฆฌ๋ธ๋ฃจ"], ["ํธ๋ผ์ด์ํ", "ํธ๋ผ์ด์ํ"],["์์จ๋น ํด๋กํด๋ฝ", "์์จ๋น ํด๋กํด๋ฝ"], ["๊ธฐํ ", "๊ธฐํ "],["์ค๋ก ๋", "์ค๋ก ๋"], ["SJ์๋", "์์ค์ ์ด์๋"],["์ฝ์ด ์ด์ผํฑ", "์ฝ์ด ์ด์ผํฑ"], ["๋ฅด๋คํฌ๋ฃจ", "๋ฅด๋คํฌ๋ฃจ"],["๋ํ", "๋ํ"], ["1์ข
", "์ผ์ข
"], ["2์ข
", "์ด์ข
"],["3์ข
", "์ผ์ข
"], ["4์ข
", "์ฌ์ข
"],["5์ข
", "์ค์ข
"], ["10์ข
", "์ญ์ข
"], ["4in1", "ํฌ์ธ์"],["25FW", "์ด์ค ์ํ ๋๋ธ์ "],["25 F/W", "์ด์ค ์ํ ๋๋ธ์ "], ["์ด์ค ์ํ๋ ๋ธ์ ", "์ด์ค ์ํ ๋๋ธ์ "],["26SS", "์ด์ญ๋ต์์ค์์ค"],["2026 SS", "์ด์ฒ์ด์ญ๋ต ์์ค์์ค"], ["SS์์ฆ", "์์ค์์ค ์์ฆ"], ["์
์
", "์ธ๋ฅ"], ["๋ฆฌ๋ฒ์๋ธ", "๋ฆฌ๋ฒ์๋ธ"],["๋งจํฌ๋งจ", "๋งจํฌ๋งจ"], ["์ํฐํฌ์ธ ", "์ํฐํฌ์ธ "],["๋ณธ๋ฉํฌ์ธ ", "๋ณธ๏ฟฝ๏ฟฝ๏ฟฝํฌ์ธ "], ["์ค์์์ผ", "์ค์์์ผ"],["ํ์ด๋ธ๋ฆฌ๋", "ํ์ด๋ธ๋ฆฌ๋"], ["๋ ์ด์ด๋ง", "๋ ์ด์ด๋ง"],["๋ ์ด์ด๋", "๋ ์ด์ด๋"], ["์์นด๋ผ", "์์นด๋ผ"],["์ธํ์ค", "์ธํ์ค"], ["๋๋ค์ดํจ๋ฉ", "๋๋ฐ์ดํจ๋ฉ"],["๋๋ค์ด์ค์ปคํธ", "๋๋ฐ์ด์ค์ปคํธ"], ["๊ทธ๋ ์ด์ง", "๊ทธ๋ ์ด์ง"],["ํธ์", "ํธ์"], ["ํ๊ฐ๋จผํธ", "ํ๊ฐ๋จผํธ"],["ํ๋ฌํผ", "ํ๋ฌํผ"], ["๋
ธ๋ฅด๋", "๋
ธ๋ฅด๋"],["์ธ๋ธ๋ ๋", "์ธ๋ธ๋ ๋"], ["๋ผ์ฟค ๋ธ๋ ๋", "๋ผ์ฟค ๋ธ๋ ๋"],["์ธ์ด์ง๊ทธ๋ฆฐ", "์ธ์ด์ง๊ทธ๋ฆฐ"], ["๋ชจ๋ธ์์ธ", "๋ชจ๋ธ์์ธ"],["ํฌ๋ก์", "ํฌ๋ก์
ฐ"], ["๋ ์ด์ค ํจ์ง", "๋ ์ด์ค ํจ์ง"],["์์ด์์ปค", "์์ด์์ปค"], ["ํธ๋ ์คํ์ผ๋ฌ", "ํธ๋ ์คํ์ผ๋ฌ"],["์์ผ๋ ", "์์ผ๋ "], ["์์ด ๋ธ๋ ์ด์ ", "์์ด ๋ธ๋ ์ด์ "],["ํธ๋ธ๋ฃจ", "ํธ๋ธ๋ฃจ"], ["์์ด๋ฆฌ", "์์ด๋ฆฌ"], ["ํํฑ", "ํํฑ"], ["์ฌ๋ฆฌ๋ธ๋ฆฌ์ค", "์ฌ๋ฆฌ๋ธ๋ฆฌ์ค"],["ํค ๋ ์ด์ด๋", "ํค ๋ ์ด์ด๋"], ["์ฌํฐ", "์ฌํฐ"], ["์ํฌ๋ธ๋", "์ํฌ๋ธ๋"], ["์ธ๋จธ๋ธ๋ผ์ด", "์ธ๋จธ๋ธ๋ผ์ด"], ["๋ธ๋ฃธํํฌ", "๋ธ๋ฃธํํฌ"],["๋ฏธ์คํธ๋ธ๋ฃจ", "๋ฏธ์คํธ๋ธ๋ฃจ"], ["๋ฅด๋ค๋ฒ ์ด์ง", "๋ฅด๋ค๋ฒ ์ด์ง"], ["์ธ๋จธ์นดํค", "์ธ๋จธ์นดํค"],["์ธํผ๋ํฐ๋ธ๋ฃจ", "์ธํผ๋ํฐ๋ธ๋ฃจ"], ["๋ฅด๋ค๋ธ๋", "๋ฅด๋ค๋ธ๋"],["๋ธ๋ฃธํ์ดํธ", "๋ธ๋ฃธํ์ดํธ"], ["์ธ๋จธ๋ค์ด๋น", "์ธ๋จธ๋ค์ด๋น"],["๋ธ๋ผ์ธํํฌ", "๋ธ๋ผ์ธํํฌ"], ["์ธ๋จธ๋ฒ ์ด์ง", "์ธ๋จธ๋ฒ ์ด์ง"],["๋ฅ์์ธ", "๋ฅ์์ธ"], ["100ํ๋ก", "๋ฐฑํ๋ก"],["100%", "๋ฐฑํ๋ก"], ["86%", "ํ์ญ์กํ๋ก"], ["14%", "์ญ์ฌํ๋ก"],["1,499,900์", "๋ฐฑ์ฌ์ญ๊ตฌ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["169,900์", "์ญ์ก๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["159,900์", "์ญ์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["149,000์", "์ญ์ฌ๋ง ๊ตฌ์ฒ ์"],["12๋ง 9์ฒ 8๋ฐฑ ์", "์ญ์ด๋ง ๊ตฌ์ฒํ๋ฐฑ ์"],["10๋ง 9์ฒ์", "์ญ๋ง ๊ตฌ์ฒ์"],["89,900์", "ํ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["79,900์", "์น ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["79,900 ์", "์น ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["6๋ง 9์ฒ 9๋ฐฑ ์", "์ก๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["69,900์", "์ก๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],["69,900 ์", "์ก๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["3๋ง 6์ฒ์๋", "์ผ๋ง ์ก์ฒ์๋"]]
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) 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 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_items existing_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) print(f"โ
์๋ ๋ณต๊ตฌ & ๋ณํฉ ์๋ฃ! ์ด {len(merged_items)}๊ฐ์ ๋จ์ด๊ฐ ์ ์ฉ๋์์ต๋๋ค.")
perform_auto_recovery_and_merge()# =====================================================================
def load_dict(): flat_dict = {} try: if os.path.exists(dict_path): with open(dict_path, "r", encoding="utf-8") as f: data = json.load(f) for item in data.get("items",[]): if len(item) == 2: flat_dict[item[0].strip()] = item[1].strip() except: pass return flat_dict
def process_text(input_text): if not input_text or not input_text.strip(): return "", "", "์
๋ ฅ ๊ธ์ ์: 0์" char_count = f"์
๋ ฅ ๊ธ์ ์: {len(input_text)}์" flat_dict = load_dict() if not flat_dict: final_text = input_text if g2p is not None: try: final_text = g2p(input_text) except: pass else: sorted_keys = sorted(flat_dict.keys(), key=len, reverse=True) pattern = re.compile("|".join(map(re.escape, sorted_keys))) parts =[] last_end = 0 for match in pattern.finditer(input_text): start, end = match.span() chunk = input_text[last_end:start] if chunk: if g2p is not None: try: parts.append(g2p(chunk)) except: parts.append(chunk) else: parts.append(chunk) matched_word = match.group() parts.append(flat_dict[matched_word]) last_end = end tail = input_text[last_end:] if tail: if g2p is not None: try: parts.append(g2p(tail)) except: parts.append(tail) else: parts.append(tail) final_text = "".join(parts)
seq = difflib.SequenceMatcher(None, input_text, final_text) html_parts =[] for tag, i1, i2, j1, j2 in seq.get_opcodes(): chunk = final_text[j1:j2].replace('\n', '<br>') if tag == 'equal': html_parts.append(chunk) elif tag in ['replace', 'insert']: html_parts.append(f'<span style="background-color: #ffe066; font-weight: bold; padding: 2px; border-radius: 3px;">{chunk}</span>') html_output = f'<div style="line-height:1.6; font-size:16px; padding:10px; border:1px solid #ddd; border-radius:5px; background-color:#f9f9f9;">{"".join(html_parts)}</div>' return final_text, html_output, char_count
def 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() word = word.strip() pronun = pronun.strip() 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 not found: j_struct["items"].append([word, pronun]) try: with open(dict_path, "w", encoding="utf-8") as f: json.dump(j_struct, f, ensure_ascii=False, indent=2) if current_input and word not in current_input: status_msg = f"โ ๏ธ ์ฌ์ ์ ์ฅ ์๋ฃ! ํ์ง๋ง ์๋ณธ ํ
์คํธ์ '{word}'(์ด)๊ฐ ์์ด ํ๋ฉด์ ๋ณํ๊ฐ ์์ต๋๋ค. (1๋ฒ ์ฐฝ์์ ๊ทธ๋๋ก ๋ณต์ฌํด์ค์ธ์!)" else: 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_count else: return status_msg, "", "", "์
๋ ฅ ๊ธ์ ์: 0์"
def get_file(): return dict_path if os.path.exists(dict_path) else None
def upload_file(file_path): if file_path is not None: shutil.copy(file_path, dict_path) return "โ
ํ์ผ ๋ณต๊ตฌ ์๋ฃ!" return "โ ๏ธ ํ์ผ์ด ์์ต๋๋ค."
def apply_json_text(json_string): if not json_string or not json_string.strip(): return "โ ๏ธ ๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์." try: new_data = json.loads(json_string) if "items" not in new_data: return "โ ๏ธ ์ฌ๋ฐ๋ฅธ ์ฌ์ ํ์์ด ์๋๋๋ค. ('items' ํค๊ฐ ์์ต๋๋ค)" 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 new_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_items existing_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) return f"โ
๊ธฐ์กด ๋จ์ด๋ฅผ ์ ์งํ๋ฉฐ {len(new_data.get('items',[]))}๊ฐ์ ๋จ์ด๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ํ๋ฌ์ค(+) ํ์ต๋๋ค! (ํ์ฌ ์ด ๋จ์ด ์: {len(merged_items)}๊ฐ)" except Exception as e: return f"โ JSON ํ์ฑ ์๋ฌ (๊ดํธ๋ ์ผํ๊ฐ ๋น ์ก๋์ง ํ์ธํด์ฃผ์ธ์): {e}"
with gr.Blocks(theme="default") as iface: gr.Markdown("## ๐๏ธ ๋๋ง์ TTS ์ ์ฒ๋ฆฌ ๋ณํ๊ธฐ") with gr.Tabs(): with gr.Tab("๐๏ธ ๋ฉ์ธ ํ๋ฉด"): with gr.Row(): with gr.Column(): input_text = gr.Textbox(lines=8, label="1๏ธโฃ ์๋ณธ ํ
์คํธ ์
๋ ฅ") 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_text = gr.Textbox(lines=8, label="2๏ธโฃ ๋ณํ๋ ํ
์คํธ", show_copy_button=True) output_html = gr.HTML(label="๐ ๋ณ๊ฒฝ์ ํ์ธ") btn_conv.click(fn=process_text, inputs=[input_text], outputs=[output_text, output_html, char_count], api_name=False) btn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count], api_name=False) btn_copy.click( fn=None, inputs=[output_text], outputs=None, js="(text) => { if(text) { navigator.clipboard.writeText(text); alert('โ
๋ณต์ฌ ์๋ฃ!'); } }", api_name=False ) gr.Markdown("---") with gr.Row(): 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") 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 ) btn_clear_dict_inputs.click( fn=lambda: ("", ""), outputs=[nw, np], 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("---") 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="๋ฐฑ์
ํ์ผ ์
๋ก๋", 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__": iface.launch()app.py+277-13