Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 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")
|
|
@@ -207,26 +205,25 @@ def remove_timeline(script_text, lecture_number):
|
|
| 207 |
stripped_line = line.strip()
|
| 208 |
if stripped_line == "":
|
| 209 |
continue
|
| 210 |
-
# ๋ฒํธ๋ง ์๋ ์ค ์ ๊ฑฐ
|
| 211 |
if re.match(r'^\d+$', stripped_line):
|
| 212 |
continue
|
| 213 |
-
# ํ์๋ผ์ธ ํ์ ์ ๊ฑฐ (์: 00:00:00.000 --> 00:00:02.000)
|
| 214 |
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):
|
| 215 |
continue
|
| 216 |
valid_lines.append(stripped_line)
|
| 217 |
cleaned_text = "".join(valid_lines)
|
| 218 |
-
# ๋ง์นจํ(.) ๋ค์์ ์ฌ๋ฐฑ์ด ์์ผ๋ฉด ์ฌ๋ฐฑ ์ถ๊ฐ
|
| 219 |
cleaned_text = re.sub(r'\.(\S)', r'. \1', cleaned_text)
|
| 220 |
-
# ๊ธ ๊ฐ์ฅ ์์ ์๋ "WEBVTT" ์ ๊ฑฐ
|
| 221 |
cleaned_text = re.sub(r'^WEBVTT\s*', '', cleaned_text)
|
| 222 |
return cleaned_text
|
| 223 |
|
|
|
|
|
|
|
|
|
|
| 224 |
# ์๋ก์ด ์ ์ฒด ์ฒ๋ฆฌ ํจ์: ๊ฐ์ URL -> ์คํฌ๋ฆฝํธ URL ์์ฑ -> ์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ -> ํ์๋ผ์ธ ์ ๊ฑฐ
|
| 225 |
def process_full(lecture_url):
|
| 226 |
"""
|
| 227 |
์
๋ ฅ๋ ๊ฐ์ URL๋ก๋ถํฐ ์คํฌ๋ฆฝํธ URL์ ์์ฑํ๊ณ ,
|
| 228 |
ํด๋น ์คํฌ๋ฆฝํธ๋ฅผ ๊ฐ์ ธ์จ ํ ํ์๋ผ์ธ์ ์ ๊ฑฐํ ์ต์ข
๊ฐ์ ๋ด์ฉ์ ๋ฐํํ๋ ํจ์.
|
| 229 |
-
์ค๊ฐ ๋จ๊ณ๋ ์ถ๋ ฅํ์ง ์๊ณ ์ต์ข
๊ฒฐ๊ณผ๋ง ๋ฐํ
|
| 230 |
"""
|
| 231 |
script_url = create_script_url(lecture_url)
|
| 232 |
if not script_url:
|
|
@@ -236,59 +233,39 @@ def process_full(lecture_url):
|
|
| 236 |
if "์ค๋ฅ ๋ฐ์" in script_text:
|
| 237 |
return script_text
|
| 238 |
|
| 239 |
-
cleaned = remove_timeline(script_text, 1)
|
| 240 |
return cleaned
|
| 241 |
|
|
|
|
| 242 |
with gr.Blocks() as additional_demo:
|
| 243 |
-
#
|
| 244 |
-
gr.Markdown("โป
|
| 245 |
with gr.Row():
|
| 246 |
url1 = gr.Textbox(label="๊ฐ์1 URL", elem_id="url1")
|
| 247 |
url2 = gr.Textbox(label="๊ฐ์2 URL", elem_id="url2")
|
| 248 |
url3 = gr.Textbox(label="๊ฐ์3 URL", elem_id="url3")
|
| 249 |
with gr.Row():
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
with gr.Row():
|
| 254 |
-
script_url1 = gr.Textbox(label="๊ฐ์1 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url1")
|
| 255 |
-
script_url2 = gr.Textbox(label="๊ฐ์2 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url2")
|
| 256 |
-
script_url3 = gr.Textbox(label="๊ฐ์3 ์คํฌ๋ฆฝํธ URL", interactive=False, elem_id="script_url3")
|
| 257 |
-
with gr.Row():
|
| 258 |
-
fetch_btn1 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn1")
|
| 259 |
-
fetch_btn2 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn2")
|
| 260 |
-
fetch_btn3 = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_btn3")
|
| 261 |
with gr.Row():
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
with gr.Row():
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
with gr.Row():
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
copy_result2 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result2")
|
| 280 |
-
copy_result3 = gr.Textbox(label="๊ฐ์ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result3")
|
| 281 |
-
|
| 282 |
-
gen_url_btn1.click(fn=lambda url: create_script_url(url), inputs=url1, outputs=script_url1)
|
| 283 |
-
gen_url_btn2.click(fn=lambda url: create_script_url(url), inputs=url2, outputs=script_url2)
|
| 284 |
-
gen_url_btn3.click(fn=lambda url: create_script_url(url), inputs=url3, outputs=script_url3)
|
| 285 |
-
fetch_btn1.click(fn=lambda url: fetch_script(url), inputs=script_url1, outputs=script1)
|
| 286 |
-
fetch_btn2.click(fn=lambda url: fetch_script(url), inputs=script_url2, outputs=script2)
|
| 287 |
-
fetch_btn3.click(fn=lambda url: fetch_script(url), inputs=script_url3, outputs=script3)
|
| 288 |
-
remove_btn1.click(fn=lambda script: remove_timeline(script, 1), inputs=script1, outputs=cleaned1)
|
| 289 |
-
remove_btn2.click(fn=lambda script: remove_timeline(script, 2), inputs=script2, outputs=cleaned2)
|
| 290 |
-
remove_btn3.click(fn=lambda script: remove_timeline(script, 3), inputs=script3, outputs=cleaned3)
|
| 291 |
-
|
| 292 |
custom_script = """
|
| 293 |
<script>
|
| 294 |
function setupCopy(copyBtnId, textBoxId, resultBoxId) {
|
|
@@ -319,9 +296,9 @@ with gr.Blocks() as additional_demo:
|
|
| 319 |
});
|
| 320 |
}
|
| 321 |
document.addEventListener("DOMContentLoaded", function(){
|
| 322 |
-
setupCopy("copy_btn1", "
|
| 323 |
-
setupCopy("copy_btn2", "
|
| 324 |
-
setupCopy("copy_btn3", "
|
| 325 |
});
|
| 326 |
</script>
|
| 327 |
"""
|
|
@@ -329,14 +306,6 @@ with gr.Blocks() as additional_demo:
|
|
| 329 |
gr.Markdown("๋๋ฒ๊น
๋ชจ๋ ํ์ฑํ๋จ: ๋ก๊ทธ๊ฐ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.")
|
| 330 |
# ---------- [๋ชจ๋2: ์ถ๊ฐ์ฝ๋] ๋ ----------
|
| 331 |
|
| 332 |
-
# ์๋ก์ด ์ ์ฒด ์ฒ๋ฆฌ ์ธํฐํ์ด์ค: ๊ฐ์ URL -> ํ์๋ผ์ธ ์ ๊ฑฐ ๊ฒฐ๊ณผ๋ง ๋ฐํ
|
| 333 |
-
full_interface = gr.Interface(
|
| 334 |
-
fn=process_full,
|
| 335 |
-
inputs=gr.Textbox(label="๊ฐ์ URL", placeholder="๊ฐ์ URL์ ์
๋ ฅํ์ธ์..."),
|
| 336 |
-
outputs=gr.Textbox(label="ํ์๋ผ์ธ ์ ๊ฑฐ ๊ฒฐ๊ณผ", lines=10),
|
| 337 |
-
description="๊ฐ์ URL์ ์
๋ ฅํ๋ฉด ์คํฌ๋ฆฝํธ URL ์์ฑ, ์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ, ํ์๋ผ์ธ ์ ๊ฑฐ๊น์ง ํ ๋ฒ์ ์ํํฉ๋๋ค."
|
| 338 |
-
)
|
| 339 |
-
|
| 340 |
# ---------- ํตํฉ Gradio ์ฑ ๊ตฌ์ฑ (ํ ํ์ด์ง์ ๋ชจ๋ ํ์) ----------
|
| 341 |
with gr.Blocks() as app:
|
| 342 |
gr.Markdown("# ์บ๋กค๋ผ์ธ๋ํ ๊ฐ์ ์ถ์ถ๊ธฐ")
|
|
@@ -347,56 +316,86 @@ with gr.Blocks() as app:
|
|
| 347 |
<strong>์ฌ์ฉ๋ฐฉ๋ฒ</strong>
|
| 348 |
<ol>
|
| 349 |
<li>์ถ์ถ์ ์ํ๋ ๊ฐ์ ํ์ด์ง์์ "Ctrl + U"๋ฅผ ๋๋ฅด๊ณ "ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
|
| 350 |
-
๋๋ ํด๋นํ์ด์ง์์ ๋ง์ฐ์ค ์ฐํด๋ฆญ ํ "ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํด๋ฆญ (์ฃ์ง์ ๊ฒฝ์ฐ "ํ์ด์ง ์๋ณธ ๋ณด๊ธฐ")</li>
|
| 351 |
-
<li>"ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํ์ด์ง์์ ์ ์ฒด ๋ณต์ฌ๋ฅผ ํฉ๋๋ค. "Ctrl+A"
|
| 352 |
-
<li>"์ ์ฒด ํ์ด์ง HTML ์
๋ ฅ"์ฐฝ์ ๋ณต์ฌํ ๋ด์ฉ์ ๋ถ
|
| 353 |
<li>"Submit" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋์์ ๊ฐ์ ๋ชฉ๋ก๏ฟฝ๏ฟฝ๏ฟฝ ๋์ต๋๋ค.</li>
|
| 354 |
-
<li>๋ด์ฉ ์ถ์ถ์ ์ํ๋ ๊ฐ์ URL์ ๋ณต์ฌํด์ ์๋ "๊ฐ์ URL" ์ฐฝ์ ๋ถ
|
| 355 |
-
<li>
|
| 356 |
-
<li>๊ฐ๊ฐ ์ถ์ถ๋ ๊ฐ์ ๋ด์ฉ์ "ChatGPT"์
|
| 357 |
</ol>
|
| 358 |
</div>
|
| 359 |
"""
|
| 360 |
)
|
| 361 |
iface.render()
|
| 362 |
-
|
| 363 |
-
gr.
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
} else {
|
| 375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
}
|
| 377 |
}
|
| 378 |
-
});
|
| 379 |
-
}
|
| 380 |
-
document.addEventListener("DOMContentLoaded", function(){
|
| 381 |
-
var buttons = document.getElementsByTagName("button");
|
| 382 |
-
for (var i = 0; i < buttons.length; i++) {
|
| 383 |
-
if (buttons[i].textContent.trim() === "Submit") {
|
| 384 |
-
buttons[i].addEventListener("click", function(){
|
| 385 |
-
clearModule2Fields();
|
| 386 |
-
});
|
| 387 |
-
}
|
| 388 |
}
|
| 389 |
});
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
gr.
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
if __name__ == "__main__":
|
| 401 |
logging.debug("ํตํฉ Gradio ์ฑ ์คํ ์ค")
|
| 402 |
app.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
import re
|
| 4 |
import logging
|
| 5 |
+
import requests
|
| 6 |
|
| 7 |
# ๋๋ฒ๊น
๋ก๊น
์ค์ (์ ์ฒด ํตํฉ์ ์ํด ํฌ๋งท ํฌํจ)
|
| 8 |
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
|
|
|
|
| 205 |
stripped_line = line.strip()
|
| 206 |
if stripped_line == "":
|
| 207 |
continue
|
|
|
|
| 208 |
if re.match(r'^\d+$', stripped_line):
|
| 209 |
continue
|
|
|
|
| 210 |
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):
|
| 211 |
continue
|
| 212 |
valid_lines.append(stripped_line)
|
| 213 |
cleaned_text = "".join(valid_lines)
|
|
|
|
| 214 |
cleaned_text = re.sub(r'\.(\S)', r'. \1', cleaned_text)
|
|
|
|
| 215 |
cleaned_text = re.sub(r'^WEBVTT\s*', '', cleaned_text)
|
| 216 |
return cleaned_text
|
| 217 |
|
| 218 |
+
# ๊ธฐ์กด์ "์คํฌ๋ฆฝํธ URL ๋ง๋ค๊ธฐ", "์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ", "ํ์๋ผ์ธ ์ ๊ฑฐ" ๊ด๋ จ ์ปดํฌ๋ํธ๋ ์ ๊ฑฐํ๊ณ ,
|
| 219 |
+
# ์๋ [๋ชจ๋2 ๊ตฌ์กฐ]์ ๋ง๊ฒ ์๋กญ๊ฒ ๊ตฌ์ฑํฉ๋๋ค.
|
| 220 |
+
|
| 221 |
# ์๋ก์ด ์ ์ฒด ์ฒ๋ฆฌ ํจ์: ๊ฐ์ URL -> ์คํฌ๋ฆฝํธ URL ์์ฑ -> ์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ -> ํ์๋ผ์ธ ์ ๊ฑฐ
|
| 222 |
def process_full(lecture_url):
|
| 223 |
"""
|
| 224 |
์
๋ ฅ๋ ๊ฐ์ URL๋ก๋ถํฐ ์คํฌ๋ฆฝํธ URL์ ์์ฑํ๊ณ ,
|
| 225 |
ํด๋น ์คํฌ๋ฆฝํธ๋ฅผ ๊ฐ์ ธ์จ ํ ํ์๋ผ์ธ์ ์ ๊ฑฐํ ์ต์ข
๊ฐ์ ๋ด์ฉ์ ๋ฐํํ๋ ํจ์.
|
| 226 |
+
(์ค๊ฐ ๋จ๊ณ๋ ์ถ๋ ฅํ์ง ์๊ณ ์ต์ข
๊ฒฐ๊ณผ๋ง ๋ฐํ)
|
| 227 |
"""
|
| 228 |
script_url = create_script_url(lecture_url)
|
| 229 |
if not script_url:
|
|
|
|
| 233 |
if "์ค๋ฅ ๋ฐ์" in script_text:
|
| 234 |
return script_text
|
| 235 |
|
| 236 |
+
cleaned = remove_timeline(script_text, 1)
|
| 237 |
return cleaned
|
| 238 |
|
| 239 |
+
# [๋ชจ๋2 ๊ตฌ์กฐ]
|
| 240 |
with gr.Blocks() as additional_demo:
|
| 241 |
+
# ์๋ด ๋ฌธ๊ตฌ ์์
|
| 242 |
+
gr.Markdown("โป '๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ' ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํด๋น ์์์ ๊ฐ์ ๋ด์ฉ์ ์ถ์ถํ ์ ์์ต๋๋ค.")
|
| 243 |
with gr.Row():
|
| 244 |
url1 = gr.Textbox(label="๊ฐ์1 URL", elem_id="url1")
|
| 245 |
url2 = gr.Textbox(label="๊ฐ์2 URL", elem_id="url2")
|
| 246 |
url3 = gr.Textbox(label="๊ฐ์3 URL", elem_id="url3")
|
| 247 |
with gr.Row():
|
| 248 |
+
get_btn1 = gr.Button("๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ", elem_id="get_btn1")
|
| 249 |
+
get_btn2 = gr.Button("๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ", elem_id="get_btn2")
|
| 250 |
+
get_btn3 = gr.Button("๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ", elem_id="get_btn3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
with gr.Row():
|
| 252 |
+
lecture_content1 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content1")
|
| 253 |
+
lecture_content2 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content2")
|
| 254 |
+
lecture_content3 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content3")
|
| 255 |
with gr.Row():
|
| 256 |
+
copy_btn1 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn1")
|
| 257 |
+
copy_btn2 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn2")
|
| 258 |
+
copy_btn3 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn3")
|
| 259 |
with gr.Row():
|
| 260 |
+
copy_result1 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result1")
|
| 261 |
+
copy_result2 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result2")
|
| 262 |
+
copy_result3 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result3")
|
| 263 |
+
|
| 264 |
+
get_btn1.click(fn=lambda url: process_full(url), inputs=url1, outputs=lecture_content1)
|
| 265 |
+
get_btn2.click(fn=lambda url: process_full(url), inputs=url2, outputs=lecture_content2)
|
| 266 |
+
get_btn3.click(fn=lambda url: process_full(url), inputs=url3, outputs=lecture_content3)
|
| 267 |
+
|
| 268 |
+
# ๊ฐ์ ๋ด์ฉ ๋ณต์ฌ ๊ธฐ๋ฅ์ ํด๋ผ์ด์ธํธ ์ฌ์ด๋ JavaScript๋ก ์ฒ๋ฆฌํฉ๋๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
custom_script = """
|
| 270 |
<script>
|
| 271 |
function setupCopy(copyBtnId, textBoxId, resultBoxId) {
|
|
|
|
| 296 |
});
|
| 297 |
}
|
| 298 |
document.addEventListener("DOMContentLoaded", function(){
|
| 299 |
+
setupCopy("copy_btn1", "lecture_content1", "copy_result1");
|
| 300 |
+
setupCopy("copy_btn2", "lecture_content2", "copy_result2");
|
| 301 |
+
setupCopy("copy_btn3", "lecture_content3", "copy_result3");
|
| 302 |
});
|
| 303 |
</script>
|
| 304 |
"""
|
|
|
|
| 306 |
gr.Markdown("๋๋ฒ๊น
๋ชจ๋ ํ์ฑํ๋จ: ๋ก๊ทธ๊ฐ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.")
|
| 307 |
# ---------- [๋ชจ๋2: ์ถ๊ฐ์ฝ๋] ๋ ----------
|
| 308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
# ---------- ํตํฉ Gradio ์ฑ ๊ตฌ์ฑ (ํ ํ์ด์ง์ ๋ชจ๋ ํ์) ----------
|
| 310 |
with gr.Blocks() as app:
|
| 311 |
gr.Markdown("# ์บ๋กค๋ผ์ธ๋ํ ๊ฐ์ ์ถ์ถ๊ธฐ")
|
|
|
|
| 316 |
<strong>์ฌ์ฉ๋ฐฉ๋ฒ</strong>
|
| 317 |
<ol>
|
| 318 |
<li>์ถ์ถ์ ์ํ๋ ๊ฐ์ ํ์ด์ง์์ "Ctrl + U"๋ฅผ ๋๋ฅด๊ณ "ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
|
| 319 |
+
๋๋ ํด๋น ํ์ด์ง์์ ๋ง์ฐ์ค ์ฐํด๋ฆญ ํ "ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํด๋ฆญ (์ฃ์ง์ ๊ฒฝ์ฐ "ํ์ด์ง ์๋ณธ ๋ณด๊ธฐ")</li>
|
| 320 |
+
<li>"ํ์ด์ง ์์ค ๋ณด๊ธฐ" ํ์ด์ง์์ ์ ์ฒด ๋ณต์ฌ๋ฅผ ํฉ๋๋ค. ("Ctrl+A" ํ "Ctrl+C")</li>
|
| 321 |
+
<li>"์ ์ฒด ํ์ด์ง HTML ์
๋ ฅ"์ฐฝ์ ๋ณต์ฌํ ๋ด์ฉ์ ๋ถ์ฌ๋ฃ๊ธฐ ํฉ๋๋ค. ("Ctrl+V")</li>
|
| 322 |
<li>"Submit" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋์์ ๊ฐ์ ๋ชฉ๋ก๏ฟฝ๏ฟฝ๏ฟฝ ๋์ต๋๋ค.</li>
|
| 323 |
+
<li>๋ด์ฉ ์ถ์ถ์ ์ํ๋ ๊ฐ์ URL์ ๋ณต์ฌํด์ ์๋ "๊ฐ์ URL" ์ฐฝ์ ๋ถ์ฌ๋ฃ๊ธฐ ํฉ๋๋ค.</li>
|
| 324 |
+
<li>"๊ฐ์๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํด๋น ์์์ ๊ฐ์ ๋ด์ฉ์ ์ถ์ถํ ์ ์์ต๋๋ค.</li>
|
| 325 |
+
<li>๊ฐ๊ฐ ์ถ์ถ๋ ๊ฐ์ ๋ด์ฉ์ "ChatGPT"์ ๋ถ์ฌ๋ฃ๊ณ ๊ฐ์ ์์ฝ์ ์์ฒญํ๋ฉด ๋ฉ๋๋ค.</li>
|
| 326 |
</ol>
|
| 327 |
</div>
|
| 328 |
"""
|
| 329 |
)
|
| 330 |
iface.render()
|
| 331 |
+
gr.Markdown("---")
|
| 332 |
+
gr.Markdown("๋์์ ๊ฐ์ ๋ชฉ๋ก์์ ํ์ํ ๊ฐ์์ URL์ ๋ณต์ฌํด์ ๋ฃ์ด์ฃผ์ธ์")
|
| 333 |
+
additional_demo.render()
|
| 334 |
+
|
| 335 |
+
# ---------- [๋ชจ๋3: ๊ฐ์๋ด์ฉ ํฉ์น๊ธฐ ์ถ๊ฐ์ฝ๋] ์์ ----------
|
| 336 |
+
gr.Markdown("## ๊ฐ์๋ด์ฉ ํฉ์น๊ธฐ")
|
| 337 |
+
with gr.Row():
|
| 338 |
+
merge_btn = gr.Button("๊ฐ์๋ด์ฉ ํฉ์น๊ธฐ", elem_id="merge_btn")
|
| 339 |
+
merged_content = gr.Textbox(label="์ ์ฒด ๊ฐ์ ๋ด์ฉ", lines=10, elem_id="merged_content")
|
| 340 |
+
with gr.Row():
|
| 341 |
+
merge_copy_btn = gr.Button("์ ์ฒด ๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="merge_copy_btn")
|
| 342 |
+
merge_copy_result = gr.Textbox(label="์ ์ฒด ๊ฐ์ ๋ด์ฉ ๋ณต์ฌ ๊ฒฐ๊ณผ", interactive=False, elem_id="merge_copy_result")
|
| 343 |
+
|
| 344 |
+
def merge_contents(l1, l2, l3):
|
| 345 |
+
merged = ""
|
| 346 |
+
if l1.strip():
|
| 347 |
+
merged += "[๊ฐ์1]\n" + l1.strip()
|
| 348 |
+
if l2.strip():
|
| 349 |
+
if merged:
|
| 350 |
+
merged += "\n\n"
|
| 351 |
+
merged += "[๊ฐ์2]\n" + l2.strip()
|
| 352 |
+
if l3.strip():
|
| 353 |
+
if merged:
|
| 354 |
+
merged += "\n\n"
|
| 355 |
+
merged += "[๊ฐ์3]\n" + l3.strip()
|
| 356 |
+
return merged
|
| 357 |
+
|
| 358 |
+
merge_btn.click(fn=merge_contents, inputs=[lecture_content1, lecture_content2, lecture_content3], outputs=merged_content)
|
| 359 |
+
|
| 360 |
+
# ์ ์ฒด ๊ฐ์ ๋ด์ฉ ๋ณต์ฌ ๊ธฐ๋ฅ์ ์ํ ํด๋ผ์ด์ธํธ ์ฌ์ด๋ JavaScript ์ถ๊ฐ
|
| 361 |
+
merge_copy_script = """
|
| 362 |
+
<script>
|
| 363 |
+
function setupMergeCopy(copyBtnId, textBoxId, resultBoxId) {
|
| 364 |
+
const copyBtn = document.getElementById(copyBtnId);
|
| 365 |
+
if (!copyBtn) {
|
| 366 |
+
console.error("๋ฒํผ " + copyBtnId + "๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.");
|
| 367 |
+
return;
|
| 368 |
+
}
|
| 369 |
+
copyBtn.addEventListener("click", function(){
|
| 370 |
+
const textBoxElem = document.getElementById(textBoxId);
|
| 371 |
+
const resultBoxElem = document.getElementById(resultBoxId);
|
| 372 |
+
if(textBoxElem && resultBoxElem) {
|
| 373 |
+
const textarea = textBoxElem.querySelector("textarea");
|
| 374 |
+
const resultTextarea = resultBoxElem.querySelector("textarea");
|
| 375 |
+
if(textarea && resultTextarea) {
|
| 376 |
+
var text = textarea.value;
|
| 377 |
+
if(text.trim() === ""){
|
| 378 |
+
resultTextarea.value = "๋ณต์ฌํ ๋ด์ฉ์ด ์์ต๋๋ค.";
|
| 379 |
} else {
|
| 380 |
+
navigator.clipboard.writeText(text).then(function(){
|
| 381 |
+
resultTextarea.value = "๋ณต์ฌ์๋ฃ";
|
| 382 |
+
}, function(err){
|
| 383 |
+
resultTextarea.value = "๋ณต์ฌ ์คํจ";
|
| 384 |
+
});
|
| 385 |
}
|
| 386 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
}
|
| 388 |
});
|
| 389 |
+
}
|
| 390 |
+
document.addEventListener("DOMContentLoaded", function(){
|
| 391 |
+
setupMergeCopy("merge_copy_btn", "merged_content", "merge_copy_result");
|
| 392 |
+
});
|
| 393 |
+
</script>
|
| 394 |
+
"""
|
| 395 |
+
gr.HTML(merge_copy_script)
|
| 396 |
+
# ---------- [๋ชจ๋3: ๊ฐ์๋ด์ฉ ํฉ์น๊ธฐ ์ถ๊ฐ์ฝ๋] ๋ ----------
|
| 397 |
+
|
| 398 |
+
# ---------- ํตํฉ Gradio ์ฑ ๊ตฌ์ฑ ๋ ----------
|
| 399 |
if __name__ == "__main__":
|
| 400 |
logging.debug("ํตํฉ Gradio ์ฑ ์คํ ์ค")
|
| 401 |
app.launch(debug=True)
|