Spaces:
Restarting
Restarting
Update teacher_panel.py
Browse files- teacher_panel.py +24 -8
teacher_panel.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
# teacher_panel.py
|
| 2 |
-
from typing import List, Tuple
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import qa_store
|
| 5 |
from qa_store import normalize_question
|
|
@@ -128,20 +130,34 @@ def teacher_delete_current(
|
|
| 128 |
|
| 129 |
|
| 130 |
def teacher_on_table_select(
|
| 131 |
-
|
| 132 |
) -> Tuple[str, str, str, str]:
|
| 133 |
"""
|
| 134 |
When teacher clicks a row in the Q&A table, load Q/A into textboxes.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
"""
|
| 136 |
try:
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
| 138 |
idx = evt.index[0] if isinstance(evt.index, (list, tuple)) else evt.index
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
msg = f"✏️ ເລືອກ Q&A ID {current_id} ສໍາລັບແກ້ໄຂ."
|
| 144 |
-
except Exception: # noqa: BLE001
|
|
|
|
| 145 |
current_id = ""
|
| 146 |
question = ""
|
| 147 |
answer = ""
|
|
|
|
| 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
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
def teacher_on_table_select(
|
| 133 |
+
table: List[List[str]], evt: gr.SelectData
|
| 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 |
+
Gradio passes:
|
| 139 |
+
- table: current Dataframe value (list of rows)
|
| 140 |
+
- evt: gr.SelectData, where evt.index = (row, col)
|
| 141 |
"""
|
| 142 |
try:
|
| 143 |
+
if evt is None or evt.index is None:
|
| 144 |
+
raise ValueError("Empty select event")
|
| 145 |
+
|
| 146 |
+
# evt.index can be int or (row, col)
|
| 147 |
idx = evt.index[0] if isinstance(evt.index, (list, tuple)) else evt.index
|
| 148 |
+
|
| 149 |
+
if idx is None or idx < 0 or idx >= len(table):
|
| 150 |
+
raise IndexError(f"Row index {idx} out of range")
|
| 151 |
+
|
| 152 |
+
row = table[idx] # row should be [id, question, answer]
|
| 153 |
+
|
| 154 |
+
current_id = str(row[0]) if len(row) > 0 else ""
|
| 155 |
+
question = str(row[1]) if len(row) > 1 else ""
|
| 156 |
+
answer = str(row[2]) if len(row) > 2 else ""
|
| 157 |
+
|
| 158 |
msg = f"✏️ ເລືອກ Q&A ID {current_id} ສໍາລັບແກ້ໄຂ."
|
| 159 |
+
except Exception as e: # noqa: BLE001
|
| 160 |
+
print(f"[WARN] teacher_on_table_select error: {e}")
|
| 161 |
current_id = ""
|
| 162 |
question = ""
|
| 163 |
answer = ""
|