unnastyle commited on
Commit
3c1b055
ยท
verified ยท
1 Parent(s): 957132b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
app.py CHANGED
@@ -502,45 +502,46 @@ with gr.Blocks() as app:
502
  </div>
503
  """
504
  )
505
- # [์‚ฌ์šฉ๋ฐฉ๋ฒ•] ์˜์—ญ ์•„๋ž˜์— "์ƒ˜ํ”Œ ๋„ฃ์–ด๋ณด๊ธฐ" ๋ฒ„ํŠผ ์ถ”๊ฐ€
506
  sample_btn = gr.Button("์ƒ˜ํ”Œ ๋„ฃ์–ด๋ณด๊ธฐ", elem_id="sample_btn")
507
  gr.HTML(
508
  """
509
  <script>
510
- document.getElementById("sample_btn").addEventListener("click", function(){
511
- fetch("sample.txt")
512
- .then(response => response.text())
513
- .then(text => {
514
- console.log("์ƒ˜ํ”Œ ํ…์ŠคํŠธ ๋กœ๋“œ๋จ:", text);
515
- navigator.clipboard.writeText(text).then(function(){
516
- console.log("ํด๋ฆฝ๋ณด๋“œ ๋ณต์‚ฌ ์™„๋ฃŒ");
517
- }).catch(function(err){
518
- console.error("ํด๋ฆฝ๋ณด๋“œ ๋ณต์‚ฌ ์‹คํŒจ", err);
519
- });
520
- const htmlInputElem = document.getElementById("html_input");
521
- if(htmlInputElem){
522
- const textarea = htmlInputElem.querySelector("textarea");
523
- if(textarea){
524
- textarea.value = text;
525
- console.log("์ „์ฒด ํŽ˜์ด์ง€ HTML ์ž…๋ ฅ ํ•„๋“œ์— ๋‚ด์šฉ ์ฑ„์›Œ์ง");
526
  } else {
527
- console.error("textarea๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Œ");
528
  }
529
- } else {
530
- console.error("html_input ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Œ");
531
- }
532
- })
533
- .catch(err => {
534
- console.error("sample.txt ๋กœ๋“œ ์‹คํŒจ", err);
535
  });
 
 
 
536
  });
537
  </script>
538
  """
539
  )
 
540
  with gr.Tab("HTML ํŒŒ์‹ฑ ๋ฐ ์„น์…˜ ์„ ํƒ"):
541
  with gr.Row():
542
  with gr.Column():
543
- html_input = gr.Textbox(label="์ „์ฒด ํŽ˜์ด์ง€ HTML ์ž…๋ ฅ", lines=20, placeholder="HTML ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...", elem_id="html_input")
544
  parse_btn = gr.Button("Submit")
545
  with gr.Column():
546
  subject_out = gr.Textbox(label="๊ณผ๋ชฉ๋ช…", interactive=False)
 
502
  </div>
503
  """
504
  )
505
+ # ------------------ [์ถ”๊ฐ€: ์‚ฌ์šฉ๋ฐฉ๋ฒ• ์˜์—ญ ์•„๋ž˜ "์ƒ˜ํ”Œ ๋„ฃ์–ด๋ณด๊ธฐ" ๋ฒ„ํŠผ ์ถ”๊ฐ€] ------------------
506
  sample_btn = gr.Button("์ƒ˜ํ”Œ ๋„ฃ์–ด๋ณด๊ธฐ", elem_id="sample_btn")
507
  gr.HTML(
508
  """
509
  <script>
510
+ document.addEventListener("DOMContentLoaded", function(){
511
+ const sampleBtn = document.getElementById("sample_btn");
512
+ if(sampleBtn){
513
+ sampleBtn.addEventListener("click", function(){
514
+ fetch("sample.html")
515
+ .then(response => response.text())
516
+ .then(function(text){
517
+ navigator.clipboard.writeText(text).then(function(){
518
+ console.log("์ƒ˜ํ”Œ HTML ๋ณต์‚ฌ ์„ฑ๊ณต");
519
+ }, function(err){
520
+ console.error("ํด๋ฆฝ๋ณด๋“œ ๋ณต์‚ฌ ์‹คํŒจ:", err);
521
+ });
522
+ var htmlInput = document.querySelector('textarea[aria-label="์ „์ฒด ํŽ˜์ด์ง€ HTML ์ž…๋ ฅ"]');
523
+ if(htmlInput){
524
+ htmlInput.value = text;
 
525
  } else {
526
+ console.error("์ „์ฒด ํŽ˜์ด์ง€ HTML ์ž…๋ ฅ ์ฐฝ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
527
  }
528
+ })
529
+ .catch(function(error){
530
+ console.error("sample.html ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ์‹คํŒจ:", error);
531
+ });
 
 
532
  });
533
+ } else {
534
+ console.error("์ƒ˜ํ”Œ ๋„ฃ์–ด๋ณด๊ธฐ ๋ฒ„ํŠผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
535
+ }
536
  });
537
  </script>
538
  """
539
  )
540
+ # ----------------------------------------------------------------------------------------
541
  with gr.Tab("HTML ํŒŒ์‹ฑ ๋ฐ ์„น์…˜ ์„ ํƒ"):
542
  with gr.Row():
543
  with gr.Column():
544
+ html_input = gr.Textbox(label="์ „์ฒด ํŽ˜์ด์ง€ HTML ์ž…๋ ฅ", lines=20, placeholder="HTML ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...")
545
  parse_btn = gr.Button("Submit")
546
  with gr.Column():
547
  subject_out = gr.Textbox(label="๊ณผ๋ชฉ๋ช…", interactive=False)