seawolf2357 commited on
Commit
238c945
Β·
verified Β·
1 Parent(s): b811715

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -89
app.py CHANGED
@@ -449,12 +449,9 @@ def load_json_data():
449
  }
450
  ]
451
 
452
-
453
  def load_session_history(selected_session=None):
454
  try:
455
- print("Loading session history...")
456
  json_data = load_json_data()
457
- print(f"Loaded {len(json_data)} items")
458
 
459
  html_content = """
460
  <style>
@@ -469,7 +466,6 @@ def load_session_history(selected_session=None):
469
  border: 1px solid #eee;
470
  border-radius: 8px;
471
  padding: 15px;
472
- cursor: pointer;
473
  transition: all 0.3s ease;
474
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
475
  min-height: 300px;
@@ -490,23 +486,13 @@ def load_session_history(selected_session=None):
490
  margin-bottom: 8px;
491
  font-size: 16px;
492
  }
493
- .card-prompt-container {
494
- position: relative;
495
- padding-right: 60px;
496
- }
497
  .card-prompt {
498
  font-size: 0.9em;
499
  color: #666;
500
- display: -webkit-box;
501
- -webkit-line-clamp: 3;
502
- -webkit-box-orient: vertical;
503
- overflow: hidden;
504
  }
505
- .copy-btn {
506
- position: absolute;
507
- right: 0;
508
- top: 0;
509
- padding: 4px 8px;
510
  background: #f0f0f0;
511
  border: 1px solid #ddd;
512
  border-radius: 4px;
@@ -514,98 +500,68 @@ def load_session_history(selected_session=None):
514
  font-size: 0.9em;
515
  transition: all 0.2s ease;
516
  }
517
- .copy-btn:hover {
518
  background: #e0e0e0;
519
  }
520
- .copy-btn:active {
521
- background: #d0d0d0;
522
- }
523
  </style>
524
  <div class="prompt-grid">
525
  """
526
 
527
  for item in json_data:
528
- name = html.escape(item.get('name', ''))
529
- image_url = item.get('image_url', '')
530
- # ν”„λ‘¬ν”„νŠΈμ—μ„œ 특수 문자 처리λ₯Ό μœ„ν•΄ JSON.stringify μ‚¬μš©
531
- prompt = json.dumps(item.get('prompt', ''))
532
-
533
  html_content += f"""
534
  <div class="prompt-card">
535
- <img src="{image_url}" class="card-image" alt="{name}">
536
- <div class="card-name">{name}</div>
537
- <div class="card-prompt-container">
538
- <div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
539
- <button class="copy-btn" onclick="copyPrompt(event, {prompt})" title="ν”„λ‘¬ν”„νŠΈ 볡사">
540
- πŸ“‹ 볡사
541
- </button>
542
- </div>
543
  </div>
544
  """
545
 
546
  html_content += """
547
  </div>
548
  <script>
549
- async function copyPrompt(event, prompt) {
550
- event.preventDefault();
551
- event.stopPropagation();
552
-
553
- try {
554
- await navigator.clipboard.writeText(prompt);
555
- const btn = event.target;
556
- btn.textContent = 'βœ“ 볡사됨';
557
- btn.style.backgroundColor = '#52c41a';
558
- btn.style.color = 'white';
559
-
560
- setTimeout(() => {
561
- btn.textContent = 'πŸ“‹ 볡사';
562
- btn.style.backgroundColor = '#f0f0f0';
563
- btn.style.color = 'inherit';
564
- }, 2000);
565
- } catch (err) {
566
- // ν΄λ¦½λ³΄λ“œ APIκ°€ μ‹€νŒ¨ν•  경우 λŒ€μ²΄ 방법 μ‚¬μš©
567
- const textarea = document.createElement('textarea');
568
- textarea.value = prompt;
569
- textarea.style.position = 'fixed';
570
- textarea.style.opacity = '0';
571
- document.body.appendChild(textarea);
572
- textarea.select();
573
  try {
574
- document.execCommand('copy');
575
- const btn = event.target;
576
- btn.textContent = 'βœ“ 볡사됨';
577
- btn.style.backgroundColor = '#52c41a';
578
- btn.style.color = 'white';
579
 
580
  setTimeout(() => {
581
- btn.textContent = 'πŸ“‹ 볡사';
582
- btn.style.backgroundColor = '#f0f0f0';
583
- btn.style.color = 'inherit';
584
  }, 2000);
585
  } catch (err) {
586
- console.error('볡사 μ‹€νŒ¨:', err);
587
- alert('볡사에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€. 직접 ν…μŠ€νŠΈλ₯Ό μ„ νƒν•˜μ—¬ λ³΅μ‚¬ν•΄μ£Όμ„Έμš”.');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  }
589
- document.body.removeChild(textarea);
590
- }
591
- }
592
-
593
- function handleCardClick(card) {
594
- const prompt = card.getAttribute('data-prompt');
595
- const textarea = document.querySelector('textarea');
596
- if (textarea) {
597
- textarea.value = prompt;
598
-
599
- const sendButton = document.querySelector('button:contains("Send")');
600
- if (sendButton) {
601
- sendButton.click();
602
- }
603
-
604
- const drawer = document.querySelector('.session-drawer');
605
- if (drawer) {
606
- drawer.style.display = 'none';
607
- }
608
- }
609
  }
610
  </script>
611
  """
@@ -614,7 +570,8 @@ def load_session_history(selected_session=None):
614
 
615
  except Exception as e:
616
  print(f"Error in load_session_history: {str(e)}")
617
- return gr.HTML("Error loading templates")
 
618
 
619
 
620
  # νžˆμŠ€ν† λ¦¬ μ•„μ΄ν…œ 선택 처리 ν•¨μˆ˜
 
449
  }
450
  ]
451
 
 
452
  def load_session_history(selected_session=None):
453
  try:
 
454
  json_data = load_json_data()
 
455
 
456
  html_content = """
457
  <style>
 
466
  border: 1px solid #eee;
467
  border-radius: 8px;
468
  padding: 15px;
 
469
  transition: all 0.3s ease;
470
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
471
  min-height: 300px;
 
486
  margin-bottom: 8px;
487
  font-size: 16px;
488
  }
 
 
 
 
489
  .card-prompt {
490
  font-size: 0.9em;
491
  color: #666;
492
+ margin-bottom: 10px;
 
 
 
493
  }
494
+ .copy-button {
495
+ padding: 5px 10px;
 
 
 
496
  background: #f0f0f0;
497
  border: 1px solid #ddd;
498
  border-radius: 4px;
 
500
  font-size: 0.9em;
501
  transition: all 0.2s ease;
502
  }
503
+ .copy-button:hover {
504
  background: #e0e0e0;
505
  }
 
 
 
506
  </style>
507
  <div class="prompt-grid">
508
  """
509
 
510
  for item in json_data:
511
+ prompt_text = html.escape(item.get('prompt', '')).replace('"', '&quot;')
 
 
 
 
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>
521
  """
522
 
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
  """
 
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
 
577
  # νžˆμŠ€ν† λ¦¬ μ•„μ΄ν…œ 선택 처리 ν•¨μˆ˜