unnastyle commited on
Commit
0ecc9da
ยท
verified ยท
1 Parent(s): 5c8884a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +163 -28
app.py CHANGED
@@ -1,12 +1,159 @@
 
 
1
  import gradio as gr
2
- import requests
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
- # ----- Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ -----
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
- demo.launch()
 
 
 
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)