seawolf2357 commited on
Commit
7dfb1c0
·
verified ·
1 Parent(s): 19f084d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -449,12 +449,11 @@ def load_session_history(selected_session):
449
  short_prompt = prompt[:100] + "..." if len(prompt) > 100 else prompt
450
  formatted_time = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S.%f').strftime('%Y-%m-%d %H:%M')
451
 
452
- # data 속성에 정보 저장
453
  html_content += f"""
454
  <div class="prompt-card"
455
  data-prompt="{html.escape(prompt)}"
456
  data-response="{html.escape(response)}"
457
- onclick="selectHistoryItem(this)">
458
  <div>{html.escape(short_prompt)}</div>
459
  <div class="timestamp">{formatted_time}</div>
460
  </div>
@@ -463,23 +462,30 @@ def load_session_history(selected_session):
463
  html_content += """
464
  </div>
465
  <script>
466
- function selectHistoryItem(element) {
467
- const event = new CustomEvent('history-item-selected', {
468
- detail: {
469
- prompt: element.getAttribute('data-prompt'),
470
- response: element.getAttribute('data-response')
471
- }
472
- });
473
- document.dispatchEvent(event);
474
- }
 
 
 
 
 
 
 
475
  </script>
476
  """
477
 
478
- return gr.HTML(value=html_content)
479
 
480
  except Exception as e:
481
  print(f"Error loading session history: {e}")
482
- return gr.HTML("Error loading history")
483
 
484
  # 히스토리 아이템 선택 처리 함수
485
  def handle_history_selection(evt: gr.SelectData):
@@ -578,8 +584,10 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
578
  )
579
  # Chatbot을 HTML로 변경
580
  session_history = gr.HTML(
581
- elem_classes="session-history"
582
- )
 
 
583
  close_btn = antd.Button(
584
  "Close",
585
  type="default",
 
449
  short_prompt = prompt[:100] + "..." if len(prompt) > 100 else prompt
450
  formatted_time = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S.%f').strftime('%Y-%m-%d %H:%M')
451
 
 
452
  html_content += f"""
453
  <div class="prompt-card"
454
  data-prompt="{html.escape(prompt)}"
455
  data-response="{html.escape(response)}"
456
+ onclick="gradioHandleClick(this)">
457
  <div>{html.escape(short_prompt)}</div>
458
  <div class="timestamp">{formatted_time}</div>
459
  </div>
 
462
  html_content += """
463
  </div>
464
  <script>
465
+ function gradioHandleClick(element) {
466
+ const data = {
467
+ prompt: element.getAttribute('data-prompt'),
468
+ response: element.getAttribute('data-response')
469
+ };
470
+ // Gradio의 select 이벤트 트리거
471
+ document.querySelector('.session-history').dispatchEvent(
472
+ new CustomEvent('select', {
473
+ detail: {
474
+ value: data,
475
+ index: 0,
476
+ target: element
477
+ }
478
+ })
479
+ );
480
+ }
481
  </script>
482
  """
483
 
484
+ return gr.HTML(value=html_content, interactive=True)
485
 
486
  except Exception as e:
487
  print(f"Error loading session history: {e}")
488
+ return gr.HTML("Error loading history", interactive=True)
489
 
490
  # 히스토리 아이템 선택 처리 함수
491
  def handle_history_selection(evt: gr.SelectData):
 
584
  )
585
  # Chatbot을 HTML로 변경
586
  session_history = gr.HTML(
587
+ elem_classes="session-history",
588
+ interactive=True # 이 부분 추가
589
+ )
590
+
591
  close_btn = antd.Button(
592
  "Close",
593
  type="default",