Heng2004 commited on
Commit
0ab7867
·
verified ·
1 Parent(s): e7ab1a5

Update teacher_panel.py

Browse files
Files changed (1) hide show
  1. teacher_panel.py +8 -9
teacher_panel.py CHANGED
@@ -1,7 +1,7 @@
1
  # teacher_panel.py
2
  from typing import List, Tuple
3
 
4
- import gradio as gr # ⬅️ needed for gr.SelectData type
5
 
6
  import qa_store
7
  from qa_store import normalize_question
@@ -10,6 +10,7 @@ from loader import (
10
  save_manual_qa_file,
11
  rebuild_combined_qa,
12
  manual_qa_table_data,
 
13
  )
14
 
15
 
@@ -56,8 +57,9 @@ def teacher_save_add_overwrite(
56
  current_id = new_id
57
  msg = "✅ ບັນທຶກ Q&A ໃໝ່ສໍາເລັດ."
58
 
59
- save_manual_qa_file()
60
- rebuild_combined_qa()
 
61
 
62
  return question, answer, current_id, _table(), msg
63
 
@@ -97,6 +99,7 @@ def teacher_update_current(
97
 
98
  save_manual_qa_file()
99
  rebuild_combined_qa()
 
100
 
101
  msg = "✅ ແກ້ໄຂ Q&A ສໍາເລັດ."
102
  return question, answer, current_id, _table(), msg
@@ -124,6 +127,7 @@ def teacher_delete_current(
124
 
125
  save_manual_qa_file()
126
  rebuild_combined_qa()
 
127
 
128
  msg = "🗑️ ລຶບ Q&A ສໍາເລັດ."
129
  return "", "", "", _table(), msg
@@ -134,16 +138,11 @@ def teacher_on_table_select(
134
  ) -> Tuple[str, str, str, str]:
135
  """
136
  When teacher clicks a row in the Q&A table, load Q/A into textboxes.
137
-
138
- We only use the SelectData event:
139
- - evt.index -> (row, col)
140
- - evt.row_value -> the whole row [id, question, answer]
141
  """
142
  try:
143
  if evt is None or evt.index is None or evt.row_value is None:
144
  raise ValueError("Empty select event")
145
 
146
- # row_value is already the full row (list-like)
147
  row = list(evt.row_value)
148
 
149
  current_id = str(row[0]) if len(row) > 0 else ""
@@ -161,4 +160,4 @@ def teacher_on_table_select(
161
  answer = ""
162
  msg = "⚠️ ບໍ່ສາມາດເລືອກແຖວໄດ້."
163
 
164
- return question, answer, current_id, msg
 
1
  # teacher_panel.py
2
  from typing import List, Tuple
3
 
4
+ import gradio as gr # needed for gr.SelectData type
5
 
6
  import qa_store
7
  from qa_store import normalize_question
 
10
  save_manual_qa_file,
11
  rebuild_combined_qa,
12
  manual_qa_table_data,
13
+ sync_upload_manual_qa, # <--- IMPORT THE NEW FUNCTION
14
  )
15
 
16
 
 
57
  current_id = new_id
58
  msg = "✅ ບັນທຶກ Q&A ໃໝ່ສໍາເລັດ."
59
 
60
+ save_manual_qa_file() # 1. Save locally
61
+ rebuild_combined_qa() # 2. Update memory
62
+ sync_upload_manual_qa() # 3. Upload to Cloud (NEW)
63
 
64
  return question, answer, current_id, _table(), msg
65
 
 
99
 
100
  save_manual_qa_file()
101
  rebuild_combined_qa()
102
+ sync_upload_manual_qa() # <--- Upload to Cloud (NEW)
103
 
104
  msg = "✅ ແກ້ໄຂ Q&A ສໍາເລັດ."
105
  return question, answer, current_id, _table(), msg
 
127
 
128
  save_manual_qa_file()
129
  rebuild_combined_qa()
130
+ sync_upload_manual_qa() # <--- Upload to Cloud (NEW)
131
 
132
  msg = "🗑️ ລຶບ Q&A ສໍາເລັດ."
133
  return "", "", "", _table(), msg
 
138
  ) -> Tuple[str, str, str, str]:
139
  """
140
  When teacher clicks a row in the Q&A table, load Q/A into textboxes.
 
 
 
 
141
  """
142
  try:
143
  if evt is None or evt.index is None or evt.row_value is None:
144
  raise ValueError("Empty select event")
145
 
 
146
  row = list(evt.row_value)
147
 
148
  current_id = str(row[0]) if len(row) > 0 else ""
 
160
  answer = ""
161
  msg = "⚠️ ບໍ່ສາມາດເລືອກແຖວໄດ້."
162
 
163
+ return question, answer, current_id, msg