Fix image display sizes with improved layout
Browse files- Switched from Interface to Blocks for better layout control
- Added custom CSS to ensure consistent image display sizes
- Created side-by-side comparison layout with input and enhanced output
- Set max-height and object-fit to maintain aspect ratios
- Full resolution output shown separately below comparison
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -722,7 +722,7 @@ def upscale_image(image):
|
|
| 722 |
return Image.fromarray(output_np)
|
| 723 |
|
| 724 |
|
| 725 |
-
# Gradio interface
|
| 726 |
def upscale_and_resize_for_display(image):
|
| 727 |
# Get the super-resolution output
|
| 728 |
upscaled = upscale_image(image)
|
|
@@ -732,18 +732,35 @@ def upscale_and_resize_for_display(image):
|
|
| 732 |
|
| 733 |
return upscaled, display_upscaled
|
| 734 |
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 747 |
|
| 748 |
if __name__ == "__main__":
|
| 749 |
iface.launch()
|
|
|
|
| 722 |
return Image.fromarray(output_np)
|
| 723 |
|
| 724 |
|
| 725 |
+
# Gradio interface using Blocks for better layout control
|
| 726 |
def upscale_and_resize_for_display(image):
|
| 727 |
# Get the super-resolution output
|
| 728 |
upscaled = upscale_image(image)
|
|
|
|
| 732 |
|
| 733 |
return upscaled, display_upscaled
|
| 734 |
|
| 735 |
+
# Custom CSS to ensure images display at same size
|
| 736 |
+
css = """
|
| 737 |
+
.image-container img {
|
| 738 |
+
max-width: 100% !important;
|
| 739 |
+
max-height: 400px !important;
|
| 740 |
+
object-fit: contain !important;
|
| 741 |
+
}
|
| 742 |
+
"""
|
| 743 |
+
|
| 744 |
+
with gr.Blocks(css=css, title="HAT Super-Resolution for Satellite Images") as iface:
|
| 745 |
+
gr.Markdown("# HAT Super-Resolution for Satellite Images")
|
| 746 |
+
gr.Markdown("Upload a satellite image to enhance its resolution by 4x using a fine-tuned HAT model. Compare the input with the enhanced version side-by-side.")
|
| 747 |
+
|
| 748 |
+
with gr.Row():
|
| 749 |
+
with gr.Column():
|
| 750 |
+
input_image = gr.Image(type="pil", label="Input Satellite Image", elem_classes=["image-container"])
|
| 751 |
+
submit_btn = gr.Button("Enhance Image", variant="primary")
|
| 752 |
+
|
| 753 |
+
with gr.Column():
|
| 754 |
+
comparison_output = gr.Image(type="pil", label="Enhanced Output (Same Size for Comparison)", elem_classes=["image-container"])
|
| 755 |
+
|
| 756 |
+
with gr.Row():
|
| 757 |
+
full_output = gr.Image(type="pil", label="Full Resolution Output (4x)")
|
| 758 |
+
|
| 759 |
+
submit_btn.click(
|
| 760 |
+
fn=upscale_and_resize_for_display,
|
| 761 |
+
inputs=input_image,
|
| 762 |
+
outputs=[full_output, comparison_output]
|
| 763 |
+
)
|
| 764 |
|
| 765 |
if __name__ == "__main__":
|
| 766 |
iface.launch()
|