Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,159 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
import re
|
| 4 |
import logging
|
|
|
|
| 5 |
|
| 6 |
-
# ๋๋ฒ๊น
๋ก๊น
์ค์
|
| 7 |
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 8 |
|
| 9 |
-
# ----- ๊ธฐ๋ณธ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def fetch_page_source(url):
|
| 11 |
try:
|
| 12 |
logging.debug(f"๊ฐ์ ํ์ด์ง๋ฅผ ๊ฐ์ ธ์ค๋ ์ค: {url}")
|
|
@@ -75,78 +222,56 @@ def remove_timeline(script_text, lecture_number):
|
|
| 75 |
cleaned_text = re.sub(r'^WEBVTT\s*', '', cleaned_text)
|
| 76 |
return cleaned_text
|
| 77 |
|
| 78 |
-
|
| 79 |
-
with gr.Blocks() as demo:
|
| 80 |
gr.Markdown("## ๊ฐ์ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ ์ธํฐํ์ด์ค")
|
| 81 |
gr.Markdown("โป ์๋ ์์๋๋ก ๊ฐ ๋จ๊ณ๋ณ ๋ฒํผ์ ๋๋ฌ ์งํํ์ธ์.")
|
| 82 |
-
|
| 83 |
-
# [1] ์
๋ ฅ์ฐฝ 3๊ฐ : ๊ฐ์1 URL, ๊ฐ์2 URL, ๊ฐ์3 URL (๊ฐ๋ก๋ก ๋์ด)
|
| 84 |
with gr.Row():
|
| 85 |
url1 = gr.Textbox(label="๊ฐ์1 URL")
|
| 86 |
url2 = gr.Textbox(label="๊ฐ์2 URL")
|
| 87 |
url3 = gr.Textbox(label="๊ฐ์3 URL")
|
| 88 |
-
|
| 89 |
-
# [2] ๋ฒํผ 3๊ฐ : ์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ (๊ฐ๊ฐ ์๋)
|
| 90 |
with gr.Row():
|
| 91 |
gen_url_btn1 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn1")
|
| 92 |
gen_url_btn2 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn2")
|
| 93 |
gen_url_btn3 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn3")
|
| 94 |
-
# ์ถ๋ ฅ์ฐฝ 3๊ฐ : ๊ฐ์1 ์คํฌ๋ฆฝํธ URL, ๊ฐ์2 ์คํฌ๋ฆฝํธ URL, ๊ฐ์3 ์คํฌ๋ฆฝํธ URL
|
| 95 |
with gr.Row():
|
| 96 |
script_url1 = gr.Textbox(label="๊ฐ์1 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url1")
|
| 97 |
script_url2 = gr.Textbox(label="๊ฐ์2 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url2")
|
| 98 |
script_url3 = gr.Textbox(label="๊ฐ์3 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url3")
|
| 99 |
-
|
| 100 |
-
# [3] ๋ฒํผ 3๊ฐ : ์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ (๊ฐ๊ฐ ์๋)
|
| 101 |
with gr.Row():
|
| 102 |
fetch_btn1 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn1")
|
| 103 |
fetch_btn2 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn2")
|
| 104 |
fetch_btn3 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn3")
|
| 105 |
-
# ์ถ๋ ฅ์ฐฝ 3๊ฐ : ๊ฐ์1 ์คํฌ๋ฆฝํธ, ๊ฐ์2 ์คํฌ๋ฆฝํธ, ๊ฐ์3 ์คํฌ๋ฆฝํธ
|
| 106 |
with gr.Row():
|
| 107 |
script1 = gr.Textbox(label="๊ฐ์1 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script1")
|
| 108 |
script2 = gr.Textbox(label="๊ฐ์2 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script2")
|
| 109 |
script3 = gr.Textbox(label="๊ฐ์3 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script3")
|
| 110 |
-
|
| 111 |
-
# [4] ๋ฒํผ 3๊ฐ : ํ์๋ผ์ธ ์ ๊ฑฐ (๊ฐ๊ฐ ์๋)
|
| 112 |
with gr.Row():
|
| 113 |
remove_btn1 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn1")
|
| 114 |
remove_btn2 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn2")
|
| 115 |
remove_btn3 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn3")
|
| 116 |
-
# ์ถ๋ ฅ์ฐฝ 3๊ฐ : ๊ฐ์1 ํ์๋ผ์ธ ์ ๊ฑฐ, ๊ฐ์2 ํ์๋ผ์ธ ์ ๊ฑฐ, ๊ฐ์3 ํ์๋ผ์ธ ์ ๊ฑฐ
|
| 117 |
with gr.Row():
|
| 118 |
cleaned1 = gr.Textbox(label="๊ฐ์1 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned1")
|
| 119 |
cleaned2 = gr.Textbox(label="๊ฐ์2 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned2")
|
| 120 |
cleaned3 = gr.Textbox(label="๊ฐ์3 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned3")
|
| 121 |
-
|
| 122 |
-
# [5] ๋ฒํผ 3๊ฐ : ๊ฐ์ ๋ด์ฉ ๋ณต์ฌ (๊ฐ๊ฐ ์๋, ๋ฒํผ ๊ธ์๋ง ๋ณ๊ฒฝ)
|
| 123 |
with gr.Row():
|
| 124 |
copy_btn1 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn1")
|
| 125 |
copy_btn2 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn2")
|
| 126 |
copy_btn3 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn3")
|
| 127 |
-
# ์ถ๋ ฅ์ฐฝ 3๊ฐ : ๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ, ๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ, ๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ
|
| 128 |
with gr.Row():
|
| 129 |
copy_result1 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result1")
|
| 130 |
copy_result2 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result2")
|
| 131 |
copy_result3 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result3")
|
| 132 |
|
| 133 |
-
# ----- ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ์ฐ๊ฒฐ (์๋ฒ์ธก ๊ธฐ๋ฅ) -----
|
| 134 |
-
# ์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ ๋ฒํผ (๊ฐ๊ฐ)
|
| 135 |
gen_url_btn1.click(fn=lambda url: create_script_url(url), inputs=url1, outputs=script_url1)
|
| 136 |
gen_url_btn2.click(fn=lambda url: create_script_url(url), inputs=url2, outputs=script_url2)
|
| 137 |
gen_url_btn3.click(fn=lambda url: create_script_url(url), inputs=url3, outputs=script_url3)
|
| 138 |
-
|
| 139 |
-
# ์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ ๋ฒํผ (๊ฐ๊ฐ)
|
| 140 |
fetch_btn1.click(fn=lambda url: fetch_script(url), inputs=script_url1, outputs=script1)
|
| 141 |
fetch_btn2.click(fn=lambda url: fetch_script(url), inputs=script_url2, outputs=script2)
|
| 142 |
fetch_btn3.click(fn=lambda url: fetch_script(url), inputs=script_url3, outputs=script3)
|
| 143 |
-
|
| 144 |
-
# ํ์๋ผ์ธ ์ ๊ฑฐ ๋ฒํผ (๊ฐ๊ฐ)
|
| 145 |
remove_btn1.click(fn=lambda script: remove_timeline(script, 1), inputs=script1, outputs=cleaned1)
|
| 146 |
remove_btn2.click(fn=lambda script: remove_timeline(script, 2), inputs=script2, outputs=cleaned2)
|
| 147 |
remove_btn3.click(fn=lambda script: remove_timeline(script, 3), inputs=script3, outputs=cleaned3)
|
| 148 |
|
| 149 |
-
# ----- ํด๋ผ์ด์ธํธ ์ฌ์ด๋: ๊ฐ์ ๋ด์ฉ ๋ณต์ฌ (JavaScript) -----
|
| 150 |
custom_script = """
|
| 151 |
<script>
|
| 152 |
function setupCopy(copyBtnId, textBoxId, resultBoxId) {
|
|
@@ -184,7 +309,17 @@ with gr.Blocks() as demo:
|
|
| 184 |
</script>
|
| 185 |
"""
|
| 186 |
gr.HTML(custom_script)
|
| 187 |
-
|
| 188 |
gr.Markdown("๋๋ฒ๊น
๋ชจ๋ ํ์ฑํ๋จ: ๋ก๊ทธ๊ฐ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
+
from bs4 import BeautifulSoup
|
| 5 |
import re
|
| 6 |
import logging
|
| 7 |
+
import requests # ์ถ๊ฐ์ฝ๋์์ ์ฌ์ฉ
|
| 8 |
|
| 9 |
+
# ๋๋ฒ๊น
๋ก๊น
์ค์ (์ ์ฒด ํตํฉ์ ์ํด ํฌ๋งท ํฌํจ)
|
| 10 |
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 11 |
|
| 12 |
+
# ---------- [๊ธฐ๋ณธ์ฝ๋] ์์ ----------
|
| 13 |
+
# ์์ด ์์ ํ๊ตญ์ด ์๋ก ๋ณํํ๊ธฐ ์ํ ๋งคํ
|
| 14 |
+
month_mapping = {
|
| 15 |
+
"January": "1์",
|
| 16 |
+
"February": "2์",
|
| 17 |
+
"March": "3์",
|
| 18 |
+
"April": "4์",
|
| 19 |
+
"May": "5์",
|
| 20 |
+
"June": "6์",
|
| 21 |
+
"July": "7์",
|
| 22 |
+
"August": "8์",
|
| 23 |
+
"September": "9์",
|
| 24 |
+
"October": "10์",
|
| 25 |
+
"November": "11์",
|
| 26 |
+
"December": "12์"
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
def convert_date_range(date_range_str):
|
| 30 |
+
"""
|
| 31 |
+
์
๋ ฅ๋ '6 January - 12 January' ํํ์ ๋ ์ง ๋ฌธ์์ด์
|
| 32 |
+
'1์ 6์ผ ~ 1์ 12์ผ' ํํ๋ก ๋ณํํ๋ ํจ์.
|
| 33 |
+
"""
|
| 34 |
+
logging.debug("์๋ณธ ๋ ์ง ๋ฒ์: %s", date_range_str)
|
| 35 |
+
parts = date_range_str.split('-')
|
| 36 |
+
if len(parts) != 2:
|
| 37 |
+
logging.debug("๋ ์ง ๋ฒ์ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์: %s", date_range_str)
|
| 38 |
+
return date_range_str
|
| 39 |
+
start = parts[0].strip() # ์: "6 January"
|
| 40 |
+
end = parts[1].strip() # ์: "12 January"
|
| 41 |
+
start_parts = start.split()
|
| 42 |
+
end_parts = end.split()
|
| 43 |
+
if len(start_parts) < 2 or len(end_parts) < 2:
|
| 44 |
+
logging.debug("๋ ์ง ๊ตฌ์ฑ์์ ๋ถ์กฑ: %s, %s", start, end)
|
| 45 |
+
return date_range_str
|
| 46 |
+
start_day = start_parts[0]
|
| 47 |
+
start_month_en = start_parts[1]
|
| 48 |
+
end_day = end_parts[0]
|
| 49 |
+
end_month_en = end_parts[1]
|
| 50 |
+
start_month = month_mapping.get(start_month_en, start_month_en)
|
| 51 |
+
end_month = month_mapping.get(end_month_en, end_month_en)
|
| 52 |
+
converted = f"{start_month} {start_day}์ผ ~ {end_month} {end_day}์ผ"
|
| 53 |
+
logging.debug("๋ณํ๋ ๋ ์ง ๋ฒ์: %s", converted)
|
| 54 |
+
return converted
|
| 55 |
+
|
| 56 |
+
def process_html(html_text):
|
| 57 |
+
"""
|
| 58 |
+
์ ์ฒด ํ์ด์ง HTML ์
๋ ฅ์ ๋ฐ์์ ๊ณผ๋ชฉ๋ช
๊ณผ ์น์
๋ณ ๋์์ ๊ฐ์ข ๋ชฉ๋ก์ ์ถ์ถํ๋ ํจ์.
|
| 59 |
+
|
| 60 |
+
์ถ์ถ ๊ท์น:
|
| 61 |
+
1. ๊ณผ๋ชฉ๋ช
: <h1> ํ๊ทธ ๋ด์ ํ
์คํธ๋ฅผ ์ฌ์ฉ.
|
| 62 |
+
2. ์น์
:
|
| 63 |
+
- <li> ํ๊ทธ์ id๊ฐ "section-X"์ธ ํญ๋ชฉ๋ค์ ์ํ.
|
| 64 |
+
- section-0๋ ๋ฌด์.
|
| 65 |
+
- section-1์ "Introduction"์ผ๋ก ํ๊ธฐ.
|
| 66 |
+
- section-2 ์ด์์ (section ๋ฒํธ - 1)์ฃผ์ฐจ๋ก ํ๊ธฐ.
|
| 67 |
+
- ๊ฐ ์น์
์ <h3 class="sectionname"> ๋ด๋ถ <a> ํ๊ทธ์ ํ
์คํธ์์ ๋ ์ง ๋ฒ์๋ฅผ ์ถ์ถํ์ฌ ๋ณํ.
|
| 68 |
+
- ๊ฐ ์น์
๋ด์ ๋ชจ๋ <iframe> ํ๊ทธ์ src ์์ฑ ๊ฐ์ ๋์์ URL๋ก ์ถ์ถ.
|
| 69 |
+
"""
|
| 70 |
+
logging.debug("์
๋ ฅ HTML ์ฒ๋ฆฌ ์์")
|
| 71 |
+
soup = BeautifulSoup(html_text, "html.parser")
|
| 72 |
+
|
| 73 |
+
# 1. ๊ณผ๋ชฉ๋ช
์ถ์ถ (h1 ํ๊ทธ ์ฌ์ฉ)
|
| 74 |
+
subject_elem = soup.find("h1")
|
| 75 |
+
subject_name = ""
|
| 76 |
+
if subject_elem:
|
| 77 |
+
subject_name = subject_elem.get_text(strip=True)
|
| 78 |
+
logging.debug("์ถ์ถ๋ ๊ณผ๋ชฉ๋ช
: %s", subject_name)
|
| 79 |
+
else:
|
| 80 |
+
logging.debug("h1 ํ๊ทธ๋ฅผ ์ฐพ์ง ๋ชปํจ")
|
| 81 |
+
|
| 82 |
+
# 2. ์น์
๋ณ ๋์์ ๊ฐ์ข ์ถ์ถ
|
| 83 |
+
sections_output = ""
|
| 84 |
+
section_elements = soup.find_all("li", id=re.compile(r"^section-\d+"))
|
| 85 |
+
logging.debug("์ฐพ์ ์น์
๊ฐ์: %d", len(section_elements))
|
| 86 |
+
|
| 87 |
+
for section in section_elements:
|
| 88 |
+
section_id = section.get("id")
|
| 89 |
+
logging.debug("์ฒ๋ฆฌ ์ค์ธ ์น์
ID: %s", section_id)
|
| 90 |
+
sec_match = re.search(r"section-(\d+)", section_id)
|
| 91 |
+
if not sec_match:
|
| 92 |
+
continue
|
| 93 |
+
sec_num = int(sec_match.group(1))
|
| 94 |
+
if sec_num == 0:
|
| 95 |
+
logging.debug("section-0 ์ ์คํต")
|
| 96 |
+
continue
|
| 97 |
+
|
| 98 |
+
# ์น์
๋ผ๋ฒจ ์ง์
|
| 99 |
+
if sec_num == 1:
|
| 100 |
+
section_label = "Introduction"
|
| 101 |
+
else:
|
| 102 |
+
week_num = sec_num - 1 # section-2๋ถํฐ 1์ฃผ์ฐจ, section-3์ 2์ฃผ์ฐจ ๋ฑ
|
| 103 |
+
section_label = f"{week_num}์ฃผ์ฐจ"
|
| 104 |
+
|
| 105 |
+
# ์น์
ํค๋์์ ๋ ์ง ๋ฒ์ ์ถ์ถ (h3 ํ๊ทธ ๋ด <a> ํ๊ทธ ํ
์คํธ)
|
| 106 |
+
h3_elem = section.find("h3", class_="sectionname")
|
| 107 |
+
date_range_text = ""
|
| 108 |
+
if h3_elem and h3_elem.find("a"):
|
| 109 |
+
header_text = h3_elem.find("a").get_text(strip=True)
|
| 110 |
+
logging.debug("ํค๋ ํ
์คํธ: %s", header_text)
|
| 111 |
+
date_match = re.search(r'(\d+\s+[A-Za-z]+\s*-\s*\d+\s+[A-Za-z]+)', header_text)
|
| 112 |
+
if date_match:
|
| 113 |
+
raw_date_range = date_match.group(1)
|
| 114 |
+
date_range_text = convert_date_range(raw_date_range)
|
| 115 |
+
else:
|
| 116 |
+
logging.debug("๋ ์ง ๋ฒ์ ํจํด ๋งค์นญ ์คํจ: %s", header_text)
|
| 117 |
+
else:
|
| 118 |
+
logging.debug("h3 ๋๋ h3 ๋ด a ํ๊ทธ๋ฅผ ์ฐพ์ง ๋ชปํจ for section: %s", section_id)
|
| 119 |
+
|
| 120 |
+
if sec_num == 1:
|
| 121 |
+
section_heading = f"์น์
: {section_label}"
|
| 122 |
+
else:
|
| 123 |
+
if date_range_text:
|
| 124 |
+
section_heading = f"์น์
: {section_label} ({date_range_text})"
|
| 125 |
+
else:
|
| 126 |
+
section_heading = f"์น์
: {section_label}"
|
| 127 |
+
|
| 128 |
+
sections_output += section_heading + "\n"
|
| 129 |
+
|
| 130 |
+
# ํด๋น ์น์
๋ด iframe ํ๊ทธ๋ก๋ถํฐ ๋์์ URL ์ถ์ถ
|
| 131 |
+
iframes = section.find_all("iframe")
|
| 132 |
+
logging.debug("์น์
%s ๋ด ์ฐพ์ iframe ๊ฐ์: %d", section_id, len(iframes))
|
| 133 |
+
for idx, iframe in enumerate(iframes, start=1):
|
| 134 |
+
video_url = iframe.get("src", "").strip()
|
| 135 |
+
if video_url:
|
| 136 |
+
sections_output += f"๊ฐ์ข{idx} : {video_url}\n"
|
| 137 |
+
logging.debug("์ถ์ถ๋ ๋์์ URL: %s", video_url)
|
| 138 |
+
sections_output += "\n"
|
| 139 |
+
|
| 140 |
+
logging.debug("HTML ์ฒ๋ฆฌ ์๋ฃ")
|
| 141 |
+
return subject_name, sections_output
|
| 142 |
+
|
| 143 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ (๊ธฐ๋ณธ์ฝ๋)
|
| 144 |
+
iface = gr.Interface(
|
| 145 |
+
fn=process_html,
|
| 146 |
+
inputs=gr.Textbox(label="์ ์ฒด ํ์ด์ง HTML ์
๋ ฅ", lines=20, placeholder="HTML ์ฝ๋๋ฅผ ์
๋ ฅํ์ธ์..."),
|
| 147 |
+
outputs=[
|
| 148 |
+
gr.Textbox(label="๊ณผ๋ชฉ๋ช
"),
|
| 149 |
+
gr.Textbox(label="๋์์ ๊ฐ์ข ๋ชฉ๋ก")
|
| 150 |
+
],
|
| 151 |
+
title="๋์์ ๊ฐ์ข ์ถ์ถ๊ธฐ",
|
| 152 |
+
description="์ ์ฒด ํ์ด์ง HTML์ ์
๋ ฅํ๋ฉด ๊ณผ๋ชฉ๋ช
๊ณผ ๊ฐ ์น์
๋ณ ๋์์ ๊ฐ์ข๋ฅผ ์ถ์ถํฉ๋๋ค. (๋๋ฒ๊น
์ ๋ณด๋ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.)"
|
| 153 |
+
)
|
| 154 |
+
# ---------- [๊ธฐ๋ณธ์ฝ๋] ๋ ----------
|
| 155 |
+
|
| 156 |
+
# ---------- [์ถ๊ฐ์ฝ๋] ์์ ----------
|
| 157 |
def fetch_page_source(url):
|
| 158 |
try:
|
| 159 |
logging.debug(f"๊ฐ์ ํ์ด์ง๋ฅผ ๊ฐ์ ธ์ค๋ ์ค: {url}")
|
|
|
|
| 222 |
cleaned_text = re.sub(r'^WEBVTT\s*', '', cleaned_text)
|
| 223 |
return cleaned_text
|
| 224 |
|
| 225 |
+
with gr.Blocks() as additional_demo:
|
|
|
|
| 226 |
gr.Markdown("## ๊ฐ์ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ ์ธํฐํ์ด์ค")
|
| 227 |
gr.Markdown("โป ์๋ ์์๋๋ก ๊ฐ ๋จ๊ณ๋ณ ๋ฒํผ์ ๋๋ฌ ์งํํ์ธ์.")
|
|
|
|
|
|
|
| 228 |
with gr.Row():
|
| 229 |
url1 = gr.Textbox(label="๊ฐ์1 URL")
|
| 230 |
url2 = gr.Textbox(label="๊ฐ์2 URL")
|
| 231 |
url3 = gr.Textbox(label="๊ฐ์3 URL")
|
|
|
|
|
|
|
| 232 |
with gr.Row():
|
| 233 |
gen_url_btn1 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn1")
|
| 234 |
gen_url_btn2 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn2")
|
| 235 |
gen_url_btn3 = gr.Button("์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", elem_id="gen_url_btn3")
|
|
|
|
| 236 |
with gr.Row():
|
| 237 |
script_url1 = gr.Textbox(label="๊ฐ์1 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url1")
|
| 238 |
script_url2 = gr.Textbox(label="๊ฐ์2 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url2")
|
| 239 |
script_url3 = gr.Textbox(label="๊ฐ์3 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url3")
|
|
|
|
|
|
|
| 240 |
with gr.Row():
|
| 241 |
fetch_btn1 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn1")
|
| 242 |
fetch_btn2 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn2")
|
| 243 |
fetch_btn3 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn3")
|
|
|
|
| 244 |
with gr.Row():
|
| 245 |
script1 = gr.Textbox(label="๊ฐ์1 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script1")
|
| 246 |
script2 = gr.Textbox(label="๊ฐ์2 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script2")
|
| 247 |
script3 = gr.Textbox(label="๊ฐ์3 ์คํฌ๋ฆฝํธ", lines=10, elem_id="script3")
|
|
|
|
|
|
|
| 248 |
with gr.Row():
|
| 249 |
remove_btn1 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn1")
|
| 250 |
remove_btn2 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn2")
|
| 251 |
remove_btn3 = gr.Button("ํ์๋ผ์ธ ์ ๊ฑฐ", elem_id="remove_btn3")
|
|
|
|
| 252 |
with gr.Row():
|
| 253 |
cleaned1 = gr.Textbox(label="๊ฐ์1 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned1")
|
| 254 |
cleaned2 = gr.Textbox(label="๊ฐ์2 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned2")
|
| 255 |
cleaned3 = gr.Textbox(label="๊ฐ์3 ํ์๋ผ์ธ ์ ๊ฑฐ", lines=10, interactive=False, elem_id="cleaned3")
|
|
|
|
|
|
|
| 256 |
with gr.Row():
|
| 257 |
copy_btn1 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn1")
|
| 258 |
copy_btn2 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn2")
|
| 259 |
copy_btn3 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌ", elem_id="copy_btn3")
|
|
|
|
| 260 |
with gr.Row():
|
| 261 |
copy_result1 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result1")
|
| 262 |
copy_result2 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result2")
|
| 263 |
copy_result3 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result3")
|
| 264 |
|
|
|
|
|
|
|
| 265 |
gen_url_btn1.click(fn=lambda url: create_script_url(url), inputs=url1, outputs=script_url1)
|
| 266 |
gen_url_btn2.click(fn=lambda url: create_script_url(url), inputs=url2, outputs=script_url2)
|
| 267 |
gen_url_btn3.click(fn=lambda url: create_script_url(url), inputs=url3, outputs=script_url3)
|
|
|
|
|
|
|
| 268 |
fetch_btn1.click(fn=lambda url: fetch_script(url), inputs=script_url1, outputs=script1)
|
| 269 |
fetch_btn2.click(fn=lambda url: fetch_script(url), inputs=script_url2, outputs=script2)
|
| 270 |
fetch_btn3.click(fn=lambda url: fetch_script(url), inputs=script_url3, outputs=script3)
|
|
|
|
|
|
|
| 271 |
remove_btn1.click(fn=lambda script: remove_timeline(script, 1), inputs=script1, outputs=cleaned1)
|
| 272 |
remove_btn2.click(fn=lambda script: remove_timeline(script, 2), inputs=script2, outputs=cleaned2)
|
| 273 |
remove_btn3.click(fn=lambda script: remove_timeline(script, 3), inputs=script3, outputs=cleaned3)
|
| 274 |
|
|
|
|
| 275 |
custom_script = """
|
| 276 |
<script>
|
| 277 |
function setupCopy(copyBtnId, textBoxId, resultBoxId) {
|
|
|
|
| 309 |
</script>
|
| 310 |
"""
|
| 311 |
gr.HTML(custom_script)
|
|
|
|
| 312 |
gr.Markdown("๋๋ฒ๊น
๋ชจ๋ ํ์ฑํ๋จ: ๋ก๊ทธ๊ฐ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.")
|
| 313 |
+
# ---------- [์ถ๊ฐ์ฝ๋] ๋ ----------
|
| 314 |
+
|
| 315 |
+
# ---------- ํตํฉ Gradio ์ฑ ๊ตฌ์ฑ ----------
|
| 316 |
+
with gr.Blocks() as app:
|
| 317 |
+
with gr.Tabs():
|
| 318 |
+
with gr.TabItem("๋์์ ๊ฐ์ข ์ถ์ถ๊ธฐ"):
|
| 319 |
+
iface.render()
|
| 320 |
+
with gr.TabItem("๊ฐ์ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ ์ธํฐํ์ด์ค"):
|
| 321 |
+
additional_demo.render()
|
| 322 |
|
| 323 |
+
if __name__ == "__main__":
|
| 324 |
+
logging.debug("ํตํฉ Gradio ์ฑ ์คํ ์ค")
|
| 325 |
+
app.launch(debug=True)
|