Chris Addis commited on
Commit
8409208
·
1 Parent(s): 7d4e66e

fix additional models

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -239,20 +239,32 @@ def create_demo():
239
  all_images = gr.State([])
240
  all_results = gr.State([])
241
 
242
- # Handle checkbox change to update model dropdown
243
  def toggle_models(show_all, current_model):
 
 
 
 
244
  if show_all:
245
- return gr.Dropdown.update(choices=all_models, value=current_model)
 
246
  else:
247
  # Check if current model is in preferred models list
248
- is_preferred = any(current_model == value for _, value in preferred_models)
249
 
250
- if is_preferred:
251
  # Keep the current model if it's in preferred models
252
- return gr.Dropdown.update(choices=preferred_models, value=current_model)
253
  else:
254
  # Reset to default model if current model is not in preferred models
255
- return gr.Dropdown.update(choices=preferred_models, value=default_model)
 
 
 
 
 
 
 
256
 
257
  # Update model info when model selection changes
258
  def update_model_info(model_value):
@@ -278,13 +290,6 @@ def create_demo():
278
  outputs=[model_choice]
279
  )
280
 
281
- # Connect model selection to update info
282
- model_choice.change(
283
- fn=update_model_info,
284
- inputs=[model_choice],
285
- outputs=[model_info]
286
- )
287
-
288
  # Handle file uploads
289
  def handle_upload(files, current_paths, current_filenames):
290
  file_paths = []
 
239
  all_images = gr.State([])
240
  all_results = gr.State([])
241
 
242
+ # Handle checkbox change to update model dropdown
243
  def toggle_models(show_all, current_model):
244
+ # Make a fresh copy of the models lists to avoid any reference issues
245
+ preferred_choices = list(preferred_models)
246
+ all_choices = list(all_models_list)
247
+
248
  if show_all:
249
+ # When showing all models, use the fresh copy of all models
250
+ return gr.Dropdown(choices=all_choices, value=current_model)
251
  else:
252
  # Check if current model is in preferred models list
253
+ preferred_values = [value for _, value in preferred_choices]
254
 
255
+ if current_model in preferred_values:
256
  # Keep the current model if it's in preferred models
257
+ return gr.Dropdown(choices=preferred_choices, value=current_model)
258
  else:
259
  # Reset to default model if current model is not in preferred models
260
+ return gr.Dropdown(choices=preferred_choices, value=default_model)
261
+
262
+ # Connect checkbox to toggle model choices - keep this the same
263
+ show_all_models.change(
264
+ fn=toggle_models,
265
+ inputs=[show_all_models, model_choice],
266
+ outputs=[model_choice]
267
+ )
268
 
269
  # Update model info when model selection changes
270
  def update_model_info(model_value):
 
290
  outputs=[model_choice]
291
  )
292
 
 
 
 
 
 
 
 
293
  # Handle file uploads
294
  def handle_upload(files, current_paths, current_filenames):
295
  file_paths = []