Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,6 +151,25 @@ pipe.unet.set_attn_processor(AttnProcessor2_0())
|
|
| 151 |
# Enable FreeU
|
| 152 |
pipe.enable_freeu(s1=0.9, s2=0.2, b1=1.3, b2=1.4)
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
def resize_and_upscale(input_image, resolution):
|
| 155 |
scale = 2
|
| 156 |
if resolution == 2048:
|
|
@@ -174,6 +193,10 @@ def resize_and_upscale(input_image, resolution):
|
|
| 174 |
model = RealESRGAN(device, scale=scale)
|
| 175 |
model.load_weights(f'models/upscalers/RealESRGAN_x{scale}.pth', download=False)
|
| 176 |
img = model.predict(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
return img
|
| 178 |
|
| 179 |
def calculate_brightness_factors(hdr_intensity):
|
|
|
|
| 151 |
# Enable FreeU
|
| 152 |
pipe.enable_freeu(s1=0.9, s2=0.2, b1=1.3, b2=1.4)
|
| 153 |
|
| 154 |
+
class LazyRealESRGAN:
|
| 155 |
+
def __init__(self, device, scale):
|
| 156 |
+
self.device = device
|
| 157 |
+
self.scale = scale
|
| 158 |
+
self.model = None
|
| 159 |
+
|
| 160 |
+
def load_model(self):
|
| 161 |
+
if self.model is None:
|
| 162 |
+
self.model = RealESRGAN(self.device, scale=self.scale)
|
| 163 |
+
self.model.load_weights(f'models/upscalers/RealESRGAN_x{self.scale}.pth', download=False)
|
| 164 |
+
|
| 165 |
+
def predict(self, img):
|
| 166 |
+
self.load_model()
|
| 167 |
+
return self.model.predict(img)
|
| 168 |
+
|
| 169 |
+
# Initialize the lazy models
|
| 170 |
+
lazy_realesrgan_x2 = LazyRealESRGAN(device, scale=2)
|
| 171 |
+
lazy_realesrgan_x4 = LazyRealESRGAN(device, scale=4)
|
| 172 |
+
|
| 173 |
def resize_and_upscale(input_image, resolution):
|
| 174 |
scale = 2
|
| 175 |
if resolution == 2048:
|
|
|
|
| 193 |
model = RealESRGAN(device, scale=scale)
|
| 194 |
model.load_weights(f'models/upscalers/RealESRGAN_x{scale}.pth', download=False)
|
| 195 |
img = model.predict(img)
|
| 196 |
+
if scale == 2:
|
| 197 |
+
img = lazy_realesrgan_x2.predict(img)
|
| 198 |
+
else:
|
| 199 |
+
img = lazy_realesrgan_x4.predict(img)
|
| 200 |
return img
|
| 201 |
|
| 202 |
def calculate_brightness_factors(hdr_intensity):
|