Fabrice-TIERCELIN commited on
Commit
0879b61
1 Parent(s): 59dedb4

ZERO space only for AI

Browse files
Files changed (1) hide show
  1. gradio_demo.py +52 -11
gradio_demo.py CHANGED
@@ -79,7 +79,7 @@ def check(input_image):
79
  def reset_feedback():
80
  return 3, ''
81
 
82
- @spaces.GPU(duration=540)
83
  def stage1_process(input_image, gamma_correction):
84
  print('stage1_process ==>>')
85
  if torch.cuda.device_count() == 0:
@@ -101,7 +101,7 @@ def stage1_process(input_image, gamma_correction):
101
  print('<<== stage1_process')
102
  return LQ, gr.update(visible = True)
103
 
104
- @spaces.GPU(duration=540)
105
  def llave_process(input_image, temperature, top_p, qs=None):
106
  print('llave_process ==>>')
107
  if torch.cuda.device_count() == 0:
@@ -117,7 +117,6 @@ def llave_process(input_image, temperature, top_p, qs=None):
117
  print('<<== llave_process')
118
  return captions[0]
119
 
120
- @spaces.GPU(duration=540)
121
  def stage2_process(
122
  noisy_image,
123
  denoise_image,
@@ -196,11 +195,26 @@ def stage2_process(
196
  model.ae_dtype = convert_dtype(ae_dtype)
197
  model.model.dtype = convert_dtype(diff_dtype)
198
 
199
- samples = model.batchify_sample(LQ, captions, num_steps=edm_steps, restoration_scale=s_stage1, s_churn=s_churn,
200
- s_noise=s_noise, cfg_scale=s_cfg, control_scale=s_stage2, seed=seed,
201
- num_samples=num_samples, p_p=a_prompt, n_p=n_prompt, color_fix_type=color_fix_type,
202
- use_linear_CFG=linear_CFG, use_linear_control_scale=linear_s_stage2,
203
- cfg_scale_start=spt_linear_CFG, control_scale_start=spt_linear_s_stage2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  x_samples = (einops.rearrange(samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().round().clip(
206
  0, 255).astype(np.uint8)
@@ -238,6 +252,33 @@ def stage2_process(
238
  # Only one image can be shown in the slider
239
  return [noisy_image] + [results[0]], gr.update(format = output_format, value = [noisy_image] + results), gr.update(value = information, visible = True), event_id
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  def load_and_reset(param_setting):
242
  print('load_and_reset ==>>')
243
  if torch.cuda.device_count() == 0:
@@ -289,15 +330,15 @@ def submit_feedback(event_id, fb_score, fb_text):
289
 
290
  title_html = """
291
  <h1><center>SUPIR</center></h1>
292
- <big><center>Upscale your images up to x8 freely, without account, without watermark and download it</center></big>
293
- <center>🤸<big><big><big><big><big><big><big><big>🤸</big></big></big></big></big></big></big></big></center>
294
 
295
  <p>This is an online demo of SUPIR, a practicing model scaling for photo-realistic image restoration.
296
  It is still a research project under tested and is not yet a stable commercial product.
297
  LlaVa is not integrated in this demo. The content added by SUPIR is imagination, not real-world information.
298
  The aim of SUPIR is the beauty and the illustration.
299
  Most of the processes only last few minutes.
300
- This demo can handle huge images but the process will be aborted if it lasts more than 9 min.
301
 
302
  <p><center><a href="https://arxiv.org/abs/2401.13627">Paper</a> &emsp; <a href="http://supir.xpixel.group/">Project Page</a> &emsp; <a href="https://github.com/Fanghua-Yu/SUPIR/blob/master/assets/DemoGuide.png">How to play</a> &emsp; <a href="https://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai">Local Install Guide</a></center></p>
303
  """
 
79
  def reset_feedback():
80
  return 3, ''
81
 
82
+ @spaces.GPU(duration=600)
83
  def stage1_process(input_image, gamma_correction):
84
  print('stage1_process ==>>')
85
  if torch.cuda.device_count() == 0:
 
101
  print('<<== stage1_process')
102
  return LQ, gr.update(visible = True)
103
 
104
+ @spaces.GPU(duration=600)
105
  def llave_process(input_image, temperature, top_p, qs=None):
106
  print('llave_process ==>>')
107
  if torch.cuda.device_count() == 0:
 
117
  print('<<== llave_process')
118
  return captions[0]
119
 
 
120
  def stage2_process(
121
  noisy_image,
122
  denoise_image,
 
195
  model.ae_dtype = convert_dtype(ae_dtype)
196
  model.model.dtype = convert_dtype(diff_dtype)
197
 
198
+ samples = restore(
199
+ model,
200
+ LQ,
201
+ captions,
202
+ edm_steps,
203
+ s_stage1,
204
+ s_churn,
205
+ s_noise,
206
+ s_cfg,
207
+ s_stage2,
208
+ seed,
209
+ num_samples,
210
+ a_prompt,
211
+ n_prompt,
212
+ color_fix_type,
213
+ linear_CFG,
214
+ linear_s_stage2,
215
+ spt_linear_CFG,
216
+ spt_linear_s_stage2
217
+ )
218
 
219
  x_samples = (einops.rearrange(samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().round().clip(
220
  0, 255).astype(np.uint8)
 
252
  # Only one image can be shown in the slider
253
  return [noisy_image] + [results[0]], gr.update(format = output_format, value = [noisy_image] + results), gr.update(value = information, visible = True), event_id
254
 
255
+ @spaces.GPU(duration=600)
256
+ def restore(
257
+ model,
258
+ LQ,
259
+ captions,
260
+ edm_steps,
261
+ s_stage1,
262
+ s_churn,
263
+ s_noise,
264
+ s_cfg,
265
+ s_stage2,
266
+ seed,
267
+ num_samples,
268
+ a_prompt,
269
+ n_prompt,
270
+ color_fix_type,
271
+ linear_CFG,
272
+ linear_s_stage2,
273
+ spt_linear_CFG,
274
+ spt_linear_s_stage2
275
+ ):
276
+ return model.batchify_sample(LQ, captions, num_steps=edm_steps, restoration_scale=s_stage1, s_churn=s_churn,
277
+ s_noise=s_noise, cfg_scale=s_cfg, control_scale=s_stage2, seed=seed,
278
+ num_samples=num_samples, p_p=a_prompt, n_p=n_prompt, color_fix_type=color_fix_type,
279
+ use_linear_CFG=linear_CFG, use_linear_control_scale=linear_s_stage2,
280
+ cfg_scale_start=spt_linear_CFG, control_scale_start=spt_linear_s_stage2)
281
+
282
  def load_and_reset(param_setting):
283
  print('load_and_reset ==>>')
284
  if torch.cuda.device_count() == 0:
 
330
 
331
  title_html = """
332
  <h1><center>SUPIR</center></h1>
333
+ <center><big>Upscale your images up to x8 freely, without account, without watermark and download it</big></center>
334
+ <center><big><big>🤸<big><big><big><big><big><big>🤸</big></big></big></big></big></big></big></big></center>
335
 
336
  <p>This is an online demo of SUPIR, a practicing model scaling for photo-realistic image restoration.
337
  It is still a research project under tested and is not yet a stable commercial product.
338
  LlaVa is not integrated in this demo. The content added by SUPIR is imagination, not real-world information.
339
  The aim of SUPIR is the beauty and the illustration.
340
  Most of the processes only last few minutes.
341
+ This demo can handle huge images but the process will be aborted if it lasts more than 10 min.
342
 
343
  <p><center><a href="https://arxiv.org/abs/2401.13627">Paper</a> &emsp; <a href="http://supir.xpixel.group/">Project Page</a> &emsp; <a href="https://github.com/Fanghua-Yu/SUPIR/blob/master/assets/DemoGuide.png">How to play</a> &emsp; <a href="https://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai">Local Install Guide</a></center></p>
344
  """