Dhenenjay commited on
Commit
7f03507
·
verified ·
1 Parent(s): 2391ce4

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -581,10 +581,13 @@ def load_sar_image(filepath):
581
  return Image.open(filepath).convert('RGB')
582
 
583
 
584
- def translate_sar(image, num_steps, overlap, enhance):
585
  """Main translation function."""
586
  global model
587
 
 
 
 
588
  if model is None:
589
  print("Loading model...")
590
  model = E3DiffHighRes()
@@ -592,9 +595,9 @@ def translate_sar(image, num_steps, overlap, enhance):
592
 
593
  print("Processing image...")
594
 
595
- # Handle file upload
596
- if isinstance(image, str):
597
- image = load_sar_image(image)
598
 
599
  w, h = image.size
600
  print(f"Input size: {w}x{h}")
@@ -644,7 +647,7 @@ with gr.Blocks(title="E3Diff: SAR-to-Optical Translation") as demo:
644
 
645
  with gr.Row():
646
  with gr.Column():
647
- input_image = gr.Image(label="SAR Input", type="pil")
648
 
649
  with gr.Row():
650
  num_steps = gr.Slider(1, 8, value=1, step=1, label="Quality Steps (1=fast, 4-8=high quality)")
@@ -661,7 +664,7 @@ with gr.Blocks(title="E3Diff: SAR-to-Optical Translation") as demo:
661
 
662
  submit_btn.click(
663
  fn=translate_sar,
664
- inputs=[input_image, num_steps, overlap, enhance],
665
  outputs=[output_image, output_file, info_text]
666
  )
667
 
 
581
  return Image.open(filepath).convert('RGB')
582
 
583
 
584
+ def translate_sar(file, num_steps, overlap, enhance):
585
  """Main translation function."""
586
  global model
587
 
588
+ if file is None:
589
+ return None, None, "Please upload a SAR image"
590
+
591
  if model is None:
592
  print("Loading model...")
593
  model = E3DiffHighRes()
 
595
 
596
  print("Processing image...")
597
 
598
+ # Handle file upload - get the filepath
599
+ filepath = file.name if hasattr(file, 'name') else file
600
+ image = load_sar_image(filepath)
601
 
602
  w, h = image.size
603
  print(f"Input size: {w}x{h}")
 
647
 
648
  with gr.Row():
649
  with gr.Column():
650
+ input_file = gr.File(label="SAR Input (TIFF, PNG, JPG supported)", file_types=[".tif", ".tiff", ".png", ".jpg", ".jpeg"])
651
 
652
  with gr.Row():
653
  num_steps = gr.Slider(1, 8, value=1, step=1, label="Quality Steps (1=fast, 4-8=high quality)")
 
664
 
665
  submit_btn.click(
666
  fn=translate_sar,
667
+ inputs=[input_file, num_steps, overlap, enhance],
668
  outputs=[output_image, output_file, info_text]
669
  )
670