cstr commited on
Commit
dacc767
·
verified ·
1 Parent(s): 6bbfcbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -15
app.py CHANGED
@@ -203,16 +203,26 @@ def update_model_info(model_name):
203
  """
204
  return "<p>Model information not available</p>"
205
 
206
- def update_category_models(category):
207
- """Update model list based on selected category"""
208
  for cat in MODELS:
209
  if cat["category"] == category:
210
  model_names = [model[0] for model in cat["models"]]
211
  if model_names:
212
- # Return the list of choices first, then the default value
213
- return model_names, model_names[0]
214
- return [], None
215
- return [], None
 
 
 
 
 
 
 
 
 
 
216
 
217
  def encode_image_to_base64(image_path):
218
  """Encode an image file to base64 string"""
@@ -718,12 +728,14 @@ def create_app():
718
  value=MODELS[0]["category"]
719
  )
720
 
721
- category_models = gr.Dropdown(
722
- [model[0] for model in MODELS[0]["models"]],
723
- label="Models in Category",
724
- value=MODELS[0]["models"][0][0],
725
- allow_custom_value=True
726
- )
 
 
727
 
728
  with gr.Accordion("Generation Parameters", open=False):
729
  with gr.Group(elem_classes="parameter-grid"):
@@ -917,10 +929,9 @@ def create_app():
917
 
918
  # Update model list when category changes
919
  model_categories.change(
920
- fn=update_category_models,
921
  inputs=model_categories,
922
- # The first output updates the choices, the second updates the value
923
- outputs=[category_models, category_models]
924
  )
925
 
926
  # Update main model choice when category model is selected
 
203
  """
204
  return "<p>Model information not available</p>"
205
 
206
+ def update_category_models_ui(category):
207
+ """Completely regenerate the models dropdown based on selected category"""
208
  for cat in MODELS:
209
  if cat["category"] == category:
210
  model_names = [model[0] for model in cat["models"]]
211
  if model_names:
212
+ # Return a completely new dropdown component
213
+ return gr.Dropdown(
214
+ choices=model_names,
215
+ value=model_names[0],
216
+ label="Models in Category",
217
+ allow_custom_value=True
218
+ )
219
+ # Return empty dropdown if no models found
220
+ return gr.Dropdown(
221
+ choices=[],
222
+ value=None,
223
+ label="Models in Category",
224
+ allow_custom_value=True
225
+ )
226
 
227
  def encode_image_to_base64(image_path):
228
  """Encode an image file to base64 string"""
 
728
  value=MODELS[0]["category"]
729
  )
730
 
731
+ # Create a container for the category models dropdown
732
+ with gr.Column(visible=True, elem_id="category-models-container") as category_models_container:
733
+ category_models = gr.Dropdown(
734
+ [model[0] for model in MODELS[0]["models"]],
735
+ label="Models in Category",
736
+ value=MODELS[0]["models"][0][0],
737
+ allow_custom_value=True
738
+ )
739
 
740
  with gr.Accordion("Generation Parameters", open=False):
741
  with gr.Group(elem_classes="parameter-grid"):
 
929
 
930
  # Update model list when category changes
931
  model_categories.change(
932
+ fn=update_category_models_ui,
933
  inputs=model_categories,
934
+ outputs=category_models_container
 
935
  )
936
 
937
  # Update main model choice when category model is selected