prateeksharmacoder commited on
Commit
2e80d4c
·
1 Parent(s): 0fafc69

Fix 3-band TIFF channel sorting bug caused by Gradio tmp dir paths

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -536,12 +536,16 @@ def run_super_resolution(image_path, model_choice, progress=gr.Progress()):
536
  if not all(p.lower().endswith(('.tif', '.tiff')) for p in paths):
537
  raise gr.Error("When uploading multiple files, all must be TIFF files.")
538
 
539
- red_path = next((p for p in paths if "B04" in p.upper()), None)
540
- green_path = next((p for p in paths if "B03" in p.upper()), None)
541
- blue_path = next((p for p in paths if "B02" in p.upper()), None)
 
 
 
542
 
543
  if not (red_path and green_path and blue_path):
544
- paths = sorted(paths)
 
545
  blue_path, green_path, red_path = paths[0], paths[1], paths[2]
546
 
547
  try:
 
536
  if not all(p.lower().endswith(('.tif', '.tiff')) for p in paths):
537
  raise gr.Error("When uploading multiple files, all must be TIFF files.")
538
 
539
+ def get_basename(p):
540
+ return Path(p).name.upper()
541
+
542
+ red_path = next((p for p in paths if "B04" in get_basename(p) or "B4" in get_basename(p)), None)
543
+ green_path = next((p for p in paths if "B03" in get_basename(p) or "B3" in get_basename(p)), None)
544
+ blue_path = next((p for p in paths if "B02" in get_basename(p) or "B2" in get_basename(p)), None)
545
 
546
  if not (red_path and green_path and blue_path):
547
+ # Sort by filename (not full path, to avoid Gradio temp dir randomness)
548
+ paths = sorted(paths, key=lambda p: Path(p).name)
549
  blue_path, green_path, red_path = paths[0], paths[1], paths[2]
550
 
551
  try: