Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,7 +66,7 @@ def standard_upscale(img):
|
|
| 66 |
w, h = img.size
|
| 67 |
|
| 68 |
if w > max_input_dim or h > max_input_dim:
|
| 69 |
-
gr.Warning(f"Input image exceeded the 2K ({max_input_dim}px) limit. It has been proportionally downscaled to ensure the 4K output fits in server memory.")
|
| 70 |
scale = max_input_dim / max(w, h)
|
| 71 |
w, h = int(w * scale), int(h * scale)
|
| 72 |
img = img.resize((w, h), Image.BICUBIC)
|
|
@@ -84,8 +84,8 @@ def standard_upscale(img):
|
|
| 84 |
|
| 85 |
details = (
|
| 86 |
f"### Resolution Details\n"
|
| 87 |
-
f"**Before:** {w} x {h} ({w * h:,} pixels)\n\n"
|
| 88 |
-
f"**After:** {new_w} x {new_h} ({new_w * new_h:,} pixels)"
|
| 89 |
)
|
| 90 |
|
| 91 |
return output_img, details
|
|
@@ -125,9 +125,9 @@ def benchmark_upscale(hr_img):
|
|
| 125 |
|
| 126 |
details = (
|
| 127 |
f"### Benchmark Results\n"
|
| 128 |
-
f"**PSNR:** {psnr:.2f} dB\n\n"
|
| 129 |
-
f"**Low-Res Input:** {lr_w} x {lr_h} ({lr_w * lr_h:,} pixels)\n\n"
|
| 130 |
-
f"**Model Output & Ground Truth:** {w} x {h} ({w * h:,} pixels)"
|
| 131 |
)
|
| 132 |
|
| 133 |
# Gradio's native ImageSlider expects a tuple of (image1, image2)
|
|
@@ -139,6 +139,18 @@ with gr.Blocks() as app:
|
|
| 139 |
"""
|
| 140 |
# ⚡ FastEDSR 2x Image Upscaler
|
| 141 |
Upload an image to enhance and upscale it by 2x. Supports up to 4K resolution output.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
"""
|
| 143 |
)
|
| 144 |
|
|
@@ -158,7 +170,7 @@ with gr.Blocks() as app:
|
|
| 158 |
|
| 159 |
# TAB 2: BENCHMARK
|
| 160 |
with gr.TabItem("📊 Benchmark Mode"):
|
| 161 |
-
gr.Markdown("Upload a high-quality image (up to 4K). The app will compress it to 2x lower resolution, upscale it using FastEDSR, and measure the PSNR quality against the original.")
|
| 162 |
with gr.Row():
|
| 163 |
with gr.Column():
|
| 164 |
bm_input = gr.Image(type="pil", label="Ground Truth (High Res) Image")
|
|
|
|
| 66 |
w, h = img.size
|
| 67 |
|
| 68 |
if w > max_input_dim or h > max_input_dim:
|
| 69 |
+
gr.Warning(f"Input image exceeded the 2K ({max_input_dim}px) limit. It has been proportionally downscaled to ensure the 4K output fits in server memory and constraints.")
|
| 70 |
scale = max_input_dim / max(w, h)
|
| 71 |
w, h = int(w * scale), int(h * scale)
|
| 72 |
img = img.resize((w, h), Image.BICUBIC)
|
|
|
|
| 84 |
|
| 85 |
details = (
|
| 86 |
f"### Resolution Details\n"
|
| 87 |
+
f"- **Before:** {w} x {h} ({w * h:,} pixels)\n\n"
|
| 88 |
+
f"- **After:** {new_w} x {new_h} ({new_w * new_h:,} pixels)"
|
| 89 |
)
|
| 90 |
|
| 91 |
return output_img, details
|
|
|
|
| 125 |
|
| 126 |
details = (
|
| 127 |
f"### Benchmark Results\n"
|
| 128 |
+
f"- **PSNR:** {psnr:.2f} dB\n\n"
|
| 129 |
+
f"- **Low-Res Input:** {lr_w} x {lr_h} ({lr_w * lr_h:,} pixels)\n\n"
|
| 130 |
+
f"- **Model Output & Ground Truth:** {w} x {h} ({w * h:,} pixels)"
|
| 131 |
)
|
| 132 |
|
| 133 |
# Gradio's native ImageSlider expects a tuple of (image1, image2)
|
|
|
|
| 139 |
"""
|
| 140 |
# ⚡ FastEDSR 2x Image Upscaler
|
| 141 |
Upload an image to enhance and upscale it by 2x. Supports up to 4K resolution output.
|
| 142 |
+
|
| 143 |
+
For more information on the model, training, and use, and for a local demo, visit our [website](https://infinitode.netlify.app).
|
| 144 |
+
|
| 145 |
+
This model was trained on DIV2K:
|
| 146 |
+
```
|
| 147 |
+
@inproceedings{Agustsson2017,
|
| 148 |
+
title={NTIRE 2017 Challenge on Single Image Super-Resolution: Dataset and Study},
|
| 149 |
+
author={Agustsson, Eirikur and Timofte, Radu},
|
| 150 |
+
booktitle={IEEE Conference on Computer Vision and Pattern Recognition Workshops},
|
| 151 |
+
year={2017}
|
| 152 |
+
}
|
| 153 |
+
```
|
| 154 |
"""
|
| 155 |
)
|
| 156 |
|
|
|
|
| 170 |
|
| 171 |
# TAB 2: BENCHMARK
|
| 172 |
with gr.TabItem("📊 Benchmark Mode"):
|
| 173 |
+
gr.Markdown("Upload a high-quality image (up to 4K). The app will compress it to 2x lower resolution, upscale it using FastEDSR, and measure the PSNR quality against the original. It will also generate side-by-side comparisons for you to view.")
|
| 174 |
with gr.Row():
|
| 175 |
with gr.Column():
|
| 176 |
bm_input = gr.Image(type="pil", label="Ground Truth (High Res) Image")
|