Fabrice-TIERCELIN
commited on
Commit
•
f200691
1
Parent(s):
da3b33e
Code out of GPU compute
Browse files
app.py
CHANGED
@@ -100,7 +100,7 @@ def stage2_process(*args, **kwargs):
|
|
100 |
return restore_in_Xmin(*args, **kwargs)
|
101 |
except Exception as e:
|
102 |
print('Exception of type ' + str(type(e)))
|
103 |
-
if type(e).__name__ == 'gradio.exceptions.Error':
|
104 |
print('Exception of name ' + type(e).__name__)
|
105 |
raise e
|
106 |
|
@@ -201,6 +201,12 @@ def restore_in_Xmin(
|
|
201 |
input_height, input_width, input_channel = denoise_image.shape
|
202 |
denoise_image = denoise_image.resize((input_width // downscale, input_height // downscale), Image.LANCZOS)
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
# Allocation
|
205 |
if allocation == 1:
|
206 |
return restore_in_1min(
|
@@ -243,39 +249,39 @@ def restore_in_Xmin(
|
|
243 |
noisy_image, denoise_image, prompt, a_prompt, n_prompt, num_samples, min_size, downscale, upscale, edm_steps, s_stage1, s_stage2, s_cfg, randomize_seed, seed, s_churn, s_noise, color_fix_type, diff_dtype, ae_dtype, gamma_correction, linear_CFG, linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select, output_format, allocation
|
244 |
)
|
245 |
|
246 |
-
@spaces.GPU(duration=
|
247 |
def restore_in_1min(*args, **kwargs):
|
248 |
return restore(*args, **kwargs)
|
249 |
|
250 |
-
@spaces.GPU(duration=
|
251 |
def restore_in_2min(*args, **kwargs):
|
252 |
return restore(*args, **kwargs)
|
253 |
|
254 |
-
@spaces.GPU(duration=
|
255 |
def restore_in_3min(*args, **kwargs):
|
256 |
return restore(*args, **kwargs)
|
257 |
|
258 |
-
@spaces.GPU(duration=
|
259 |
def restore_in_4min(*args, **kwargs):
|
260 |
return restore(*args, **kwargs)
|
261 |
|
262 |
-
@spaces.GPU(duration=
|
263 |
def restore_in_5min(*args, **kwargs):
|
264 |
return restore(*args, **kwargs)
|
265 |
|
266 |
-
@spaces.GPU(duration=
|
267 |
def restore_in_6min(*args, **kwargs):
|
268 |
return restore(*args, **kwargs)
|
269 |
|
270 |
-
@spaces.GPU(duration=
|
271 |
def restore_in_7min(*args, **kwargs):
|
272 |
return restore(*args, **kwargs)
|
273 |
|
274 |
-
@spaces.GPU(duration=
|
275 |
def restore_in_8min(*args, **kwargs):
|
276 |
return restore(*args, **kwargs)
|
277 |
|
278 |
-
@spaces.GPU(duration=
|
279 |
def restore_in_9min(*args, **kwargs):
|
280 |
return restore(*args, **kwargs)
|
281 |
|
@@ -316,9 +322,6 @@ def restore(
|
|
316 |
start = time.time()
|
317 |
print('restore ==>>')
|
318 |
|
319 |
-
if torch.cuda.device_count() == 0:
|
320 |
-
gr.Warning('Set this space to GPU config to make it work.')
|
321 |
-
return [input_image] * 2, [input_image], None, None
|
322 |
torch.cuda.set_device(SUPIR_device)
|
323 |
|
324 |
if model_select != model.current_model:
|
@@ -328,7 +331,6 @@ def restore(
|
|
328 |
elif model_select == 'v0-F':
|
329 |
model.load_state_dict(ckpt_F, strict=False)
|
330 |
model.current_model = model_select
|
331 |
-
input_image = HWC3(np.array(input_image))
|
332 |
input_image = upscale_image(input_image, upscale, unit_resolution=32,
|
333 |
min_size=min_size)
|
334 |
|
|
|
100 |
return restore_in_Xmin(*args, **kwargs)
|
101 |
except Exception as e:
|
102 |
print('Exception of type ' + str(type(e)))
|
103 |
+
if type(e).__name__ == "<class 'gradio.exceptions.Error'>":
|
104 |
print('Exception of name ' + type(e).__name__)
|
105 |
raise e
|
106 |
|
|
|
201 |
input_height, input_width, input_channel = denoise_image.shape
|
202 |
denoise_image = denoise_image.resize((input_width // downscale, input_height // downscale), Image.LANCZOS)
|
203 |
|
204 |
+
if torch.cuda.device_count() == 0:
|
205 |
+
gr.Warning('Set this space to GPU config to make it work.')
|
206 |
+
return [noisy_image, denoise_image], [denoise_image], None, None
|
207 |
+
|
208 |
+
denoise_image = HWC3(np.array(denoise_image))
|
209 |
+
|
210 |
# Allocation
|
211 |
if allocation == 1:
|
212 |
return restore_in_1min(
|
|
|
249 |
noisy_image, denoise_image, prompt, a_prompt, n_prompt, num_samples, min_size, downscale, upscale, edm_steps, s_stage1, s_stage2, s_cfg, randomize_seed, seed, s_churn, s_noise, color_fix_type, diff_dtype, ae_dtype, gamma_correction, linear_CFG, linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select, output_format, allocation
|
250 |
)
|
251 |
|
252 |
+
@spaces.GPU(duration=59)
|
253 |
def restore_in_1min(*args, **kwargs):
|
254 |
return restore(*args, **kwargs)
|
255 |
|
256 |
+
@spaces.GPU(duration=119)
|
257 |
def restore_in_2min(*args, **kwargs):
|
258 |
return restore(*args, **kwargs)
|
259 |
|
260 |
+
@spaces.GPU(duration=179)
|
261 |
def restore_in_3min(*args, **kwargs):
|
262 |
return restore(*args, **kwargs)
|
263 |
|
264 |
+
@spaces.GPU(duration=239)
|
265 |
def restore_in_4min(*args, **kwargs):
|
266 |
return restore(*args, **kwargs)
|
267 |
|
268 |
+
@spaces.GPU(duration=299)
|
269 |
def restore_in_5min(*args, **kwargs):
|
270 |
return restore(*args, **kwargs)
|
271 |
|
272 |
+
@spaces.GPU(duration=359)
|
273 |
def restore_in_6min(*args, **kwargs):
|
274 |
return restore(*args, **kwargs)
|
275 |
|
276 |
+
@spaces.GPU(duration=419)
|
277 |
def restore_in_7min(*args, **kwargs):
|
278 |
return restore(*args, **kwargs)
|
279 |
|
280 |
+
@spaces.GPU(duration=479)
|
281 |
def restore_in_8min(*args, **kwargs):
|
282 |
return restore(*args, **kwargs)
|
283 |
|
284 |
+
@spaces.GPU(duration=539)
|
285 |
def restore_in_9min(*args, **kwargs):
|
286 |
return restore(*args, **kwargs)
|
287 |
|
|
|
322 |
start = time.time()
|
323 |
print('restore ==>>')
|
324 |
|
|
|
|
|
|
|
325 |
torch.cuda.set_device(SUPIR_device)
|
326 |
|
327 |
if model_select != model.current_model:
|
|
|
331 |
elif model_select == 'v0-F':
|
332 |
model.load_state_dict(ckpt_F, strict=False)
|
333 |
model.current_model = model_select
|
|
|
334 |
input_image = upscale_image(input_image, upscale, unit_resolution=32,
|
335 |
min_size=min_size)
|
336 |
|