Fabrice-TIERCELIN commited on
Commit
15fc37d
1 Parent(s): 5b111e7

Title & button

Browse files
Files changed (1) hide show
  1. gradio_demo.py +21 -22
gradio_demo.py CHANGED
@@ -178,7 +178,7 @@ def stage2_process(input_image, prompt, a_prompt, n_prompt, num_samples, upscale
178
  for i, result in enumerate(results):
179
  Image.fromarray(result).save(f'./history/{event_id[:5]}/{event_id[5:]}/HQ_{i}.png')
180
  print('End stage2_process')
181
- return [input_image] + results, event_id
182
 
183
  def load_and_reset(param_setting):
184
  print('Start load_and_reset')
@@ -227,22 +227,14 @@ def submit_feedback(event_id, fb_score, fb_text):
227
  else:
228
  return 'Submit failed, the server is not set to log history.'
229
 
230
- if torch.cuda.device_count() == 0:
231
- title_md = """
232
- <h1><center>SUPIR: Practicing Model Scaling for Photo-Realistic Image Restoration</center></h1>
233
-
234
- <p style="background-color: red;"><big><big><big><b>⚠️To use SUPIR, <a href="https://huggingface.co/spaces/Fabrice-TIERCELIN/SUPIR?duplicate=true">Duplicate this space</a> and set a GPU with 30 GB VRAM.</b>
235
-
236
- You can't use SUPIR directly here because this space runs on a CPU, which is not enough for SUPIR. This is a template space. Please provide feedback if you have issues.
237
- </big></big></big></p>
238
- """
239
- else:
240
- title_md = """
241
- <h1><center>SUPIR Image Upscaler</center></h1>
242
 
243
  <p>SUPIR is a practicing model scaling for photo-realistic image restoration. It is still a research project under tested and is not yet a stable commercial product. LLaVa is not available in this demo. If you want to auto-generate the description of your image, use another <a href="https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b">LLaVa space</a>.
244
 
245
- <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></p>
246
  """
247
 
248
 
@@ -258,8 +250,16 @@ The service is a research preview intended for non-commercial use only, subject
258
 
259
  # Gradio interface
260
  with gr.Blocks(title="SUPIR") as interface:
 
 
 
 
 
 
 
 
261
  with gr.Row():
262
- gr.HTML(title_md)
263
 
264
  with gr.Row():
265
  with gr.Column():
@@ -281,9 +281,9 @@ with gr.Blocks(title="SUPIR") as interface:
281
  qs = gr.Textbox(label="Question", info="Ask LLaVa what description you want", value="Describe the image and its style in a very detailed manner. The image is a realistic photography, not an art painting.", lines=3)
282
 
283
  with gr.Accordion("Restoring options", open=False):
284
- num_samples = gr.Slider(label="Num Samples", info="Number of generated results; I discourage to increase because the process is limited to 4 min", minimum=1, maximum=4 if not args.use_image_slider else 1
285
  , value=1, step=1)
286
- upscale = gr.Slider(label="Upscale factor", info="Resolution x1, x2, x3, x4, x5, x6, x7 or x8", minimum=1, maximum=8, value=1, step=1)
287
  edm_steps = gr.Slider(label="Steps", info="lower=faster, higher=more details", minimum=1, maximum=200, value=default_setting.edm_steps if torch.cuda.device_count() > 0 else 1, step=1)
288
  s_cfg = gr.Slider(label="Text Guidance Scale", info="lower=follow the image, higher=follow the prompt", minimum=1.0, maximum=15.0,
289
  value=default_setting.s_cfg_Quality if torch.cuda.device_count() > 0 else 1.0, step=0.1)
@@ -332,17 +332,15 @@ with gr.Blocks(title="SUPIR") as interface:
332
 
333
  with gr.Column():
334
  gr.Markdown("<center>Restoring Output</center>")
335
- if not args.use_image_slider:
336
- result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery1")
337
- else:
338
- result_gallery = ImageSlider(label='Output', show_label=False, elem_id="gallery1")
339
  with gr.Row():
340
  with gr.Column():
341
  denoise_button = gr.Button(value="Pre-denoise")
342
  with gr.Column(visible=False):
343
  llave_button = gr.Button(value="Generate description by LlaVa (disabled)")
344
  with gr.Column():
345
- diffusion_button = gr.Button(value="🚀 Restore", variant = "primary")
346
  with gr.Row():
347
  with gr.Column():
348
  param_setting = gr.Radio(["Quality", "Fidelity"], interactive=True, label="Parameter setting", value="Quality")
@@ -412,6 +410,7 @@ with gr.Blocks(title="SUPIR") as interface:
412
  spt_linear_s_stage2,
413
  model_select
414
  ], outputs = [
 
415
  result_gallery,
416
  event_id
417
  ])
 
