Chris Addis commited on
Commit
02cc108
·
1 Parent(s): bf57f6a
Files changed (1) hide show
  1. app.py +36 -20
app.py CHANGED
@@ -94,7 +94,7 @@ def get_base_filename(filepath):
94
 
95
  # Define the Gradio interface
96
  def create_demo():
97
- # --- Reintroduce CSS ---
98
  custom_css = """
99
  /* Container for the image component (#current-image-display is the elem_id of gr.Image) */
100
  #current-image-display {
@@ -115,6 +115,15 @@ def create_demo():
115
  height: auto; /* Use natural height unless constrained by max-height */
116
  display: block; /* Ensure image behaves predictably in flex */
117
  }
 
 
 
 
 
 
 
 
 
118
  """
119
  # --- Pass css to gr.Blocks ---
120
  with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
@@ -154,7 +163,7 @@ def create_demo():
154
  ]
155
 
156
  # Calculate all models once
157
- all_models = preferred_models + additional_models
158
 
159
  # Default model value
160
  default_model = "google/gemini-2.0-flash-001"
@@ -195,12 +204,20 @@ def create_demo():
195
  label="Content Type",
196
  value="Museum Object"
197
  )
198
-
199
- # Display current model info
200
- model_info = gr.Markdown(
201
- f"""**Current Model**: Gemini 2.0 Flash (default)
202
- **Cost per 100 Images**: {MODEL_PRICING[default_model]}"""
203
- )
 
 
 
 
 
 
 
 
204
 
205
  gr.Markdown("### Uploaded Images")
206
  input_gallery = gr.Gallery(
@@ -239,11 +256,11 @@ 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
  # 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)
247
 
248
  if show_all:
249
  # When showing all models, use the fresh copy of all models
@@ -258,23 +275,15 @@ def create_demo():
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):
271
  # Find display name
272
- for name, value in all_models:
 
273
  if value == model_value:
274
  model_name = name
275
  break
276
- else:
277
- model_name = "Unknown Model"
278
 
279
  # Get cost
280
  cost = MODEL_PRICING.get(model_value, "Unknown")
@@ -290,6 +299,13 @@ def create_demo():
290
  outputs=[model_choice]
291
  )
292
 
 
 
 
 
 
 
 
293
  # Handle file uploads
294
  def handle_upload(files, current_paths, current_filenames):
295
  file_paths = []
 
94
 
95
  # Define the Gradio interface
96
  def create_demo():
97
+ # --- Updated CSS with model info styling ---
98
  custom_css = """
99
  /* Container for the image component (#current-image-display is the elem_id of gr.Image) */
100
  #current-image-display {
 
115
  height: auto; /* Use natural height unless constrained by max-height */
116
  display: block; /* Ensure image behaves predictably in flex */
117
  }
118
+
119
+ /* Custom style for model info display */
120
+ #model-info-display {
121
+ font-size: 0.85rem; /* Small font size */
122
+ color: #666; /* Subtle color */
123
+ margin-top: 0.5rem; /* Small top margin */
124
+ margin-bottom: 1rem; /* Bottom margin before next element */
125
+ padding-left: 0.5rem; /* Slight indentation */
126
+ }
127
  """
128
  # --- Pass css to gr.Blocks ---
129
  with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
 
163
  ]
164
 
165
  # Calculate all models once
166
+ all_models_list = preferred_models + additional_models
167
 
168
  # Default model value
169
  default_model = "google/gemini-2.0-flash-001"
 
204
  label="Content Type",
205
  value="Museum Object"
206
  )
207
+
208
+ # Find the default model's display name
209
+ default_model_name = "Unknown Model"
210
+ for name, value in preferred_models:
211
+ if value == default_model:
212
+ default_model_name = name
213
+ break
214
+
215
+ # Model info outside the accordion
216
+ model_info = gr.Markdown(
217
+ f"""**Current Model**: {default_model_name}
218
+ **Cost per 100 Images**: {MODEL_PRICING[default_model]}""",
219
+ elem_id="model-info-display"
220
+ )
221
 
222
  gr.Markdown("### Uploaded Images")
223
  input_gallery = gr.Gallery(
 
256
  all_images = gr.State([])
257
  all_results = gr.State([])
258
 
259
+ # Handle checkbox change to update model dropdown - modern version
260
  def toggle_models(show_all, current_model):
261
  # Make a fresh copy of the models lists to avoid any reference issues
262
  preferred_choices = list(preferred_models)
263
+ all_choices = list(all_models_list)
264
 
265
  if show_all:
266
  # When showing all models, use the fresh copy of all models
 
275
  else:
276
  # Reset to default model if current model is not in preferred models
277
  return gr.Dropdown(choices=preferred_choices, value=default_model)
 
 
 
 
 
 
 
278
 
279
  # Update model info when model selection changes
280
  def update_model_info(model_value):
281
  # Find display name
282
+ model_name = "Unknown Model"
283
+ for name, value in all_models_list:
284
  if value == model_value:
285
  model_name = name
286
  break
 
 
287
 
288
  # Get cost
289
  cost = MODEL_PRICING.get(model_value, "Unknown")
 
299
  outputs=[model_choice]
300
  )
301
 
302
+ # Connect model selection to update info
303
+ model_choice.change(
304
+ fn=update_model_info,
305
+ inputs=[model_choice],
306
+ outputs=[model_info]
307
+ )
308
+
309
  # Handle file uploads
310
  def handle_upload(files, current_paths, current_filenames):
311
  file_paths = []