seawolf2357 commited on
Commit
b6c1706
ยท
verified ยท
1 Parent(s): 238c945

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -34
app.py CHANGED
@@ -508,13 +508,14 @@ def load_session_history(selected_session=None):
508
  """
509
 
510
  for item in json_data:
511
- prompt_text = html.escape(item.get('prompt', '')).replace('"', '"')
 
512
  html_content += f"""
513
  <div class="prompt-card">
514
  <img src="{item.get('image_url', '')}" class="card-image" alt="{html.escape(item.get('name', ''))}">
515
  <div class="card-name">{html.escape(item.get('name', ''))}</div>
516
- <div class="card-prompt">{prompt_text}</div>
517
- <button class="copy-button" onclick="copyToClipboard(this, '{prompt_text}')">
518
  ๐Ÿ“‹ ๋ณต์‚ฌ
519
  </button>
520
  </div>
@@ -523,46 +524,47 @@ def load_session_history(selected_session=None):
523
  html_content += """
524
  </div>
525
  <script>
526
- function copyToClipboard(button, text) {
527
- // ํด๋ฆฝ๋ณด๋“œ์— ๋ณต์‚ฌํ•˜๋Š” ํ•จ์ˆ˜
528
- const copyText = async () => {
529
- try {
530
- await navigator.clipboard.writeText(text);
531
- button.textContent = 'โœ“ ๋ณต์‚ฌ๋จ';
532
- button.style.backgroundColor = '#52c41a';
533
- button.style.color = 'white';
534
 
535
- setTimeout(() => {
536
- button.textContent = '๐Ÿ“‹ ๋ณต์‚ฌ';
537
- button.style.backgroundColor = '#f0f0f0';
538
- button.style.color = 'inherit';
539
- }, 2000);
540
- } catch (err) {
541
- // fallback
542
- const textarea = document.createElement('textarea');
543
- textarea.value = text;
544
- document.body.appendChild(textarea);
545
- textarea.select();
546
  try {
 
 
 
 
 
 
 
 
 
547
  document.execCommand('copy');
548
- button.textContent = 'โœ“ ๋ณต์‚ฌ๋จ';
549
- button.style.backgroundColor = '#52c41a';
550
- button.style.color = 'white';
551
 
 
 
 
 
 
 
552
  setTimeout(() => {
553
- button.textContent = '๐Ÿ“‹ ๋ณต์‚ฌ';
554
- button.style.backgroundColor = '#f0f0f0';
555
- button.style.color = 'inherit';
556
  }, 2000);
 
557
  } catch (err) {
558
  console.error('๋ณต์‚ฌ ์‹คํŒจ:', err);
559
  alert('๋ณต์‚ฌ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์ง์ ‘ ํ…์ŠคํŠธ๋ฅผ ์„ ํƒํ•˜์—ฌ ๋ณต์‚ฌํ•ด์ฃผ์„ธ์š”.');
560
  }
561
- document.body.removeChild(textarea);
562
- }
563
- };
564
- copyText();
565
- }
566
  </script>
567
  """
568
 
@@ -570,7 +572,7 @@ def load_session_history(selected_session=None):
570
 
571
  except Exception as e:
572
  print(f"Error in load_session_history: {str(e)}")
573
- return gr.HTML("Error loading templates")
574
 
575
 
576
 
 
508
  """
509
 
510
  for item in json_data:
511
+ # JSON์œผ๋กœ ์ง๋ ฌํ™”ํ•˜์—ฌ JavaScript ๋ฌธ์ž์—ด๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ๋ณ€ํ™˜
512
+ prompt_json = json.dumps(item.get('prompt', ''))
513
  html_content += f"""
514
  <div class="prompt-card">
515
  <img src="{item.get('image_url', '')}" class="card-image" alt="{html.escape(item.get('name', ''))}">
516
  <div class="card-name">{html.escape(item.get('name', ''))}</div>
517
+ <div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
518
+ <button class="copy-button" data-prompt={prompt_json}>
519
  ๐Ÿ“‹ ๋ณต์‚ฌ
520
  </button>
521
  </div>
 
524
  html_content += """
525
  </div>
526
  <script>
527
+ // ๋ชจ๋“  ๋ณต์‚ฌ ๋ฒ„ํŠผ์— ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์ถ”๊ฐ€
528
+ document.addEventListener('DOMContentLoaded', function() {
529
+ document.querySelectorAll('.copy-button').forEach(button => {
530
+ button.addEventListener('click', async function(e) {
531
+ e.preventDefault();
532
+ e.stopPropagation();
533
+
534
+ const promptText = this.dataset.prompt;
535
 
 
 
 
 
 
 
 
 
 
 
 
536
  try {
537
+ // ํ…์ŠคํŠธ ์˜์—ญ ์ƒ์„ฑ ๋ฐ ์„ค์ •
538
+ const textarea = document.createElement('textarea');
539
+ textarea.value = promptText;
540
+ textarea.style.position = 'fixed';
541
+ textarea.style.left = '-9999px';
542
+ document.body.appendChild(textarea);
543
+ textarea.select();
544
+
545
+ // ๋ณต์‚ฌ ์‹œ๋„
546
  document.execCommand('copy');
547
+ document.body.removeChild(textarea);
 
 
548
 
549
+ // ๋ฒ„ํŠผ ์ƒํƒœ ์—…๋ฐ์ดํŠธ
550
+ this.textContent = 'โœ“ ๋ณต์‚ฌ๋จ';
551
+ this.style.backgroundColor = '#52c41a';
552
+ this.style.color = 'white';
553
+
554
+ // 2์ดˆ ํ›„ ์›๋ž˜ ์ƒํƒœ๋กœ ๋ณต๊ตฌ
555
  setTimeout(() => {
556
+ this.textContent = '๐Ÿ“‹ ๋ณต์‚ฌ';
557
+ this.style.backgroundColor = '#f0f0f0';
558
+ this.style.color = 'inherit';
559
  }, 2000);
560
+
561
  } catch (err) {
562
  console.error('๋ณต์‚ฌ ์‹คํŒจ:', err);
563
  alert('๋ณต์‚ฌ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์ง์ ‘ ํ…์ŠคํŠธ๋ฅผ ์„ ํƒํ•˜์—ฌ ๋ณต์‚ฌํ•ด์ฃผ์„ธ์š”.');
564
  }
565
+ });
566
+ });
567
+ });
 
 
568
  </script>
569
  """
570
 
 
572
 
573
  except Exception as e:
574
  print(f"Error in load_session_history: {str(e)}")
575
+ return gr.HTML("Error loading templates")
576
 
577
 
578