I am trying to work on a feature in the Gradio App, where the user selects a value from a dropdown, lets call this PF dropdown. So different PFs have different number of output varibales and say different output varibales have different number of models that we have saved.
Now, after this first selection from the dropdown, the user clicks an "Export" button which triggers the flow where, Total number of ouput varibles in the selected PF are calculated, then the models saved per output varibale are checked then should return this informtation in dropdowns, one dropdown per output varibale. If the output variable had no model saved then we get a NONE option for this, we do have NONE for all the dropdowns too. So the user should be able to see all these dropdowns and make selections.
After making selections some zipping and download flow is triggered.
Everything seems to be working, except i am not able to get the UI updated. That is, I ran through several iterations of
debugging and could see the dropdowns being returned, but unable to update them on UI.
"""This is all under a Gradio tab, tab starts here."""
with gr.Row():
model_delete_button = gr.Button("Delete Model", variant="stop")
model_dropdown_column = gr.Column(visible=False)
def update_dropdowns(problem_name):
col_update, new_dropdowns = show_model_selection(problem_name)
print("Updating dropdowns with:", new_dropdowns)
return gr.Column(new_dropdowns, visible=True)
def show_model_selection(problem_name):
"""Dynamically create dropdowns for each output variable."""
problem_data = load_problem_formulation(problem_name)
if not problem_data:
return gr.update(visible=False), []
output_vars = problem_data["output_variables"]
dropdowns = [gr.Dropdown(choices=get_available_models(var), value="None", label=f"Select model for {var}") for var in output_vars]
return gr.update(visible=True), dropdowns
def get_available_models(output_var):
"""Fetch saved models for a specific output variable."""
model_files = [f.replace(".pkl", "") for f in os.listdir(SAVED_MODELS_DIR) if f.endswith(".pkl")]
models_for_output = [m for m in model_files if m.endswith(output_var)]
return ["None"] + models_for_output if models_for_output else ["None"]
export_to_set_button.click(
update_dropdowns,
inputs=[problems],
outputs=model_dropdown_column
)
Also here is the output of the print if that helps:
Updating dropdowns with: [<gradioponents.dropdown.Dropdown object at 0x000001976674BFA0>, <gradioponents.dropdown.Dropdown object at 0x000001976674BFD0>, <gradioponents.dropdown.Dropdown object at 0x000001976674BF70>]
Apologies for the mismatches in return and types, tried so many things that it got hard to keep track of which was for what. Thanks for the help. You are awesome.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744371247a4570963.html
评论列表(0条)