leharris3 Claude Opus 4.5 commited on
Commit
99586dc
Β·
1 Parent(s): f8b3790

Replace ImageSlider with side-by-side gr.Image components

Browse files

ImageSlider is only available as a third-party component with
compatibility issues. Using two standard gr.Image components
side-by-side is more reliable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -364,12 +364,13 @@ def run_inference(
364
  device_str: str,
365
  colormap: str,
366
  export_format: str,
367
- ) -> Tuple[Optional[Tuple[np.ndarray, np.ndarray]], dict, Optional[str], str]:
368
  """
369
  Main inference function.
370
 
371
  Returns:
372
- - (input_image, output_image) tuple for ImageSlider
 
373
  - statistics dictionary
374
  - path to downloadable file
375
  - status/warning message
@@ -378,7 +379,7 @@ def run_inference(
378
  use_demo = demo_sample and demo_sample != "Upload your own"
379
 
380
  if not use_demo and file is None:
381
- return None, {}, None, "Please select a demo sample or upload an image file."
382
 
383
  try:
384
  # Load input
@@ -451,10 +452,10 @@ def run_inference(
451
  # Save to requested format
452
  download_path = save_to_format(output_denorm, export_format, colormap)
453
 
454
- return (input_colored, output_colored), stats, download_path, status
455
 
456
  except Exception as e:
457
- return None, {}, None, f"Error: {str(e)}"
458
 
459
 
460
  # ─────────────────────────────────────────────────────────────────────────────
@@ -521,11 +522,16 @@ def create_app() -> gr.Blocks:
521
 
522
  # Right column: outputs
523
  with gr.Column(scale=2):
524
- # Image comparison slider
525
- image_slider = gr.ImageSlider(
526
- label="Original (left) vs Upsampled (right)",
527
- type="numpy",
528
- )
 
 
 
 
 
529
 
530
  with gr.Row():
531
  # Statistics panel
@@ -542,7 +548,7 @@ def create_app() -> gr.Blocks:
542
  run_button.click(
543
  fn=run_inference,
544
  inputs=[file_input, demo_dropdown, scale_dropdown, device_dropdown, colormap_dropdown, export_dropdown],
545
- outputs=[image_slider, stats_output, download_output, status_box],
546
  )
547
 
548
  return app
 
364
  device_str: str,
365
  colormap: str,
366
  export_format: str,
367
+ ) -> Tuple[Optional[np.ndarray], Optional[np.ndarray], dict, Optional[str], str]:
368
  """
369
  Main inference function.
370
 
371
  Returns:
372
+ - input_image for display
373
+ - output_image for display
374
  - statistics dictionary
375
  - path to downloadable file
376
  - status/warning message
 
379
  use_demo = demo_sample and demo_sample != "Upload your own"
380
 
381
  if not use_demo and file is None:
382
+ return None, None, {}, None, "Please select a demo sample or upload an image file."
383
 
384
  try:
385
  # Load input
 
452
  # Save to requested format
453
  download_path = save_to_format(output_denorm, export_format, colormap)
454
 
455
+ return input_colored, output_colored, stats, download_path, status
456
 
457
  except Exception as e:
458
+ return None, None, {}, None, f"Error: {str(e)}"
459
 
460
 
461
  # ─────────────────────────────────────────────────────────────────────────────
 
522
 
523
  # Right column: outputs
524
  with gr.Column(scale=2):
525
+ # Image comparison - side by side
526
+ with gr.Row():
527
+ input_image = gr.Image(
528
+ label="Original",
529
+ type="numpy",
530
+ )
531
+ output_image = gr.Image(
532
+ label="Upsampled",
533
+ type="numpy",
534
+ )
535
 
536
  with gr.Row():
537
  # Statistics panel
 
548
  run_button.click(
549
  fn=run_inference,
550
  inputs=[file_input, demo_dropdown, scale_dropdown, device_dropdown, colormap_dropdown, export_dropdown],
551
+ outputs=[input_image, output_image, stats_output, download_output, status_box],
552
  )
553
 
554
  return app