Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,21 +7,6 @@ import requests
|
|
| 7 |
# ๋๋ฒ๊น
๋ก๊น
์ค์ (์ ์ฒด ํตํฉ์ ์ํด ํฌ๋งท ํฌํจ)
|
| 8 |
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 9 |
|
| 10 |
-
# ---------- ์ฌ์ฉ์ ์ ์ CSS (์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ ์์ญ์ ๋์ด๋ฅผ ๋์ผํ๊ฒ ๋ง์ถค) ----------
|
| 11 |
-
css = """
|
| 12 |
-
<style>
|
| 13 |
-
/* ์ผ์ชฝ '์ ์ฒด ํ์ด์ง HTML ์
๋ ฅ' ์์ญ์ textarea ๋์ด ์ค์ */
|
| 14 |
-
#html_input textarea {
|
| 15 |
-
height: 400px !important;
|
| 16 |
-
}
|
| 17 |
-
/* ์ค๋ฅธ์ชฝ ์์ญ์ ๊ฐ์ธ๋ ์ปจํ
์ด๋์ ๋์ด ์ค์ */
|
| 18 |
-
#right_panel {
|
| 19 |
-
height: 400px;
|
| 20 |
-
overflow-y: auto;
|
| 21 |
-
}
|
| 22 |
-
</style>
|
| 23 |
-
"""
|
| 24 |
-
|
| 25 |
# ---------- [๋ชจ๋1: ๊ธฐ์กด ๊ธฐ๋ณธ์ฝ๋] ์์ ----------
|
| 26 |
# ์์ด ์์ ํ๊ตญ์ด ์๋ก ๋ณํํ๊ธฐ ์ํ ๋งคํ
|
| 27 |
month_mapping = {
|
|
@@ -228,13 +213,14 @@ def update_lecture_and_urls(selected_section, sections_dict):
|
|
| 228 |
์ ํํ ์น์
์ ๋ฐํ์ผ๋ก ๊ฐ์ ๋ชฉ๋ก ํ
์คํธ์ URL๋ค์ ์ถ์ถํ์ฌ
|
| 229 |
- ๊ฐ์ ๋ชฉ๋ก ํ
์คํธ(์์ผ๋ฉด "๊ฐ์๊ฐ ์์ต๋๋ค" ๋ฐํ)
|
| 230 |
- ์ต๋ 3๊ฐ์ ๊ฐ์ URL (๊ฐ์ URL์ด ์์ผ๋ฉด ๋น ๋ฌธ์์ด)
|
| 231 |
-
|
| 232 |
"""
|
| 233 |
if not selected_section or not sections_dict:
|
| 234 |
return "", "", "", ""
|
| 235 |
lectures_text, url_list = sections_dict.get(selected_section, ("", []))
|
| 236 |
if not lectures_text:
|
| 237 |
lectures_text = "๊ฐ์๊ฐ ์์ต๋๋ค"
|
|
|
|
| 238 |
url1 = url_list[0] if len(url_list) >= 1 else ""
|
| 239 |
url2 = url_list[1] if len(url_list) >= 2 else ""
|
| 240 |
url3 = url_list[2] if len(url_list) >= 3 else ""
|
|
@@ -323,6 +309,7 @@ def process_full(lecture_url):
|
|
| 323 |
"""
|
| 324 |
์
๋ ฅ๋ ๊ฐ์ URL๋ก๋ถํฐ ์คํฌ๋ฆฝํธ URL์ ์์ฑํ๊ณ ,
|
| 325 |
ํด๋น ์คํฌ๋ฆฝํธ๋ฅผ ๊ฐ์ ธ์จ ํ ํ์๋ผ์ธ์ ์ ๊ฑฐํ ์ต์ข
๊ฐ์ ๋ด์ฉ์ ๋ฐํํ๋ ํจ์.
|
|
|
|
| 326 |
"""
|
| 327 |
script_url = create_script_url(lecture_url)
|
| 328 |
if not script_url:
|
|
@@ -339,6 +326,7 @@ def process_full(lecture_url):
|
|
| 339 |
# ---------- [๋ชจ๋3: ๊ฐ์ ๋ด์ฉ ํฉ์น๊ธฐ ์ถ๊ฐ์ฝ๋] ์์ ----------
|
| 340 |
with gr.Blocks() as merge_demo:
|
| 341 |
gr.Markdown("## ๊ฐ์ ๋ด์ฉ ํฉ์น๊ธฐ")
|
|
|
|
| 342 |
merged_content = gr.Textbox(label="์ ์ฒด ๊ฐ์ ๋ด์ฉ", lines=10, elem_id="merged_content")
|
| 343 |
with gr.Row():
|
| 344 |
merge_copy_btn = gr.Button("์ ์ฒด ๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="merge_copy_btn")
|
|
@@ -438,76 +426,12 @@ def handle_fetch_all(lecture_list_text):
|
|
| 438 |
# ---------- ์๋ก์ด ๊ธฐ๋ฅ ๋ ----------
|
| 439 |
|
| 440 |
# ---------- ํตํฉ Gradio ์ฑ ๊ตฌ์ฑ (ํ ํ์ด์ง์ ๋ชจ๋ ํ์) ----------
|
| 441 |
-
with gr.Blocks() as additional_demo:
|
| 442 |
-
# [๋ชจ๋2] - ๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ ์์ญ (์ญ์ ๋ด์ฉ ์ ๊ฑฐ ๋ฐ ํ์ดํ ์์ )
|
| 443 |
-
gr.Markdown("## ๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ")
|
| 444 |
-
with gr.Row():
|
| 445 |
-
url1 = gr.Textbox(label="๊ฐ์1 URL", elem_id="url1")
|
| 446 |
-
url2 = gr.Textbox(label="๊ฐ์2 URL", elem_id="url2")
|
| 447 |
-
url3 = gr.Textbox(label="๊ฐ์3 URL", elem_id="url3")
|
| 448 |
-
with gr.Row():
|
| 449 |
-
# ๊ฐ๋ณ '๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ' ๋ฒํผ์ ์ญ์ ๋จ (์์ฒญ์ฌํญ์ ๋ฐ๋ผ ์ ๊ฑฐ)
|
| 450 |
-
pass
|
| 451 |
-
with gr.Row():
|
| 452 |
-
lecture_content1 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content1")
|
| 453 |
-
lecture_content2 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content2")
|
| 454 |
-
lecture_content3 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content3")
|
| 455 |
-
with gr.Row():
|
| 456 |
-
copy_btn1 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn1")
|
| 457 |
-
copy_btn2 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn2")
|
| 458 |
-
copy_btn3 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn3")
|
| 459 |
-
with gr.Row():
|
| 460 |
-
copy_result1 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result1")
|
| 461 |
-
copy_result2 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result2")
|
| 462 |
-
copy_result3 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result3")
|
| 463 |
-
|
| 464 |
-
custom_script = """
|
| 465 |
-
<script>
|
| 466 |
-
function setupCopy(copyBtnId, textBoxId, resultBoxId) {
|
| 467 |
-
const copyBtn = document.getElementById(copyBtnId);
|
| 468 |
-
if (!copyBtn) {
|
| 469 |
-
console.error("๋ฒํผ " + copyBtnId + "๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.");
|
| 470 |
-
return;
|
| 471 |
-
}
|
| 472 |
-
copyBtn.addEventListener("click", function(){
|
| 473 |
-
const textBoxElem = document.getElementById(textBoxId);
|
| 474 |
-
const resultBoxElem = document.getElementById(resultBoxId);
|
| 475 |
-
if(textBoxElem && resultBoxElem) {
|
| 476 |
-
const textarea = textBoxElem.querySelector("textarea");
|
| 477 |
-
const resultTextarea = resultBoxElem.querySelector("textarea");
|
| 478 |
-
if(textarea && resultTextarea) {
|
| 479 |
-
var text = textarea.value;
|
| 480 |
-
if(text.trim() === ""){
|
| 481 |
-
resultTextarea.value = "๋ณต์ฌํ ๋ด์ฉ์ด ๏ฟฝ๏ฟฝ์ต๋๋ค.";
|
| 482 |
-
} else {
|
| 483 |
-
navigator.clipboard.writeText(text).then(function(){
|
| 484 |
-
resultTextarea.value = "๋ณต์ฌ์๋ฃ";
|
| 485 |
-
}, function(err){
|
| 486 |
-
resultTextarea.value = "๋ณต์ฌ ์คํจ";
|
| 487 |
-
});
|
| 488 |
-
}
|
| 489 |
-
}
|
| 490 |
-
}
|
| 491 |
-
});
|
| 492 |
-
}
|
| 493 |
-
document.addEventListener("DOMContentLoaded", function(){
|
| 494 |
-
setupCopy("copy_btn1", "lecture_content1", "copy_result1");
|
| 495 |
-
setupCopy("copy_btn2", "lecture_content2", "copy_result2");
|
| 496 |
-
setupCopy("copy_btn3", "lecture_content3", "copy_result3");
|
| 497 |
-
});
|
| 498 |
-
</script>
|
| 499 |
-
"""
|
| 500 |
-
gr.HTML(custom_script)
|
| 501 |
-
# (์ญ์ ๋ด์ฉ ๊ด๋ จ gr.Markdown ์ ๊ฑฐ)
|
| 502 |
-
|
| 503 |
with gr.Blocks() as app:
|
| 504 |
-
gr.HTML(css) # ์ฌ์ฉ์ ์ ์ CSS ์ฝ์
|
| 505 |
gr.Markdown("# ์บ๋กค๋ผ์ธ๋ํ ๊ฐ์ ์ถ์ถ๊ธฐ")
|
| 506 |
-
gr.Markdown(
|
| 507 |
-
gr.HTML(
|
| 508 |
"""
|
| 509 |
<div style="background-color: #f0f0f0; padding: 10px; margin-bottom: 20px;">
|
| 510 |
-
<strong>
|
| 511 |
<ol>
|
| 512 |
<li>์ถ์ถ์ ์ํ๋ ๊ฐ์ ํ์ด์ง์์ "Ctrl + U"๋ฅผ ๋๋ฌ ํ์ด์ง ์์ค๋ฅผ ํ์ธํ๊ฑฐ๋, ๋ง์ฐ์ค ์ฐํด๋ฆญ ํ "ํ์ด์ง ์์ค ๋ณด๊ธฐ"๋ฅผ ์ ํํฉ๋๋ค.</li>
|
| 513 |
<li>ํ์ด์ง ์์ค์์ ์ ์ฒด ๋ณต์ฌ ํฉ๋๋ค. ("Ctrl+A" โ "Ctrl+C")</li>
|
|
@@ -518,17 +442,18 @@ with gr.Blocks() as app:
|
|
| 518 |
</div>
|
| 519 |
"""
|
| 520 |
)
|
| 521 |
-
# ๋ชจ๋1: HTML ์
๋ ฅ ๋ฐ ๊ณผ๋ชฉ/์น์
|
| 522 |
with gr.Tab("HTML ํ์ฑ ๋ฐ ์น์
์ ํ"):
|
| 523 |
with gr.Row():
|
| 524 |
with gr.Column():
|
| 525 |
-
html_input = gr.Textbox(label="์ ์ฒด ํ์ด์ง HTML ์
๋ ฅ", lines=20, placeholder="HTML ์ฝ๋๋ฅผ ์
๋ ฅํ์ธ์..."
|
| 526 |
parse_btn = gr.Button("Submit")
|
| 527 |
-
with gr.Column(
|
| 528 |
-
subject_out = gr.Textbox(label="๊ณผ๋ชฉ๋ช
", interactive=False
|
| 529 |
section_dropdown = gr.Dropdown(label="์น์
์ ํ", choices=[], interactive=True)
|
| 530 |
-
lecture_out = gr.Textbox(label="์ ํํ ์น์
๊ฐ์ ๋ชฉ๋ก", lines=
|
| 531 |
with gr.Row():
|
|
|
|
| 532 |
fetch_all_btn = gr.Button("๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_all_btn")
|
| 533 |
sections_state = gr.State()
|
| 534 |
|
|
@@ -537,21 +462,87 @@ with gr.Blocks() as app:
|
|
| 537 |
inputs=html_input,
|
| 538 |
outputs=[subject_out, section_dropdown, sections_state]
|
| 539 |
)
|
| 540 |
-
# ์น์
์ ํ
|
| 541 |
section_dropdown.change(
|
| 542 |
fn=update_lecture_text_only,
|
| 543 |
inputs=[section_dropdown, sections_state],
|
| 544 |
outputs=lecture_out
|
| 545 |
)
|
| 546 |
-
# "๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ" ๋ฒํผ ํด๋ฆญ
|
| 547 |
fetch_all_btn.click(
|
| 548 |
fn=handle_fetch_all,
|
| 549 |
inputs=lecture_out,
|
| 550 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
)
|
| 552 |
|
| 553 |
-
|
| 554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
additional_demo.render()
|
| 556 |
merge_demo.render()
|
| 557 |
|
|
|
|
| 7 |
# ๋๋ฒ๊น
๋ก๊น
์ค์ (์ ์ฒด ํตํฉ์ ์ํด ํฌ๋งท ํฌํจ)
|
| 8 |
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# ---------- [๋ชจ๋1: ๊ธฐ์กด ๊ธฐ๋ณธ์ฝ๋] ์์ ----------
|
| 11 |
# ์์ด ์์ ํ๊ตญ์ด ์๋ก ๋ณํํ๊ธฐ ์ํ ๋งคํ
|
| 12 |
month_mapping = {
|
|
|
|
| 213 |
์ ํํ ์น์
์ ๋ฐํ์ผ๋ก ๊ฐ์ ๋ชฉ๋ก ํ
์คํธ์ URL๋ค์ ์ถ์ถํ์ฌ
|
| 214 |
- ๊ฐ์ ๋ชฉ๋ก ํ
์คํธ(์์ผ๋ฉด "๊ฐ์๊ฐ ์์ต๋๋ค" ๋ฐํ)
|
| 215 |
- ์ต๋ 3๊ฐ์ ๊ฐ์ URL (๊ฐ์ URL์ด ์์ผ๋ฉด ๋น ๋ฌธ์์ด)
|
| 216 |
+
๋ฅผ ๋ฐํ.
|
| 217 |
"""
|
| 218 |
if not selected_section or not sections_dict:
|
| 219 |
return "", "", "", ""
|
| 220 |
lectures_text, url_list = sections_dict.get(selected_section, ("", []))
|
| 221 |
if not lectures_text:
|
| 222 |
lectures_text = "๊ฐ์๊ฐ ์์ต๋๋ค"
|
| 223 |
+
# ๊ฐ์ URL 3๊ฐ ์ฑ์ฐ๊ธฐ (์์ผ๋ฉด ๋น ๋ฌธ์์ด)
|
| 224 |
url1 = url_list[0] if len(url_list) >= 1 else ""
|
| 225 |
url2 = url_list[1] if len(url_list) >= 2 else ""
|
| 226 |
url3 = url_list[2] if len(url_list) >= 3 else ""
|
|
|
|
| 309 |
"""
|
| 310 |
์
๋ ฅ๋ ๊ฐ์ URL๋ก๋ถํฐ ์คํฌ๋ฆฝํธ URL์ ์์ฑํ๊ณ ,
|
| 311 |
ํด๋น ์คํฌ๋ฆฝํธ๋ฅผ ๊ฐ์ ธ์จ ํ ํ์๋ผ์ธ์ ์ ๊ฑฐํ ์ต์ข
๊ฐ์ ๋ด์ฉ์ ๋ฐํํ๋ ํจ์.
|
| 312 |
+
(์ค๊ฐ ๋จ๊ณ๋ ์ถ๋ ฅํ์ง ์๊ณ ์ต์ข
๊ฒฐ๊ณผ๋ง ๋ฐํ)
|
| 313 |
"""
|
| 314 |
script_url = create_script_url(lecture_url)
|
| 315 |
if not script_url:
|
|
|
|
| 326 |
# ---------- [๋ชจ๋3: ๊ฐ์ ๋ด์ฉ ํฉ์น๊ธฐ ์ถ๊ฐ์ฝ๋] ์์ ----------
|
| 327 |
with gr.Blocks() as merge_demo:
|
| 328 |
gr.Markdown("## ๊ฐ์ ๋ด์ฉ ํฉ์น๊ธฐ")
|
| 329 |
+
# "๊ฐ์๋ด์ฉ ํฉ์น๊ธฐ" ๋ฒํผ ์ญ์ (์์ฒญ์ฌํญ์ ๋ฐ๋ผ ์ญ์ )
|
| 330 |
merged_content = gr.Textbox(label="์ ์ฒด ๊ฐ์ ๋ด์ฉ", lines=10, elem_id="merged_content")
|
| 331 |
with gr.Row():
|
| 332 |
merge_copy_btn = gr.Button("์ ์ฒด ๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="merge_copy_btn")
|
|
|
|
| 426 |
# ---------- ์๋ก์ด ๊ธฐ๋ฅ ๋ ----------
|
| 427 |
|
| 428 |
# ---------- ํตํฉ Gradio ์ฑ ๊ตฌ์ฑ (ํ ํ์ด์ง์ ๋ชจ๋ ํ์) ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
with gr.Blocks() as app:
|
|
|
|
| 430 |
gr.Markdown("# ์บ๋กค๋ผ์ธ๋ํ ๊ฐ์ ์ถ์ถ๊ธฐ")
|
| 431 |
+
gr.Markdown(
|
|
|
|
| 432 |
"""
|
| 433 |
<div style="background-color: #f0f0f0; padding: 10px; margin-bottom: 20px;">
|
| 434 |
+
<strong>์ฌ์ฉ๋ฐฉ๋ฒ</strong>
|
| 435 |
<ol>
|
| 436 |
<li>์ถ์ถ์ ์ํ๋ ๊ฐ์ ํ์ด์ง์์ "Ctrl + U"๋ฅผ ๋๋ฌ ํ์ด์ง ์์ค๋ฅผ ํ์ธํ๊ฑฐ๋, ๋ง์ฐ์ค ์ฐํด๋ฆญ ํ "ํ์ด์ง ์์ค ๋ณด๊ธฐ"๋ฅผ ์ ํํฉ๋๋ค.</li>
|
| 437 |
<li>ํ์ด์ง ์์ค์์ ์ ์ฒด ๋ณต์ฌ ํฉ๋๋ค. ("Ctrl+A" โ "Ctrl+C")</li>
|
|
|
|
| 442 |
</div>
|
| 443 |
"""
|
| 444 |
)
|
| 445 |
+
# ๋ชจ๋1: HTML ์
๋ ฅ ๋ฐ ์ค๋ฅธ์ชฝ์ ๊ณผ๋ชฉ/์น์
/๊ฐ์ ๋ชฉ๋ก ํ์
|
| 446 |
with gr.Tab("HTML ํ์ฑ ๋ฐ ์น์
์ ํ"):
|
| 447 |
with gr.Row():
|
| 448 |
with gr.Column():
|
| 449 |
+
html_input = gr.Textbox(label="์ ์ฒด ํ์ด์ง HTML ์
๋ ฅ", lines=20, placeholder="HTML ์ฝ๋๋ฅผ ์
๋ ฅํ์ธ์...")
|
| 450 |
parse_btn = gr.Button("Submit")
|
| 451 |
+
with gr.Column():
|
| 452 |
+
subject_out = gr.Textbox(label="๊ณผ๋ชฉ๋ช
", interactive=False)
|
| 453 |
section_dropdown = gr.Dropdown(label="์น์
์ ํ", choices=[], interactive=True)
|
| 454 |
+
lecture_out = gr.Textbox(label="์ ํํ ์น์
๊ฐ์ ๋ชฉ๋ก", lines=10, interactive=False)
|
| 455 |
with gr.Row():
|
| 456 |
+
# [์์ฒญ์ฌํญ]์ ๋ฐ๋ผ "์ ํํ ์น์
๊ฐ์ ๋ชฉ๋ก" ์๋์ '๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ' ๋ฒํผ ์ถ๊ฐ
|
| 457 |
fetch_all_btn = gr.Button("๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ", elem_id="fetch_all_btn")
|
| 458 |
sections_state = gr.State()
|
| 459 |
|
|
|
|
| 462 |
inputs=html_input,
|
| 463 |
outputs=[subject_out, section_dropdown, sections_state]
|
| 464 |
)
|
| 465 |
+
# ์น์
์ ํ์ ๊ฐ์๋ชฉ๋ก ํ
์คํธ๋ง ์
๋ฐ์ดํธํ๋ ์ด๋ฒคํธ ๋ฑ๋ก
|
| 466 |
section_dropdown.change(
|
| 467 |
fn=update_lecture_text_only,
|
| 468 |
inputs=[section_dropdown, sections_state],
|
| 469 |
outputs=lecture_out
|
| 470 |
)
|
| 471 |
+
# "๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ" ๋ฒํผ ํด๋ฆญ์ ๊ฐ์ URL๊ณผ ๋ด์ฉ ์
๋ฐ์ดํธ (๋ฒํผ ํด๋ฆญ ์ [ํ๋] ์คํ)
|
| 472 |
fetch_all_btn.click(
|
| 473 |
fn=handle_fetch_all,
|
| 474 |
inputs=lecture_out,
|
| 475 |
+
outputs=[None, None, None,
|
| 476 |
+
# ํด๋น ์ถ๋ ฅ์ ๊ฐ์ URL์ฐฝ ์๋์ ์์นํ ๊ฐ๋ณ ๊ฐ์ ๋ด์ฉ ํ
์คํธ๋ฐ์ค๋ค์ ๋์
|
| 477 |
+
# URL ํ
์คํธ๋ฐ์ค๋ ๊ทธ๋๋ก ์ ์งํ์ง๋ง ์ญ์ ๋ ๋ด์ฉ์ด ์ถ๋ ฅ๋์ง ์๋๋ก None ์ฒ๋ฆฌ
|
| 478 |
+
# ์๋ ์์: url1, url2, url3, lecture_content1, lecture_content2, lecture_content3, merged_content
|
| 479 |
+
# URL ํ
์คํธ๋ฐ์ค๏ฟฝ๏ฟฝ ์
๋ฐ์ดํธ ์์ด ์ ์งํ๊ธฐ ์ํด None ๋ฐํ
|
| 480 |
+
None, None, None, merged_content]
|
| 481 |
)
|
| 482 |
|
| 483 |
+
# ๋ชจ๋2: ๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ (ํ์ดํ ์์ )
|
| 484 |
+
with gr.Blocks() as additional_demo:
|
| 485 |
+
gr.Markdown("## ๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ")
|
| 486 |
+
with gr.Row():
|
| 487 |
+
url1 = gr.Textbox(label="๊ฐ์1 URL", elem_id="url1")
|
| 488 |
+
url2 = gr.Textbox(label="๊ฐ์2 URL", elem_id="url2")
|
| 489 |
+
url3 = gr.Textbox(label="๊ฐ์3 URL", elem_id="url3")
|
| 490 |
+
with gr.Row():
|
| 491 |
+
# ๊ฐ๋ณ '๊ฐ์ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ' ๋ฒํผ ์ญ์ (์์ฒญ์ฌํญ์ ๋ฐ๋ผ ์ญ์ )
|
| 492 |
+
pass
|
| 493 |
+
with gr.Row():
|
| 494 |
+
lecture_content1 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content1")
|
| 495 |
+
lecture_content2 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content2")
|
| 496 |
+
lecture_content3 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ", lines=10, elem_id="lecture_content3")
|
| 497 |
+
with gr.Row():
|
| 498 |
+
copy_btn1 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn1")
|
| 499 |
+
copy_btn2 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn2")
|
| 500 |
+
copy_btn3 = gr.Button("๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ", elem_id="copy_btn3")
|
| 501 |
+
with gr.Row():
|
| 502 |
+
copy_result1 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result1")
|
| 503 |
+
copy_result2 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result2")
|
| 504 |
+
copy_result3 = gr.Textbox(label="๊ฐ์ ๋ด์ฉ ๋ณต์ฌํ๊ธฐ ๊ฒฐ๊ณผ", interactive=False, elem_id="copy_result3")
|
| 505 |
+
|
| 506 |
+
custom_script = """
|
| 507 |
+
<script>
|
| 508 |
+
function setupCopy(copyBtnId, textBoxId, resultBoxId) {
|
| 509 |
+
const copyBtn = document.getElementById(copyBtnId);
|
| 510 |
+
if (!copyBtn) {
|
| 511 |
+
console.error("๋ฒํผ " + copyBtnId + "๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.");
|
| 512 |
+
return;
|
| 513 |
+
}
|
| 514 |
+
copyBtn.addEventListener("click", function(){
|
| 515 |
+
const textBoxElem = document.getElementById(textBoxId);
|
| 516 |
+
const resultBoxElem = document.getElementById(resultBoxId);
|
| 517 |
+
if(textBoxElem && resultBoxElem) {
|
| 518 |
+
const textarea = textBoxElem.querySelector("textarea");
|
| 519 |
+
const resultTextarea = resultBoxElem.querySelector("textarea");
|
| 520 |
+
if(textarea && resultTextarea) {
|
| 521 |
+
var text = textarea.value;
|
| 522 |
+
if(text.trim() === ""){
|
| 523 |
+
resultTextarea.value = "๋ณต์ฌํ ๋ด์ฉ์ด ์์ต๋๋ค.";
|
| 524 |
+
} else {
|
| 525 |
+
navigator.clipboard.writeText(text).then(function(){
|
| 526 |
+
resultTextarea.value = "๋ณต์ฌ์๋ฃ";
|
| 527 |
+
}, function(err){
|
| 528 |
+
resultTextarea.value = "๋ณต์ฌ ์คํจ";
|
| 529 |
+
});
|
| 530 |
+
}
|
| 531 |
+
}
|
| 532 |
+
}
|
| 533 |
+
});
|
| 534 |
+
}
|
| 535 |
+
document.addEventListener("DOMContentLoaded", function(){
|
| 536 |
+
setupCopy("copy_btn1", "lecture_content1", "copy_result1");
|
| 537 |
+
setupCopy("copy_btn2", "lecture_content2", "copy_result2");
|
| 538 |
+
setupCopy("copy_btn3", "lecture_content3", "copy_result3");
|
| 539 |
+
});
|
| 540 |
+
</script>
|
| 541 |
+
"""
|
| 542 |
+
gr.HTML(custom_script)
|
| 543 |
+
gr.Markdown("๋๋ฒ๊น
๋ชจ๋ ํ์ฑํ๋จ: ๋ก๊ทธ๊ฐ ์ฝ์์ ์ถ๋ ฅ๋ฉ๋๋ค.")
|
| 544 |
+
|
| 545 |
+
# ๋ชจ๋3์ ์์์ ์ ์๋ merge_demo ์ฌ์ฉ
|
| 546 |
additional_demo.render()
|
| 547 |
merge_demo.render()
|
| 548 |
|