jaker86 commited on
Commit
3ee9608
·
verified ·
1 Parent(s): 2fe6c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -264,14 +264,14 @@ def create_interactive_inputs(file, label_col):
264
  return []
265
 
266
  X = df.drop(columns=[label_col])
267
- inputs = []
268
  for col in X.columns:
269
  examples = X[col].dropna().sample(min(3, len(X[col].dropna()))).tolist()
270
  if pd.api.types.is_numeric_dtype(X[col]):
271
- inputs.append(gr.Number(label=f"{col} (e.g., {', '.join(map(str, examples))})"))
272
  else:
273
- inputs.append(gr.Textbox(label=f"{col} (e.g., {', '.join(map(str, examples))})"))
274
- return inputs
275
  except Exception:
276
  return []
277
 
@@ -325,15 +325,25 @@ with gr.Blocks() as demo:
325
  with gr.TabItem("Interactive"):
326
  gr.Markdown("### Interactive Prediction")
327
  gr.Markdown("Enter values for each feature to get a prediction based on the trained model.")
328
- interactive_inputs = gr.State(value=[])
329
  with gr.Column():
330
- input_components = gr.DynamicLayout(fn=create_interactive_inputs, inputs=[file_input, label_dropdown], outputs=interactive_inputs)
 
331
  predict_btn = gr.Button("Predict")
332
  prediction_output = gr.Textbox(label="Prediction Result")
333
 
 
 
 
 
 
 
 
 
 
 
334
  predict_btn.click(
335
  fn=predict_interactive,
336
- inputs=interactive_inputs,
337
  outputs=prediction_output
338
  )
339
 
 
264
  return []
265
 
266
  X = df.drop(columns=[label_col])
267
+ components = []
268
  for col in X.columns:
269
  examples = X[col].dropna().sample(min(3, len(X[col].dropna()))).tolist()
270
  if pd.api.types.is_numeric_dtype(X[col]):
271
+ components.append(gr.Number(label=f"{col} (e.g., {', '.join(map(str, examples))})"))
272
  else:
273
+ components.append(gr.Textbox(label=f"{col} (e.g., {', '.join(map(str, examples))})"))
274
+ return components
275
  except Exception:
276
  return []
277
 
 
325
  with gr.TabItem("Interactive"):
326
  gr.Markdown("### Interactive Prediction")
327
  gr.Markdown("Enter values for each feature to get a prediction based on the trained model.")
 
328
  with gr.Column():
329
+ interactive_inputs = gr.State(value=[])
330
+ input_components = gr.Column()
331
  predict_btn = gr.Button("Predict")
332
  prediction_output = gr.Textbox(label="Prediction Result")
333
 
334
+ file_input.change(
335
+ fn=create_interactive_inputs,
336
+ inputs=[file_input, label_dropdown],
337
+ outputs=input_components
338
+ )
339
+ label_dropdown.change(
340
+ fn=create_interactive_inputs,
341
+ inputs=[file_input, label_dropdown],
342
+ outputs=input_components
343
+ )
344
  predict_btn.click(
345
  fn=predict_interactive,
346
+ inputs=input_components,
347
  outputs=prediction_output
348
  )
349