jaker86 commited on
Commit
1ed57a6
·
verified ·
1 Parent(s): fdf0d81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -348,26 +348,39 @@ with gr.Blocks() as demo:
348
  diff_output = gr.Image(label="Differentiating Features")
349
 
350
  with gr.TabItem("Interactive"):
351
- gr.Markdown("### interactive prediction")
352
- gr.Markdown("enter values for each feature to get a prediction based on the trained model.")
353
- with gr.Form() as interactive_form:
354
- dynamic_inputs = gr.Column() # container for the dynamic input components
355
- predict_btn = gr.Button("predict") # now inside the form
356
- prediction_output = gr.Textbox(label="prediction result")
 
357
 
358
  def update_inputs(file, label_col):
359
- print(f"updating inputs with file: {file}, label_col: {label_col}")
360
- if file is None or label_col is None:
361
- return gr.Column.update(visible=False)
362
  components = create_interactive_inputs(file, label_col)
363
- return gr.Column.update(visible=True, children=components)
 
 
 
 
 
364
 
365
- # bind changes to update dynamic_inputs:
366
- file_input.change(fn=update_inputs, inputs=[file_input, label_dropdown], outputs=dynamic_inputs)
367
- label_dropdown.change(fn=update_inputs, inputs=[file_input, label_dropdown], outputs=dynamic_inputs)
368
-
369
- # bind the form submit to prediction (this collects values from all inputs inside the form):
370
- interactive_form.submit(fn=predict_interactive, inputs=dynamic_inputs, outputs=prediction_output)
 
 
 
 
 
 
 
 
 
371
 
372
  analyze_btn.click(fn=analyze_file, inputs=[file_input, label_dropdown, clusters_slider],
373
  outputs=[results_textbox, model_img_output, fi_output, kmeans_output, agg_output, diff_output])
 
348
  diff_output = gr.Image(label="Differentiating Features")
349
 
350
  with gr.TabItem("Interactive"):
351
+ gr.Markdown("### Interactive Prediction")
352
+ gr.Markdown("Enter values for each feature to get a prediction based on the trained model.")
353
+ with gr.Column():
354
+ input_components = gr.State(value=[])
355
+ dynamic_inputs = gr.Column(visible=True)
356
+ predict_btn = gr.Button("Predict")
357
+ prediction_output = gr.Textbox(label="Prediction Result")
358
 
359
  def update_inputs(file, label_col):
360
+ print(f"Updating inputs with file: {file}, label_col: {label_col}") # Debug logging
 
 
361
  components = create_interactive_inputs(file, label_col)
362
+ # Return the components and update the Column's visibility
363
+ return components, gr.update(visible=True) # Only update visibility, components are rendered in Blocks
364
+ # Use Blocks to render components dynamically
365
+ with dynamic_inputs:
366
+ for component in components:
367
+ component.render()
368
 
369
+ file_input.change(
370
+ fn=update_inputs,
371
+ inputs=[file_input, label_dropdown],
372
+ outputs=[input_components, dynamic_inputs]
373
+ )
374
+ label_dropdown.change(
375
+ fn=update_inputs,
376
+ inputs=[file_input, label_dropdown],
377
+ outputs=[input_components, dynamic_inputs]
378
+ )
379
+ predict_btn.click(
380
+ fn=predict_interactive,
381
+ inputs=input_components,
382
+ outputs=prediction_output
383
+ )
384
 
385
  analyze_btn.click(fn=analyze_file, inputs=[file_input, label_dropdown, clusters_slider],
386
  outputs=[results_textbox, model_img_output, fi_output, kmeans_output, agg_output, diff_output])