Spaces:
Running
Running
Download app.py from easyadaptor/VoiceScript-AI-II: direct link, hf CLI and curl.
- Browser
- Download file 22.3 kB
-
https://huggingface.co/spaces/easyadaptor/VoiceScript-AI-II/resolve/53df6b89bac2c683044bcb4e9bef14dfc28d20a3/app.py
- Command line
-
hf download hf://spaces/easyadaptor/VoiceScript-AI-II@53df6b89bac2c683044bcb4e9bef14dfc28d20a3/app.py
-
curl -L -o app.py https://huggingface.co/spaces/easyadaptor/VoiceScript-AI-II/resolve/53df6b89bac2c683044bcb4e9bef14dfc28d20a3/app.py
22.3 kB
| import gradio as gr | |
| import json | |
| import os | |
| import difflib | |
| import shutil | |
| import re | |
| try: | |
| from g2pk import G2p | |
| except ImportError: | |
| G2p = None | |
| print("G2P ๋ชจ๋ธ ๋ก๋ฉ ์ค...") | |
| try: | |
| if G2p: | |
| g2p = G2p() | |
| else: | |
| g2p = None | |
| except Exception as e: | |
| print(f"G2P ๋ก๋ฉ ์คํจ: {e}") | |
| g2p = None | |
| dict_path = "custom_dict.json" | |
| # ===================================================================== | |
| # โ 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์์ฆ", "์์ค์์ค ์์ฆ"],["์ ์ ", "์ธ๋ฅ"],["๋ฆฌ๋ฒ์๋ธ", "๋ฆฌ๋ฒ์๋ธ"],["๋งจํฌ๋งจ", "๋งจํฌ๋งจ"],["์ํฐํฌ์ธ ", "์ํฐํฌ์ธ "],["๋ณธ๋ฉํฌ์ธ ", "๋ณธ๋ฉํฌ์ธ "],["์ค์์์ผ", "์ค์์์ผ"],["ํ์ด๋ธ๋ฆฌ๋", "ํ์ด๋ธ๋ฆฌ๋"],["๋ ์ด์ด๋ง", "๋ ์ด์ด๋ง"],["๋ ์ด์ด๋", "๋ ์ด์ด๋"],["์์นด๋ผ", "์์นด๋ผ"],["์ธํ์ค", "์ธํ์ค"],["๋๋ค์ดํจ๋ฉ", "๋๋ฐ์ดํจ๋ฉ"],["๋๋ค์ด์ค์ปคํธ", "๋๋ฐ์ด์ค์ปคํธ"],["๊ทธ๋ ์ด์ง", "๊ทธ๋ ์ด์ง"],["ํธ์", "ํธ์"],["ํ๊ฐ๋จผํธ", "ํ๊ฐ๋จผํธ"],["ํ๋ฌํผ", "ํ๋ฌํผ"],["๋ ธ๋ฅด๋", "๋ ธ๋ฅด๋"],["์ธ๋ธ๋ ๋", "์ธ๋ธ๋ ๋"],["๋ผ์ฟค ๋ธ๋ ๋", "๋ผ์ฟค ๋ธ๋ ๋"],["์ธ์ด์ง๊ทธ๋ฆฐ", "์ธ์ด์ง๊ทธ๋ฆฐ"],["๋ชจ๋ธ์์ธ", "๋ชจ๋ธ์์ธ"],["ํฌ๋ก์", "ํฌ๋ก์ ฐ"],["๋ ์ด์ค ํจ์ง", "๋ ์ด์ค ํจ์ง"],["์์ด์์ปค", "์์ด์์ปค"],["ํธ๋ ์คํ์ผ๋ฌ", "ํธ๋ ์คํ์ผ๋ฌ"],["์์ผ๋ ", "์์ผ๋ "],["์์ด ๋ธ๋ ์ด์ ", "์์ด ๋ธ๋ ์ด์ "],["ํธ๋ธ๋ฃจ", "ํธ๋ธ๋ฃจ"],["์์ด๋ฆฌ", "์์ด๋ฆฌ"],["ํํฑ", "ํํฑ"],["์ฌ๋ฆฌ๋ธ๋ฆฌ์ค", "์ฌ๋ฆฌ๋ธ๋ฆฌ์ค"],["ํค ๋ ์ด์ด๋", "ํค ๋ ์ด์ด๋"],["์ฌํฐ", "์ฌํฐ"],["์ํฌ๋ธ๋", "์ํฌ๋ธ๋"],["์ธ๋จธ๋ธ๋ผ์ด", "์ธ๋จธ๋ธ๋ผ์ด"],["๋ธ๋ฃธํํฌ", "๋ธ๋ฃธํํฌ"],["๋ฏธ์คํธ๋ธ๋ฃจ", "๋ฏธ์คํธ๋ธ๋ฃจ"],["๋ฅด๋ค๋ฒ ์ด์ง", "๋ฅด๋ค๋ฒ ์ด์ง"],["์ธ๋จธ์นดํค", "์ธ๋จธ์นดํค"],["์ธํผ๋ํฐ๋ธ๋ฃจ", "์ธํผ๋ํฐ๋ธ๋ฃจ"],["๋ฅด๋ค๋ธ๋", "๋ฅด๋ค๋ธ๋"],["๋ธ๋ฃธํ์ดํธ", "๋ธ๋ฃธํ์ดํธ"],["์ธ๋จธ๋ค์ด๋น", "์ธ๋จธ๋ค์ด๋น"],["๋ธ๋ผ์ธํํฌ", "๋ธ๋ผ์ธํํฌ"],["์ธ๋จธ๋ฒ ์ด์ง", "์ธ๋จธ๋ฒ ์ด์ง"],["๋ฅ์์ธ", "๋ฅ์์ธ"],["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) | |
| 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, use_g2p, auto_break, font_size): | |
| 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 use_g2p and 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 use_g2p and 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 use_g2p and g2p is not None: | |
| try: | |
| parts.append(g2p(tail)) | |
| except: | |
| parts.append(tail) | |
| else: | |
| parts.append(tail) | |
| final_text = "".join(parts) | |
| if auto_break: | |
| final_text = final_text.replace(". ", ".\n\n").replace("? ", "?\n\n") | |
| 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; color: #000;">{chunk}</span>') | |
| html_output = f''' | |
| <div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div> | |
| <div id="prompter_output_div" style="font-size:{font_size}px;"> | |
| {"".join(html_parts)} | |
| </div> | |
| ''' | |
| return final_text, html_output, char_count | |
| def clear_all(): | |
| return "", "", "", "์ ๋ ฅ ๊ธ์ ์: 0์" | |
| def add_and_update(word, pronun, current_input, use_g2p, auto_break, font_size): | |
| 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}'(์ด)๊ฐ ์์ด ํ๋ฉด์ ๋ณํ๊ฐ ์์ต๋๋ค." | |
| 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, use_g2p, auto_break, font_size) | |
| 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',[]))}๊ฐ์ ๋จ์ด๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ํ๋ฌ์ค(+) ํ์ต๋๋ค!" | |
| except Exception as e: | |
| return f"โ JSON ํ์ฑ ์๋ฌ: {e}" | |
| # โ ํต์ฌ! ๋ค์ฌ์ฐ๊ธฐ ์์ธ(max-width)์ ๋ฌด๋ ฅํํ๊ณ ์์ชฝ์ 100% ๋์ผํ๊ฒ ์ธํ ํ๋ ์๋ฒฝ CSS โ | |
| custom_css = """ | |
| /* Gradio์ HTML ์ปดํฌ๋ํธ๊ฐ ๊ฐ์ ๋ก ํญ์ ์ขํ๊ณ ์ค์ ์ ๋ ฌํ๋ ์ ์ฑ ๊ธฐ๋ณธ๊ฐ์ ์๋ฒฝํ ๋ฌด๋ ฅํํฉ๋๋ค! */ | |
| #prompter_html_wrap { | |
| width: 100% !important; | |
| max-width: 100% !important; | |
| margin: 0 !important; | |
| padding: 0 !important; | |
| } | |
| #prompter_html_wrap .prose { | |
| width: 100% !important; | |
| max-width: 100% !important; | |
| text-align: left !important; | |
| margin: 0 !important; | |
| } | |
| /* ์ผ์ชฝ ์๋ณธ ํ ์คํธ ์ฐฝ */ | |
| #input_text_area textarea { | |
| height: 500px !important; | |
| max-height: 500px !important; | |
| overflow-y: auto !important; | |
| padding: 16px !important; | |
| line-height: 1.8 !important; | |
| box-sizing: border-box !important; | |
| white-space: pre-wrap !important; | |
| word-break: break-word !important; | |
| } | |
| /* ์ค๋ฅธ์ชฝ ํ๋กฌํํฐ ๋ทฐ ๋ผ๋ฒจ */ | |
| #prompter_label_space { | |
| font-size: 13px !important; | |
| color: var(--body-text-color-subdued, #6b7280) !important; | |
| margin-bottom: 8px !important; | |
| display: block !important; | |
| text-align: left !important; | |
| font-weight: 400 !important; | |
| } | |
| /* ์ค๋ฅธ์ชฝ ํ๋กฌํํฐ ๋ทฐ ๊น๋ง ์ฐฝ */ | |
| #prompter_output_div { | |
| height: 500px !important; | |
| max-height: 500px !important; | |
| overflow-y: auto !important; | |
| padding: 16px !important; | |
| line-height: 1.8 !important; | |
| box-sizing: border-box !important; | |
| background-color: #333 !important; | |
| color: #fff !important; | |
| border: 1px solid #ddd !important; | |
| border-radius: 8px !important; | |
| font-family: inherit !important; | |
| white-space: pre-wrap !important; | |
| word-break: break-word !important; | |
| text-align: left !important; | |
| margin-top: 0 !important; | |
| width: 100% !important; | |
| max-width: 100% !important; | |
| } | |
| """ | |
| script_js = """ | |
| function() { | |
| function applyFontSize(size) { | |
| let ta1 = document.querySelector('#input_text_area textarea'); | |
| if(ta1) { ta1.style.fontSize = size + 'px'; } | |
| let ta2 = document.querySelector('#output_text_area textarea'); | |
| if(ta2) { ta2.style.fontSize = size + 'px'; ta2.style.lineHeight = '1.8'; } | |
| } | |
| setTimeout(function() { applyFontSize(22); }, 500); | |
| let isSyncing1 = false; | |
| let isSyncing2 = false; | |
| let isSyncing3 = false; | |
| document.addEventListener('scroll', function(e) { | |
| let target = e.target; | |
| let ta1 = document.querySelector('#input_text_area textarea'); | |
| let ta2 = document.querySelector('#output_text_area textarea'); | |
| let div3 = document.getElementById('prompter_output_div'); | |
| if (!ta1 || !div3) return; | |
| if (target === ta1) { | |
| if (isSyncing1) { isSyncing1 = false; return; } | |
| if (ta1.scrollHeight - ta1.clientHeight <= 0) return; | |
| isSyncing2 = true; | |
| isSyncing3 = true; | |
| let percentage = ta1.scrollTop / (ta1.scrollHeight - ta1.clientHeight); | |
| if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { | |
| ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); | |
| } | |
| if (div3.scrollHeight - div3.clientHeight > 0) { | |
| div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight); | |
| } | |
| } | |
| else if (target === ta2) { | |
| if (isSyncing2) { isSyncing2 = false; return; } | |
| if (ta2 && ta2.scrollHeight - ta2.clientHeight <= 0) return; | |
| isSyncing1 = true; | |
| isSyncing3 = true; | |
| let percentage = ta2.scrollTop / (ta2.scrollHeight - ta2.clientHeight); | |
| if (ta1.scrollHeight - ta1.clientHeight > 0) { | |
| ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight); | |
| } | |
| if (div3.scrollHeight - div3.clientHeight > 0) { | |
| div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight); | |
| } | |
| } | |
| else if (target === div3) { | |
| if (isSyncing3) { isSyncing3 = false; return; } | |
| if (div3.scrollHeight - div3.clientHeight <= 0) return; | |
| isSyncing1 = true; | |
| isSyncing2 = true; | |
| let percentage = div3.scrollTop / (div3.scrollHeight - div3.clientHeight); | |
| if (ta1.scrollHeight - ta1.clientHeight > 0) { | |
| ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight); | |
| } | |
| if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { | |
| ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); | |
| } | |
| } | |
| }, true); | |
| } | |
| """ | |
| with gr.Blocks(theme="default", css=custom_css) as iface: | |
| 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(): | |
| gr.Markdown("**โ๏ธ ๋ณํ ๋ฐ ํ๋ฉด ์ค์ **") | |
| use_g2p = gr.Checkbox(label="๐ค AI ๋ฐ์ ๋ณํ ์ผ๊ธฐ (์ฐ์ ์ฒ๋ฆฌ์ฉ)", value=False) | |
| auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋์์ ์๋์ผ๋ก ์ค๋ฐ๊ฟ ํ๊ธฐ", value=True) | |
| 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") | |
| with gr.Column(): | |
| initial_html = '<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ (๋ณ๊ฒฝ์ ํ์ธ)</div><div id="prompter_output_div" style="font-size:22px;"></div>' | |
| # โ ๋ณ๊ฒฝ๋ ๋ถ๋ถ: elem_id="prompter_html_wrap" ๋ฅผ ๋ถ์ฌํด์ Gradio์ ๊ฐ์ ์ค์์ ๋ ฌ/ํญ์ ํ ์์ฑ์ CSS๋ก ๋ฌด๋ ฅํํฉ๋๋ค! โ | |
| output_html = gr.HTML(value=initial_html, 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") | |
| btn_conv.click(fn=process_text, inputs=[input_text, use_g2p, auto_break, font_size], 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 | |
| ) | |
| font_size.change( | |
| fn=process_text, | |
| inputs=[input_text, use_g2p, auto_break, font_size], | |
| outputs=[output_text, output_html, char_count], | |
| api_name=False | |
| ).then( | |
| fn=None, | |
| inputs=[font_size], | |
| js="(size) => { " | |
| "let ta1 = document.querySelector('#input_text_area textarea'); " | |
| "if(ta1) { ta1.style.fontSize = size + 'px'; } " | |
| "let ta2 = document.querySelector('#output_text_area textarea'); " | |
| "if(ta2) { ta2.style.fontSize = size + 'px'; } " | |
| "}" | |
| ) | |
| auto_break.change(fn=process_text, inputs=[input_text, use_g2p, auto_break, font_size], outputs=[output_text, output_html, char_count], 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, use_g2p, auto_break, font_size], | |
| 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) | |
| iface.load(None, js=script_js) | |
| if __name__ == "__main__": | |
| iface.launch() | |