JohanBeytell commited on
Commit
d4a7e1c
·
verified ·
1 Parent(s): f0ea2eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -63,10 +63,12 @@ def calc_psnr(pred, target):
63
  def standard_upscale(img):
64
  if img is None: return None, ""
65
 
66
- max_input_dim = 1024
 
67
  w, h = img.size
68
 
69
  if w > max_input_dim or h > max_input_dim:
 
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)
@@ -101,11 +103,12 @@ def benchmark_upscale(hr_img):
101
  h = h - (h % 2)
102
  hr_img = hr_img.crop((0, 0, w, h))
103
 
104
- max_input_dim = 2048 # HR can be 2048 because LR will be 1024
105
- if w > max_input_dim or h > max_input_dim:
106
- scale = max_input_dim / max(w, h)
 
 
107
  w, h = int(w * scale), int(h * scale)
108
- # Ensure even dimensions again after resize
109
  w = w - (w % 2)
110
  h = h - (h % 2)
111
  hr_img = hr_img.resize((w, h), Image.BICUBIC)
@@ -142,14 +145,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
142
  gr.Markdown(
143
  """
144
  # ⚡ FastEDSR 2x Image Upscaler
145
- Upload an image to enhance and upscale it by 2x.
146
  """
147
  )
148
 
149
  with gr.Tabs():
150
  # TAB 1: STANDARD
151
  with gr.TabItem("⚡ Standard Upscaling"):
152
- gr.Markdown("Directly upscale any low-resolution image.")
153
  with gr.Row():
154
  with gr.Column():
155
  std_input = gr.Image(type="pil", label="Low Resolution Input")
@@ -162,7 +165,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
162
 
163
  # TAB 2: BENCHMARK
164
  with gr.TabItem("📊 Benchmark Mode"):
165
- gr.Markdown("Upload a high-quality image. The app will compress it, upscale it, and measure the PSNR quality against the original.")
166
  with gr.Row():
167
  with gr.Column():
168
  bm_input = gr.Image(type="pil", label="Ground Truth (High Res) Image")
 
63
  def standard_upscale(img):
64
  if img is None: return None, ""
65
 
66
+ # Bumped max input to 2K (2048px) for a 4K output
67
+ max_input_dim = 2048
68
  w, h = img.size
69
 
70
  if w > max_input_dim or h > max_input_dim:
71
+ 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.")
72
  scale = max_input_dim / max(w, h)
73
  w, h = int(w * scale), int(h * scale)
74
  img = img.resize((w, h), Image.BICUBIC)
 
103
  h = h - (h % 2)
104
  hr_img = hr_img.crop((0, 0, w, h))
105
 
106
+ # HR can now be 4K (4096px) because the LR input to the model will be max 2K
107
+ max_hr_dim = 4096
108
+ if w > max_hr_dim or h > max_hr_dim:
109
+ gr.Warning(f"Ground truth image exceeded the 4K ({max_hr_dim}px) limit. It has been proportionally downscaled.")
110
+ scale = max_hr_dim / max(w, h)
111
  w, h = int(w * scale), int(h * scale)
 
112
  w = w - (w % 2)
113
  h = h - (h % 2)
114
  hr_img = hr_img.resize((w, h), Image.BICUBIC)
 
145
  gr.Markdown(
146
  """
147
  # ⚡ FastEDSR 2x Image Upscaler
148
+ Upload an image to enhance and upscale it by 2x. Supports up to 4K resolution output.
149
  """
150
  )
151
 
152
  with gr.Tabs():
153
  # TAB 1: STANDARD
154
  with gr.TabItem("⚡ Standard Upscaling"):
155
+ gr.Markdown("Directly upscale any low-resolution image. Inputs over 2K (2048px) will be scaled down to prevent memory limits.")
156
  with gr.Row():
157
  with gr.Column():
158
  std_input = gr.Image(type="pil", label="Low Resolution Input")
 
165
 
166
  # TAB 2: BENCHMARK
167
  with gr.TabItem("📊 Benchmark Mode"):
168
+ 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.")
169
  with gr.Row():
170
  with gr.Column():
171
  bm_input = gr.Image(type="pil", label="Ground Truth (High Res) Image")