TimeCapsuleX commited on
Commit
8b42bf4
·
1 Parent(s): 13cd9b4

Fixed Gradio table select crash

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -129,7 +129,7 @@ def build_rag_chain():
129
  """
130
  PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
131
 
132
- # Included the token-saving "k": 2 limit we discussed earlier!
133
  retriever = main_vector_store.as_retriever(search_kwargs={"k": 2})
134
  QA_CHAIN = RetrievalQA.from_chain_type(
135
  llm=llm,
@@ -240,11 +240,18 @@ if build_rag_chain():
240
  submit_feedback_btn = gr.Button("Submit Rating")
241
  feedback_status = gr.Textbox(label="Feedback Status", interactive=False)
242
 
243
- def update_selection(df, evt: gr.SelectData):
244
- if df is None or df.empty: return ""
245
- selected_row = df.iloc[evt.index[0]]
246
- action = selected_row['action']
247
- return action
 
 
 
 
 
 
 
248
 
249
  submit_btn.click(
250
  fn=fmea_rag_interface,
@@ -252,9 +259,10 @@ if build_rag_chain():
252
  outputs=[rpn_output, recommendations_output, df_state]
253
  )
254
 
 
255
  recommendations_output.select(
256
  fn=update_selection,
257
- inputs=[df_state],
258
  outputs=[selected_action_text]
259
  )
260
 
 
129
  """
130
  PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
131
 
132
+ # Included the token-saving "k": 2 limit
133
  retriever = main_vector_store.as_retriever(search_kwargs={"k": 2})
134
  QA_CHAIN = RetrievalQA.from_chain_type(
135
  llm=llm,
 
240
  submit_feedback_btn = gr.Button("Submit Rating")
241
  feedback_status = gr.Textbox(label="Feedback Status", interactive=False)
242
 
243
+ # FIX 1: New safer update_selection function
244
+ def update_selection(table_df, evt: gr.SelectData):
245
+ # Safety check if the table is empty
246
+ if table_df is None or len(table_df) == 0:
247
+ return ""
248
+
249
+ # evt.index gives us [row_index, column_index] of the click
250
+ row_idx = evt.index[0]
251
+
252
+ # "Recommended Action" is the 2nd column in your UI table (index 1)
253
+ selected_action = table_df.iloc[row_idx, 1]
254
+ return selected_action
255
 
256
  submit_btn.click(
257
  fn=fmea_rag_interface,
 
259
  outputs=[rpn_output, recommendations_output, df_state]
260
  )
261
 
262
+ # FIX 2: Trigger relies on the visible table (recommendations_output) instead of df_state
263
  recommendations_output.select(
264
  fn=update_selection,
265
+ inputs=[recommendations_output], # <-- Pass the visible table directly!
266
  outputs=[selected_action_text]
267
  )
268