Alexander Becker commited on
Commit
21f2036
·
1 Parent(s): 2b8654e

Crop and warn instead of error

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -15,7 +15,7 @@ from super_resolve import process
15
 
16
  REPO_ID_EDSR = "prs-eth/thera-edsr-pro"
17
  REPO_ID_RDN = "prs-eth/thera-rdn-pro"
18
- MAX_SIZE = 600
19
 
20
  print(f"JAX devices: {jax.devices()}")
21
  print(f"JAX device type: {jax.devices()[0].device_kind}")
@@ -56,6 +56,9 @@ class TheraApp(DualVisionApp):
56
  <p align="center" style="margin-top: 0px;">
57
  <strong>Upload a photo or select an example below to do arbitrary-scale super-resolution in real time!</strong>
58
  </p>
 
 
 
59
  """
60
  )
61
 
@@ -96,8 +99,15 @@ class TheraApp(DualVisionApp):
96
  model = kwargs.get("model", self.DEFAULT_MODEL)
97
 
98
  if max(*image_in.size) > MAX_SIZE:
99
- raise gr.Error(f"We have currently limited the size of uploaded images to {MAX_SIZE}x{MAX_SIZE}"
100
- f" pixels, to enable a smooth experience to all users.")
 
 
 
 
 
 
 
101
 
102
  source = np.asarray(image_in) / 255.
103
 
 
15
 
16
  REPO_ID_EDSR = "prs-eth/thera-edsr-pro"
17
  REPO_ID_RDN = "prs-eth/thera-rdn-pro"
18
+ MAX_SIZE = 500
19
 
20
  print(f"JAX devices: {jax.devices()}")
21
  print(f"JAX device type: {jax.devices()[0].device_kind}")
 
56
  <p align="center" style="margin-top: 0px;">
57
  <strong>Upload a photo or select an example below to do arbitrary-scale super-resolution in real time!</strong>
58
  </p>
59
+ <p align="center" style="margin-top: 0px;">
60
+ <strong>Note: The model has not been trained on input images with JPEG artifacts, so this may not work well.</strong>
61
+ </p>
62
  """
63
  )
64
 
 
99
  model = kwargs.get("model", self.DEFAULT_MODEL)
100
 
101
  if max(*image_in.size) > MAX_SIZE:
102
+ gr.Warning(f"The image has been cropped to enable a smooth experience for all users.")
103
+ width, height = image_in.size
104
+ crop_width = min(width, MAX_SIZE)
105
+ crop_height = min(height, MAX_SIZE)
106
+ left = (width - crop_width) / 2
107
+ top = (height - crop_height) / 2
108
+ right = left + crop_width
109
+ bottom = top + crop_height
110
+ image_in = image_in.crop((left, top, right, bottom))
111
 
112
  source = np.asarray(image_in) / 255.
113