Rulga commited on
Commit
4fec12d
·
1 Parent(s): aa37882

Enhance QA pairs table interactivity; add column configuration and row selection handler

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -954,8 +954,25 @@ with gr.Blocks() as demo:
954
  show_evaluated = gr.Checkbox(label="Show Already Evaluated Pairs", value=False)
955
  qa_table = gr.DataFrame(
956
  get_qa_pairs_dataframe(chat_evaluator),
957
- interactive=False
958
- # Removed column_config for compatibility
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
959
  )
960
 
961
  # Conversation selection section
@@ -1016,17 +1033,21 @@ with gr.Blocks() as demo:
1016
  outputs=[qa_table]
1017
  )
1018
 
1019
- # Table row selection function
1020
- def on_table_select(evt):
 
1021
  try:
1022
- return evt.value[0] if evt and hasattr(evt, 'value') and len(evt.value) > 0 else ""
 
 
1023
  except Exception as e:
1024
- print(f"Error selecting table row: {str(e)}")
1025
  return ""
1026
-
1027
  # Table row selection handler
1028
  qa_table.select(
1029
  fn=on_table_select,
 
1030
  outputs=[selected_conversation]
1031
  )
1032
 
 
954
  show_evaluated = gr.Checkbox(label="Show Already Evaluated Pairs", value=False)
955
  qa_table = gr.DataFrame(
956
  get_qa_pairs_dataframe(chat_evaluator),
957
+ interactive=True, # Делаем таблицу интерактивной
958
+ wrap=True, # Включаем перенос текста
959
+ column_config={
960
+ "conversation_id": gr.Column(
961
+ label="Conversation ID",
962
+ copy_button=True # Добавляем кнопку копирования
963
+ ),
964
+ "question": gr.Column(
965
+ label="Question",
966
+ max_width=300,
967
+ wrap=True
968
+ ),
969
+ "answer": gr.Column(
970
+ label="Answer",
971
+ max_width=300,
972
+ wrap=True
973
+ )
974
+ },
975
+ elem_id="qa_pairs_table" # Добавляем ID для возможности стилизации
976
  )
977
 
978
  # Conversation selection section
 
1033
  outputs=[qa_table]
1034
  )
1035
 
1036
+ # Обработчик выбора строки в таблице
1037
+ def on_table_select(evt: gr.SelectData) -> str:
1038
+ """Handle table row selection"""
1039
  try:
1040
+ # evt.value содержит данные выбранной строки
1041
+ # Возвращаем conversation_id из первой колонки
1042
+ return evt.value[0]
1043
  except Exception as e:
1044
+ logger.error(f"Error in table selection: {str(e)}")
1045
  return ""
1046
+
1047
  # Table row selection handler
1048
  qa_table.select(
1049
  fn=on_table_select,
1050
+ inputs=[], # Не нужны входные данные
1051
  outputs=[selected_conversation]
1052
  )
1053