Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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("###
|
| 352 |
-
gr.Markdown("
|
| 353 |
-
with gr.
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
|
|
|
| 357 |
|
| 358 |
def update_inputs(file, label_col):
|
| 359 |
-
print(f"
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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])
|