Fabrice-TIERCELIN commited on
Commit
66c976a
1 Parent(s): 153b44f
Files changed (1) hide show
  1. gradio_demo.py +7 -51
gradio_demo.py CHANGED
@@ -79,7 +79,7 @@ def check(input_image):
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,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=600)
105
  def llave_process(input_image, temperature, top_p, qs=None):
106
  print('llave_process ==>>')
107
  if torch.cuda.device_count() == 0:
@@ -117,6 +117,7 @@ def llave_process(input_image, temperature, top_p, qs=None):
117
  print('<<== llave_process')
118
  return captions[0]
119
 
 
120
  def stage2_process(
121
  noisy_image,
122
  denoise_image,
@@ -160,6 +161,7 @@ def stage2_process(
160
  if 1 < downscale:
161
  input_height, input_width, input_channel = np.array(input_image).shape
162
  input_image = input_image.resize((input_width // downscale, input_height // downscale), Image.LANCZOS)
 
163
  event_id = str(time.time_ns())
164
  event_dict = {'event_id': event_id, 'localtime': time.ctime(), 'prompt': prompt, 'a_prompt': a_prompt,
165
  'n_prompt': n_prompt, 'num_samples': num_samples, 'upscale': upscale, 'edm_steps': edm_steps,
@@ -180,47 +182,6 @@ def stage2_process(
180
  input_image = upscale_image(input_image, upscale, unit_resolution=32,
181
  min_size=min_size)
182
 
183
- result_slider, result_gallery, restore_information, event_id = restore(
184
- model,
185
- edm_steps,
186
- s_stage1,
187
- s_churn,
188
- s_noise,
189
- s_cfg,
190
- s_stage2,
191
- seed,
192
- num_samples,
193
- a_prompt,
194
- n_prompt,
195
- color_fix_type,
196
- linear_CFG,
197
- linear_s_stage2,
198
- spt_linear_CFG,
199
- spt_linear_s_stage2
200
- )
201
-
202
- return result_slider, result_gallery, restore_information, event_id
203
-
204
- @spaces.GPU(duration=600)
205
- def restore(
206
- model,
207
- edm_steps,
208
- s_stage1,
209
- s_churn,
210
- s_noise,
211
- s_cfg,
212
- s_stage2,
213
- seed,
214
- num_samples,
215
- a_prompt,
216
- n_prompt,
217
- color_fix_type,
218
- linear_CFG,
219
- linear_s_stage2,
220
- spt_linear_CFG,
221
- spt_linear_s_stage2
222
- ):
223
- torch.cuda.set_device(SUPIR_device)
224
  LQ = np.array(input_image) / 255.0
225
  LQ = np.power(LQ, gamma_correction)
226
  LQ *= 255.0
@@ -328,7 +289,7 @@ def submit_feedback(event_id, fb_score, fb_text):
328
 
329
  title_html = """
330
  <h1><center>SUPIR</center></h1>
331
- <center><big>Upscale your images up to x8 freely, without account, without watermark and download it</big></center>
332
  <center><big><big>🤸<big><big><big><big><big><big>🤸</big></big></big></big></big></big></big></big></center>
333
 
334
  <p>This is an online demo of SUPIR, a practicing model scaling for photo-realistic image restoration.
@@ -336,7 +297,7 @@ title_html = """
336
  LlaVa is not integrated in this demo. The content added by SUPIR is imagination, not real-world information.
337
  The aim of SUPIR is the beauty and the illustration.
338
  Most of the processes only last few minutes.
339
- This demo can handle huge images but the process will be aborted if it lasts more than 10 min.
340
 
341
  <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>
342
  """
@@ -344,15 +305,10 @@ title_html = """
344
 
345
  claim_md = """
346
  ## **Piracy**
347
-
348
  The images are not stored but the logs are saved during a month.
349
-
350
  ## **Terms of use**
351
-
352
  By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. The service may collect user dialogue data for future research. Please submit a feedback to us if you get any inappropriate answer! We will collect those to keep improving our models. For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
353
-
354
  ## **License**
355
-
356
  The service is a research preview intended for non-commercial use only, subject to the model [License](https://github.com/Fanghua-Yu/SUPIR) of SUPIR.
357
  """
358
 
@@ -550,4 +506,4 @@ with gr.Blocks(title="SUPIR") as interface:
550
  fb_text
551
  ])
552
 
553
- interface.queue(10).launch()
 
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
  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
  print('<<== llave_process')
118
  return captions[0]
119
 
120
+ @spaces.GPU(duration=540)
121
  def stage2_process(
122
  noisy_image,
123
  denoise_image,
 
161
  if 1 < downscale:
162
  input_height, input_width, input_channel = np.array(input_image).shape
163
  input_image = input_image.resize((input_width // downscale, input_height // downscale), Image.LANCZOS)
164
+ torch.cuda.set_device(SUPIR_device)
165
  event_id = str(time.time_ns())
166
  event_dict = {'event_id': event_id, 'localtime': time.ctime(), 'prompt': prompt, 'a_prompt': a_prompt,
167
  'n_prompt': n_prompt, 'num_samples': num_samples, 'upscale': upscale, 'edm_steps': edm_steps,
 
182
  input_image = upscale_image(input_image, upscale, unit_resolution=32,
183
  min_size=min_size)
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  LQ = np.array(input_image) / 255.0
186
  LQ = np.power(LQ, gamma_correction)
187
  LQ *= 255.0
 
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.
 
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
  """
 
305
 
306
  claim_md = """
307
  ## **Piracy**
 
308
  The images are not stored but the logs are saved during a month.
 
309
  ## **Terms of use**
 
310
  By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. The service may collect user dialogue data for future research. Please submit a feedback to us if you get any inappropriate answer! We will collect those to keep improving our models. For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
 
311
  ## **License**
 
312
  The service is a research preview intended for non-commercial use only, subject to the model [License](https://github.com/Fanghua-Yu/SUPIR) of SUPIR.
313
  """
314
 
 
506
  fb_text
507
  ])
508
 
509
+ interface.queue(10).launch()