178
  for i, result in enumerate(results):
179
  Image.fromarray(result).save(f'./history/{event_id[:5]}/{event_id[5:]}/HQ_{i}.png')
180
  print('End stage2_process')
181
+ return [input_image] + results, [input_image] + results, event_id
182
 
183
  def load_and_reset(param_setting):
184
  print('Start load_and_reset')
 
227
  else:
228
  return 'Submit failed, the server is not set to log history.'
229
 
230
+ title_html = """
231
+ <h1><center>SUPIR</center></h1>
232
+ <center>Upscale your images up to x8 freely, without account, without watermark and download it</center>
233
+ <br/>
 
 
 
 
 
 
 
 
234
 
235
  <p>SUPIR is a practicing model scaling for photo-realistic image restoration. It is still a research project under tested and is not yet a stable commercial product. LLaVa is not available in this demo. If you want to auto-generate the description of your image, use another <a href="https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b">LLaVa space</a>.
236
 
237
+ <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>
238
  """
239
 
240
 
 
250
 
251
  # Gradio interface
252
  with gr.Blocks(title="SUPIR") as interface:
253
+ if torch.cuda.device_count() == 0:
254
+ with gr.Row():
255
+ gr.HTML("""
256
+ <p style="background-color: red;"><big><big><big><b>⚠️To use SUPIR, <a href="https://huggingface.co/spaces/Fabrice-TIERCELIN/SUPIR?duplicate=true">Duplicate this space</a> and set a GPU with 30 GB VRAM.</b>
257
+
258
+ You can't use SUPIR directly here because this space runs on a CPU, which is not enough for SUPIR. This is a template space. Please provide feedback if you have issues.
259
+ </big></big></big></p>
260
+ """)
261
  with gr.Row():
262
+ gr.HTML(title_html)
263
 
264
  with gr.Row():
265
  with gr.Column():
 
281
  qs = gr.Textbox(label="Question", info="Ask LLaVa what description you want", value="Describe the image and its style in a very detailed manner. The image is a realistic photography, not an art painting.", lines=3)
282
 
283
  with gr.Accordion("Restoring options", open=False):
284
+ num_samples = gr.Slider(label="Num Samples", info="Number of generated results; I discourage to increase because the process is limited to 3 min", minimum=1, maximum=4 if not args.use_image_slider else 1
285
  , value=1, step=1)
286
+ upscale = gr.Slider(label="Upscale factor", info="Resolution x1, x2, x3, x4, x5, x6, x7 or x8", minimum=1, maximum=8, value=2, step=1)
287
  edm_steps = gr.Slider(label="Steps", info="lower=faster, higher=more details", minimum=1, maximum=200, value=default_setting.edm_steps if torch.cuda.device_count() > 0 else 1, step=1)
288
  s_cfg = gr.Slider(label="Text Guidance Scale", info="lower=follow the image, higher=follow the prompt", minimum=1.0, maximum=15.0,
289
  value=default_setting.s_cfg_Quality if torch.cuda.device_count() > 0 else 1.0, step=0.1)
 
332
 
333
  with gr.Column():
334
  gr.Markdown("<center>Restoring Output</center>")
335
+ result_slider = ImageSlider(label='Output', show_label=False, elem_id="slider1")
336
+ result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery1")
 
 
337
  with gr.Row():
338
  with gr.Column():
339
  denoise_button = gr.Button(value="Pre-denoise")
340
  with gr.Column(visible=False):
341
  llave_button = gr.Button(value="Generate description by LlaVa (disabled)")
342
  with gr.Column():
343
+ diffusion_button = gr.Button(value="🚀 Upscale/Restore", variant = "primary")
344
  with gr.Row():
345
  with gr.Column():
346
  param_setting = gr.Radio(["Quality", "Fidelity"], interactive=True, label="Parameter setting", value="Quality")
 
410
  spt_linear_s_stage2,
411
  model_select
412
  ], outputs = [
413
+ result_slider,
414
  result_gallery,
415
  event_id
416
  ])