Upload app.py with huggingface_hub
Browse files
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(
|
| 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
|
| 597 |
-
|
| 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 |
-
|
| 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=[
|
| 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 |
|