Spaces:
Running
Running
Refactor table selection handler: Enhance row selection logic by passing dataframe as input for improved error handling and clarity
Browse files
app.py
CHANGED
|
@@ -1205,28 +1205,33 @@ with gr.Blocks(css="""
|
|
| 1205 |
outputs=[qa_table]
|
| 1206 |
)
|
| 1207 |
|
| 1208 |
-
def on_table_select(evt: gr.SelectData)
|
| 1209 |
-
"""Handle table row selection"""
|
| 1210 |
try:
|
| 1211 |
-
# Get the selected row index
|
| 1212 |
row_index = evt.index[0]
|
| 1213 |
|
| 1214 |
-
#
|
| 1215 |
-
|
| 1216 |
-
|
| 1217 |
-
|
| 1218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1219 |
except Exception as e:
|
| 1220 |
logger.error(f"Error in table selection: {str(e)}")
|
|
|
|
|
|
|
| 1221 |
return ""
|
| 1222 |
|
| 1223 |
-
#
|
| 1224 |
qa_table.select(
|
| 1225 |
fn=on_table_select,
|
| 1226 |
-
inputs=[],
|
| 1227 |
outputs=[selected_conversation]
|
| 1228 |
)
|
| 1229 |
-
|
| 1230 |
# Load conversation for evaluation
|
| 1231 |
load_btn.click(
|
| 1232 |
fn=lambda x: load_qa_pair_for_evaluation(conversation_id=x, evaluator=chat_evaluator),
|
|
|
|
| 1205 |
outputs=[qa_table]
|
| 1206 |
)
|
| 1207 |
|
| 1208 |
+
def on_table_select(evt: gr.SelectData, dataframe):
|
| 1209 |
+
"""Handle table row selection using the dataframe input"""
|
| 1210 |
try:
|
| 1211 |
+
# Get the selected row index
|
| 1212 |
row_index = evt.index[0]
|
| 1213 |
|
| 1214 |
+
# Access the dataframe passed as input parameter
|
| 1215 |
+
if dataframe is not None and len(dataframe) > row_index:
|
| 1216 |
+
# Get conversation ID from first column
|
| 1217 |
+
conversation_id = str(dataframe.iloc[row_index, 0])
|
| 1218 |
+
logger.info(f"Selected conversation ID: {conversation_id}")
|
| 1219 |
+
return conversation_id
|
| 1220 |
+
else:
|
| 1221 |
+
logger.error("DataFrame is empty or row index out of bounds")
|
| 1222 |
+
return ""
|
| 1223 |
except Exception as e:
|
| 1224 |
logger.error(f"Error in table selection: {str(e)}")
|
| 1225 |
+
import traceback
|
| 1226 |
+
logger.error(traceback.format_exc())
|
| 1227 |
return ""
|
| 1228 |
|
| 1229 |
+
# Update the table row selection handler to include the dataframe as input
|
| 1230 |
qa_table.select(
|
| 1231 |
fn=on_table_select,
|
| 1232 |
+
inputs=[qa_table], # Pass the table itself as input
|
| 1233 |
outputs=[selected_conversation]
|
| 1234 |
)
|
|
|
|
| 1235 |
# Load conversation for evaluation
|
| 1236 |
load_btn.click(
|
| 1237 |
fn=lambda x: load_qa_pair_for_evaluation(conversation_id=x, evaluator=chat_evaluator),
|