Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from bs4 import BeautifulSoup | |
| import re | |
| import logging | |
| import requests # ์ถ๊ฐ์ฝ๋์์ ์ฌ์ฉ | |
| # ๋๋ฒ๊น ๋ก๊น ์ค์ (์ ์ฒด ํตํฉ์ ์ํด ํฌ๋งท ํฌํจ) | |
| logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s") | |
| # ---------- [๋ชจ๋1: ๊ธฐ๋ณธ์ฝ๋] ์์ ---------- | |
| # ์์ด ์์ ํ๊ตญ์ด ์๋ก ๋ณํํ๊ธฐ ์ํ ๋งคํ | |
| month_mapping = { | |
| "January": "1์", | |
| "February": "2์", | |
| "March": "3์", | |
| "April": "4์", | |
| "May": "5์", | |
| "June": "6์", | |
| "July": "7์", | |
| "August": "8์", | |
| "September": "9์", | |
| "October": "10์", | |
| "November": "11์", | |
| "December": "12์" | |
| } | |
| def convert_date_range(date_range_str): | |
| """ | |
| ์ ๋ ฅ๋ '6 January - 12 January' ํํ์ ๋ ์ง ๋ฌธ์์ด์ | |
| '1์ 6์ผ ~ 1์ 12์ผ' ํํ๋ก ๋ณํํ๋ ํจ์. | |
| """ | |
| logging.debug("์๋ณธ ๋ ์ง ๋ฒ์: %s", date_range_str) | |
| parts = date_range_str.split('-') | |
| if len(parts) != 2: | |
| logging.debug("๋ ์ง ๋ฒ์ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์: %s", date_range_str) | |
| return date_range_str | |
| start = parts[0].strip() # ์: "6 January" | |
| end = parts[1].strip() # ์: "12 January" | |
| start_parts = start.split() | |
| end_parts = end.split() | |
| if len(start_parts) < 2 or len(end_parts) < 2: | |
| logging.debug("๋ ์ง ๊ตฌ์ฑ์์ ๋ถ์กฑ: %s, %s", start, end) | |
| return date_range_str | |
| start_day = start_parts[0] | |
| start_month_en = start_parts[1] | |
| end_day = end_parts[0] | |
| end_month_en = end_parts[1] | |
| start_month = month_mapping.get(start_month_en, start_month_en) | |
| end_month = month_mapping.get(end_month_en, end_month_en) | |
| converted = f"{start_month} {start_day}์ผ ~ {end_month} {end_day}์ผ" | |
| logging.debug("๋ณํ๋ ๋ ์ง ๋ฒ์: %s", converted) | |
| return converted | |
| def process_html(html_text): | |
| """ | |
| ์ ์ฒด ํ์ด์ง HTML ์ ๋ ฅ์ ๋ฐ์์ ๊ณผ๋ชฉ๋ช ๊ณผ ๊ฐ ์น์ ๋ณ ๋์์ ๊ฐ์ ๋ชฉ๋ก์ ์ถ์ถํ๋ ํจ์. | |
| ์ถ์ถ ๊ท์น: | |
| 1. ๊ณผ๋ชฉ๋ช : <h1> ํ๊ทธ ๋ด์ ํ ์คํธ๋ฅผ ์ฌ์ฉ. | |
| 2. ์น์ : | |
| - <li> ํ๊ทธ์ id๊ฐ "section-X"์ธ ํญ๋ชฉ๋ค์ ์ํ. | |
| - section-0๋ ์คํต. | |
| - section-1์ "Introduction"์ผ๋ก ํ๊ธฐ. | |
| - section-2 ์ด์์ (section ๋ฒํธ - 1)์ฃผ์ฐจ๋ก ํ๊ธฐ. | |
| - ๊ฐ ์น์ ์ <h3 class="sectionname"> ๋ด๋ถ <a> ํ๊ทธ์ ํ ์คํธ์์ ๋ ์ง ๋ฒ์๋ฅผ ์ถ์ถํ์ฌ ๋ณํ. | |
| - ๊ฐ ์น์ ๋ด์ ๋ชจ๋ <iframe> ํ๊ทธ์ src ์์ฑ ๊ฐ์ ๋์์ ๊ฐ์ URL๋ก ์ถ์ถ. | |
| """ | |
| logging.debug("์ ๋ ฅ HTML ์ฒ๋ฆฌ ์์") | |
| soup = BeautifulSoup(html_text, "html.parser") | |
| # 1. ๊ณผ๋ชฉ๋ช ์ถ์ถ (h1 ํ๊ทธ ์ฌ์ฉ) | |
| subject_elem = soup.find("h1") | |
| subject_name = "" | |
| if subject_elem: | |
| subject_name = subject_elem.get_text(strip=True) | |
| logging.debug("์ถ์ถ๋ ๊ณผ๋ชฉ๋ช : %s", subject_name) | |
| else: | |
| logging.debug("h1 ํ๊ทธ๋ฅผ ์ฐพ์ง ๋ชปํจ") | |
| # 2. ์น์ ๋ณ ๋์์ ๊ฐ์ ๋ชฉ๋ก ์ถ์ถ | |
| sections_output = "" | |
| section_elements = soup.find_all("li", id=re.compile(r"^section-\d+")) | |
| logging.debug("์ฐพ์ ์น์ ๊ฐ์: %d", len(section_elements)) | |
| for section in section_elements: | |
| section_id = section.get("id") | |
| logging.debug("์ฒ๋ฆฌ ์ค์ธ ์น์ ID: %s", section_id) | |
| sec_match = re.search(r"section-(\d+)", section_id) | |
| if not sec_match: | |
| continue | |
| sec_num = int(sec_match.group(1)) | |
| if sec_num == 0: | |
| logging.debug("section-0 ์ ์คํต") | |
| continue | |
| # ์น์ ๋ผ๋ฒจ ์ง์ | |
| if sec_num == 1: | |
| section_label = "Introduction" | |
| else: | |
| week_num = sec_num - 1 # section-2๋ถํฐ 1์ฃผ์ฐจ, section-3์ 2์ฃผ์ฐจ ๋ฑ | |
| section_label = f"{week_num}์ฃผ์ฐจ" | |
| # ์น์ ํค๋์์ ๋ ์ง ๋ฒ์ ์ถ์ถ (h3 ํ๊ทธ ๋ด <a> ํ๊ทธ ํ ์คํธ) | |
| h3_elem = section.find("h3", class_="sectionname") | |
| date_range_text = "" | |
| if h3_elem and h3_elem.find("a"): | |
| header_text = h3_elem.find("a").get_text(strip=True) | |
| logging.debug("ํค๋ ํ ์คํธ: %s", header_text) | |
| date_match = re.search(r'(\d+\s+[A-Za-z]+\s*-\s*\d+\s+[A-Za-z]+)', header_text) | |
| if date_match: | |
| raw_date_range = date_match.group(1) | |
| date_range_text = convert_date_range(raw_date_range) | |
| else: | |
| logging.debug("๋ ์ง ๋ฒ์ ํจํด ๋งค์นญ ์คํจ: %s", header_text) | |
| else: | |
| logging.debug("h3 ๋๋ h3 ๋ด a ํ๊ทธ๋ฅผ ์ฐพ์ง ๋ชปํจ for section: %s", section_id) | |
| if sec_num == 1: | |
| section_heading = f"์น์ : {section_label}" | |
| else: | |
| if date_range_text: | |
| section_heading = f"์น์ : {section_label} ({date_range_text})" | |
| else: | |
| section_heading = f"์น์ : {section_label}" | |
| sections_output += section_heading + "\n" | |
| # ํด๋น ์น์ ๋ด iframe ํ๊ทธ๋ก๋ถํฐ ๋์์ ๊ฐ์ URL ์ถ์ถ | |
| iframes = section.find_all("iframe") | |
| logging.debug("์น์ %s ๋ด ์ฐพ์ iframe ๊ฐ์: %d", section_id, len(iframes)) | |
| for idx, iframe in enumerate(iframes, start=1): | |
| video_url = iframe.get("src", "").strip() | |
| if video_url: | |
| sections_output += f"๊ฐ์{idx} : {video_url}\n" | |
| logging.debug("์ถ์ถ๋ ๋์์ ๊ฐ์ URL: %s", video_url) | |
| sections_output += "\n" | |
| logging.debug("HTML ์ฒ๋ฆฌ ์๋ฃ") | |
| return subject_name, sections_output | |
| # Gradio ์ธํฐํ์ด์ค ์์ฑ (๋ชจ๋1) | |
| iface = gr.Interface( | |
| fn=process_html, | |
| inputs=gr.Textbox(label="์ ์ฒด ํ์ด์ง HTML ์ ๋ ฅ", lines=20, placeholder="HTML ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์..."), | |
| outputs=[ | |
| gr.Textbox(label="๊ณผ๋ชฉ๋ช "), | |
| gr.Textbox(label="๋์์ ๊ฐ์ ๋ชฉ๋ก") | |
| ], | |
| description="์ ์ฒด ํ์ด์ง HTML์ ์ ๋ ฅํ๋ฉด ๊ณผ๋ชฉ๋ช ๊ณผ ๊ฐ ์น์ ๋ณ ๋์์ ๊ฐ์ ๋ชฉ๋ก์ ์ถ์ถํฉ๋๋ค. (๋๋ฒ๊น ์ ๋ณด๋ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.)" | |
| ) | |
| # ---------- [๋ชจ๋1: ๊ธฐ๋ณธ์ฝ๋] ๋ ---------- | |
| # ---------- [๋ชจ๋2: ์ถ๊ฐ์ฝ๋] ์์ ---------- | |
| def fetch_page_source(url): | |
| try: | |
| logging.debug(f"๊ฐ์ ํ์ด์ง๋ฅผ ๊ฐ์ ธ์ค๋ ์ค: {url}") | |
| response = requests.get(url) | |
| response.raise_for_status() | |
| logging.debug("ํ์ด์ง ์์ค๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๊ฐ์ ธ์ด") | |
| return response.text | |
| except Exception as e: | |
| logging.error(f"ํ์ด์ง ์์ค ๊ฐ์ ธ์ค๊ธฐ ์ค๋ฅ: {e}") | |
| return "์ค๋ฅ ๋ฐ์: " + str(e) | |
| def create_script_url(lecture_url): | |
| """ | |
| ์ ๋ ฅ๋ฐ์ ๊ฐ์ URL์ ํ์ด์ง ์์ค์์ ์คํฌ๋ฆฝํธ ํ๊ทธ ์์ ๋ถ๋ถ์ ์ฐพ์ | |
| "text_tracks" ๋ด๋ถ์ "url" ๊ฐ์ ์ถ์ถํ ํ, 'https://player.vimeo.com'์ ์์ ๋ถ์ฌ์ ์คํฌ๋ฆฝํธ URL์ ์์ฑํจ. | |
| """ | |
| page_source = fetch_page_source(lecture_url) | |
| pattern = r'"text_tracks"\s*:\s*\[\s*\{[^}]*"url"\s*:\s*"([^"]+)"' | |
| match = re.search(pattern, page_source) | |
| if match: | |
| relative_url = match.group(1) | |
| script_url = "https://player.vimeo.com" + relative_url | |
| logging.debug(f"์คํฌ๋ฆฝํธ URL ์์ฑ: {script_url}") | |
| return script_url | |
| else: | |
| logging.debug("ํ์ด์ง ์์ค์์ ์คํฌ๋ฆฝํธ ํ๊ทธ ์์ ๋ถ๋ถ์ ์ฐพ์ง ๋ชปํจ") | |
| return "" | |
| def fetch_script(script_url): | |
| try: | |
| logging.debug(f"์คํฌ๋ฆฝํธ๋ฅผ ๊ฐ์ ธ์ค๋ ์ค: {script_url}") | |
| response = requests.get(script_url) | |
| response.raise_for_status() | |
| logging.debug("์คํฌ๋ฆฝํธ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๊ฐ์ ธ์ด") | |
| return response.text | |
| except Exception as e: | |
| logging.error(f"์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ ์ค๋ฅ: {e}") | |
| return "์ค๋ฅ ๋ฐ์: " + str(e) | |
| def remove_timeline(script_text, lecture_number): | |
| """ | |
| [๊ท์น์์ ] | |
| 1. ๋ฒํธ, ์๊ฐ(ํ์๋ผ์ธ) ๋ฑ์ ์ ์ธํ ๋ด์ฉ๋ง์ผ๋ก ์์ฑํ ๊ฒ. | |
| 2. ์๋์ ๋ฌธ์ฅ ์ฌ์ด ์ค ๊ฐ๊ฒฉ์ด ์๋๋ก ๋ชจ๋ ๋ถ์ฌ ์ถ๋ ฅํ ๊ฒ. | |
| 3. ๋ง์นจํ(.) ๋ค์์๋ ๋ฐ๋์ ์ฌ๋ฐฑ 1์นธ์ด ์์ด์ผ ํ๋ฉฐ, ์ฌ๋ฐฑ ์์ด ๋ด์ฉ์ด ์ด์ด์ง ๊ฒฝ์ฐ ๋ง์นจํ ๋ค์ ์ฌ๋ฐฑ์ ์ถ๊ฐํ ๊ฒ. | |
| 4. ๊ธ ๊ฐ์ฅ ์์ ์๋ "WEBVTT"๋ ์ญ์ ํ ๊ฒ. | |
| 5. ์ ๋ ๋ด์ฉ์ ์ค์ด๊ฑฐ๋ ์์ฝํ๊ฑฐ๋ ๋ฐ๊พธ์ง ๋ง๊ฒ. | |
| """ | |
| lines = script_text.splitlines() | |
| valid_lines = [] | |
| for line in lines: | |
| stripped_line = line.strip() | |
| if stripped_line == "": | |
| continue | |
| # ๋ฒํธ๋ง ์๋ ์ค ์ ๊ฑฐ | |
| if re.match(r'^\d+$', stripped_line): | |
| continue | |
| # ํ์๋ผ์ธ ํ์ ์ ๊ฑฐ (์: 00:00:00.000 --> 00:00:02.000) | |
| if re.match(r'^\d{1,2}:\d{2}(?::\d{2}(?:\.\d{3})?)?\s*-->\s*\d{1,2}:\d{2}(?::\d{2}(?:\.\d{3})?)?$', stripped_line): | |
| continue | |
| valid_lines.append(stripped_line) | |
| cleaned_text = "".join(valid_lines) | |
| # ๋ง์นจํ(.) ๋ค์์ ์ฌ๋ฐฑ์ด ์์ผ๋ฉด ์ฌ๋ฐฑ ์ถ๊ฐ | |
| cleaned_text = re.sub(r'\.(\S)', r'. \1', cleaned_text) | |
| # ๊ธ ๊ฐ์ฅ ์์ ์๋ "WEBVTT" ์ ๊ฑฐ | |
| cleaned_text = re.sub(r'^WEBVTT\s*', '', cleaned_text) | |
| return cleaned_text | |
| with gr.Blocks() as additional_demo: | |
| # ๋ชจ๋2 ์๋จ ์๋ด ๋ฌธ๊ตฌ | |
| gr.Markdown("โป ์๋ ์์๋๋ก ๊ฐ ๋จ๊ณ๋ณ ๋ฒํผ์ ๋๋ฌ ์งํํ์ธ์.") | |
| with gr.Row(): | |
| url1 = gr.Textbox(label="๊ฐ์1 URL", elem_id="url1") | |
| url2 = gr.Textbox(label="๊ฐ์2 URL", elem_id="url2") | |
| url3 = gr.Textbox(label="๊ฐ์3 URL", elem_id="url3") | |
| with gr.Row(): | |
| gen_url_btn1 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn1") | |
| gen_url_btn2 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn2") | |
| gen_url_btn3 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn3") | |
| with gr.Row(): | |
| script_url1 = gr.Textbox(label="๊ฐ์1 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url1") | |
| script_url2 = gr.Textbox(label="๊ฐ์2 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url2") | |
| script_url3 = gr.Textbox(label="๊ฐ์3 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url3") | |
| with gr.Row(): | |
| fetch_btn1 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn1") | |
| fetch_btn2 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn2") | |
| fetch_btn3 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn3") | |
| with gr.Row(): | |
| script1 = gr.Textbox(label="๊ฐ์1 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script1") | |
| script2 = gr.Textbox(label="๊ฐ์2 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script2") | |
| script3 = gr.Textbox(label="๊ฐ์3 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script3") | |
| with gr.Row(): | |
| remove_btn1 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn1") | |
| remove_btn2 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn2") | |
| remove_btn3 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn3") | |
| with gr.Row(): | |
| cleaned1 = gr.Textbox(label="๊ฐ์1 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned1") | |
| cleaned2 = gr.Textbox(label="๊ฐ์2 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned2") | |
| cleaned3 = gr.Textbox(label="๊ฐ์3 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned3") | |
| with gr.Row(): | |
| copy_btn1 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn1") | |
| copy_btn2 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn2") | |
| copy_btn3 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn3") | |
| with gr.Row(): | |
| copy_result1 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result1") | |
| copy_result2 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result2") | |
| copy_result3 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result3") | |
| gen_url_btn1.click(fn=lambda url: create_script_url(url), inputs=url1, outputs=script_url1) | |
| gen_url_btn2.click(fn=lambda url: create_script_url(url), inputs=url2, outputs=script_url2) | |
| gen_url_btn3.click(fn=lambda url: create_script_url(url), inputs=url3, outputs=script_url3) | |
| fetch_btn1.click(fn=lambda url: fetch_script(url), inputs=script_url1, outputs=script1) | |
| fetch_btn2.click(fn=lambda url: fetch_script(url), inputs=script_url2, outputs=script2) | |
| fetch_btn3.click(fn=lambda url: fetch_script(url), inputs=script_url3, outputs=script3) | |
| remove_btn1.click(fn=lambda script: remove_timeline(script, 1), inputs=script1, outputs=cleaned1) | |
| remove_btn2.click(fn=lambda script: remove_timeline(script, 2), inputs=script2, outputs=cleaned2) | |
| remove_btn3.click(fn=lambda script: remove_timeline(script, 3), inputs=script3, outputs=cleaned3) | |
| custom_script = """ | |
| <script> | |
| function setupCopy(copyBtnId, textBoxId, resultBoxId) { | |
| const copyBtn = document.getElementById(copyBtnId); | |
| if (!copyBtn) { | |
| console.error("๋ฒํผ " + copyBtnId + "๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."); | |
| return; | |
| } | |
| copyBtn.addEventListener("click", function(){ | |
| const textBoxElem = document.getElementById(textBoxId); | |
| const resultBoxElem = document.getElementById(resultBoxId); | |
| if(textBoxElem && resultBoxElem) { | |
| const textarea = textBoxElem.querySelector("textarea"); | |
| const resultTextarea = resultBoxElem.querySelector("textarea"); | |
| if(textarea && resultTextarea) { | |
| var text = textarea.value; | |
| if(text.trim() === ""){ | |
| resultTextarea.value = "๋ณต์ฌํ ๋ด์ฉ์ด ์์ต๋๋ค."; | |
| } else { | |
| navigator.clipboard.writeText(text).then(function(){ | |
| resultTextarea.value = "๋ณต์ฌ์๋ฃ"; | |
| }, function(err){ | |
| resultTextarea.value = "๋ณต์ฌ ์คํจ"; | |
| }); | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| document.addEventListener("DOMContentLoaded", function(){ | |
| setupCopy("copy_btn1", "cleaned1", "copy_result1"); | |
| setupCopy("copy_btn2", "cleaned2", "copy_result2"); | |
| setupCopy("copy_btn3", "cleaned3", "copy_result3"); | |
| }); | |
| </script> | |
| """ | |
| gr.HTML(custom_script) | |
| gr.Markdown("๋๋ฒ๊น ๋ชจ๋ ํ์ฑํ๋จ: ๋ก๊ทธ๊ฐ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.") | |
| # ---------- [๋ชจ๋2: ์ถ๊ฐ์ฝ๋] ๋ ---------- | |
| # ---------- ํตํฉ Gradio ์ฑ ๊ตฌ์ฑ (ํ ํ์ด์ง์ ๋ชจ๋ ํ์) ---------- | |
| with gr.Blocks() as app: | |
| gr.Markdown("# ์บ๋กค๋ผ์ธ๋ํ ๊ฐ์ ์ถ์ถ๊ธฐ") | |
| gr.Markdown("์ ์ฒด ํ์ด์ง HTML์ ์ ๋ ฅํ๋ฉด ๊ณผ๋ชฉ๋ช ๊ณผ ๊ฐ ์น์ ๋ณ ๋์์ ๊ฐ์ ๋ชฉ๋ก์ ์ถ์ถํฉ๋๋ค. (๋๋ฒ๊น ์ ๋ณด๋ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.)") | |
| gr.HTML( | |
| """ | |
| <div style="background-color: #f0f0f0; padding: 10px; margin-bottom: 20px;"> | |
| <strong>์ฌ์ฉ๋ฐฉ๋ฒ</strong> | |
| <ol> | |
| <li>์ถ์ถ์ ์ํ๋ ๊ฐ์ ํ์ด์ง์์ "Ctrl + U"๋ฅผ ๋๋ฅด๊ณ "ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค. | |
| ๋๋ ํด๋นํ์ด์ง์์ ๋ง์ฐ์ค ์ฐํด๋ฆญ ํ "ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํด๋ฆญ (์ฃ์ง์ ๊ฒฝ์ฐ "ํ์ด์ง ์๋ณธ ๋ณด๊ธฐ")</li> | |
| <li>"ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํ์ด์ง์์ ์ ์ฒด ๋ณต์ฌ๋ฅผ ํฉ๋๋ค. "Ctrl+A" ๋ค์ "Ctrl + C"</li> | |
| <li>"์ ์ฒด ํ์ด์ง HTML ์ ๋ ฅ"์ฐฝ์ ๋ณต์ฌํ ๋ด์ฉ์ ๋ถํ๋ฃ๊ธฐ ํฉ๋๋ค. "Ctrl + V"</li> | |
| <li>"Submit" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋์์ ๊ฐ์ ๋ชฉ๋ก์ด ๋์ต๋๋ค.</li> | |
| <li>๋ด์ฉ ์ถ์ถ์ ์ํ๋ ๊ฐ์ URL์ ๋ณต์ฌํด์ ์๋ "๊ฐ์ URL" ์ฐฝ์ ๋ถํ๋ฃ๊ธฐ ํฉ๋๋ค.</li> | |
| <li>์์๋๋ก ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํด๋น ์์์ ๊ฐ์ ๋ด์ฉ์ ์ถ์ถ ํ ์ ์์ต๋๋ค.</li> | |
| <li>๊ฐ๊ฐ ์ถ์ถ๋ ๊ฐ์ ๋ด์ฉ์ "ChatGPT"์ ์ ์ฒด ๋ถํ๋ฃ๊ณ ๊ฐ์ ์์ฝ์ ์ง์ํ๋ฉด ๋ฉ๋๋ค.</li> | |
| </ol> | |
| </div> | |
| """ | |
| ) | |
| iface.render() | |
| # Module1์ Submit ๋ฒํผ ํด๋ฆญ ์ Module2 ๋ด์ฉ ์ง์ฐ๊ธฐ ์ํ JavaScript | |
| gr.HTML( | |
| """ | |
| <script> | |
| function clearModule2Fields() { | |
| var ids = ["url1", "url2", "url3", "script_url1", "script_url2", "script_url3", "script1", "script2", "script3", "cleaned1", "cleaned2", "cleaned3", "copy_result1", "copy_result2", "copy_result3"]; | |
| ids.forEach(function(id) { | |
| var elem = document.getElementById(id); | |
| if (elem) { | |
| var textarea = elem.querySelector("textarea"); | |
| if (textarea) { | |
| textarea.value = ""; | |
| } else { | |
| elem.value = ""; | |
| } | |
| } | |
| }); | |
| } | |
| document.addEventListener("DOMContentLoaded", function(){ | |
| var buttons = document.getElementsByTagName("button"); | |
| for (var i = 0; i < buttons.length; i++) { | |
| if (buttons[i].textContent.trim() === "Submit") { | |
| buttons[i].addEventListener("click", function(){ | |
| clearModule2Fields(); | |
| }); | |
| } | |
| } | |
| }); | |
| </script> | |
| """ | |
| ) | |
| gr.Markdown("---") | |
| gr.Markdown("๋์์ ๊ฐ์ ๋ชฉ๋ก์์ ํ์ํ ๊ฐ์์ URL์ ๋ณต์ฌํด์ ๋ฃ์ด์ฃผ์ธ์") | |
| additional_demo.render() | |
| if __name__ == "__main__": | |
| logging.debug("ํตํฉ Gradio ์ฑ ์คํ ์ค") | |
| app.launch(debug=True) | |