Chris Addis commited on
Commit
fea3c74
·
1 Parent(s): 7aa90ae

Advanced settings

Browse files
Files changed (1) hide show
  1. app.py +22 -16
app.py CHANGED
@@ -37,14 +37,14 @@ os.makedirs(os.path.dirname(PREFERENCES_FILE), exist_ok=True)
37
 
38
  # Define model pricing information (approximate costs per 100 image API calls)
39
  MODEL_PRICING = {
40
- "google/gemini-2.0-flash-001": "$0.50",
41
- "gpt-4.1-mini": "$2.00",
42
- "gpt-4.1": "$5.00",
43
- "anthropic/claude-3.7-sonnet": "$4.00",
44
- "google/gemini-2.5-pro-preview-03-25": "$1.50",
45
- "google/gemini-2.5-flash-preview:thinking": "$0.75",
46
- "gpt-4.1-nano": "$1.00",
47
- "openai/chatgpt-4o-latest": "$4.50",
48
  "meta-llama/llama-4-maverick": "$0.25"
49
  }
50
 
@@ -239,15 +239,21 @@ def create_demo():
239
  all_images = gr.State([])
240
  all_results = gr.State([])
241
 
242
- # Define functions within the demo function to avoid scope issues
243
-
244
- # Handle checkbox change to update model dropdown
245
- def toggle_models(show_all):
246
  if show_all:
247
- return gr.Dropdown.update(choices=all_models)
248
  else:
249
- return gr.Dropdown.update(choices=preferred_models)
250
-
 
 
 
 
 
 
 
 
251
  # Update model info when model selection changes
252
  def update_model_info(model_value):
253
  # Find display name
@@ -268,7 +274,7 @@ def create_demo():
268
  # Connect checkbox to toggle model choices
269
  show_all_models.change(
270
  fn=toggle_models,
271
- inputs=[show_all_models],
272
  outputs=[model_choice]
273
  )
274
 
 
37
 
38
  # Define model pricing information (approximate costs per 100 image API calls)
39
  MODEL_PRICING = {
40
+ "google/gemini-2.0-flash-001": "$0.03",
41
+ "gpt-4.1-mini": "$0.07",
42
+ "gpt-4.1": "$0.35",
43
+ "anthropic/claude-3.7-sonnet": "$0.70",
44
+ "google/gemini-2.5-pro-preview-03-25": "$1.20",
45
+ "google/gemini-2.5-flash-preview:thinking": "$0.35",
46
+ "gpt-4.1-nano": "$0.02",
47
+ "openai/chatgpt-4o-latest": "$0.75",
48
  "meta-llama/llama-4-maverick": "$0.25"
49
  }
50
 
 
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):
259
  # Find display name
 
274
  # Connect checkbox to toggle model choices
275
  show_all_models.change(
276
  fn=toggle_models,
277
+ inputs=[show_all_models, model_choice],
278
  outputs=[model_choice]
279
  )
280