Fabrice-TIERCELIN commited on
Commit
2012398
1 Parent(s): 4f1d55c

Add labels for radio buttons

Browse files
Files changed (1) hide show
  1. gradio_demo.py +16 -16
gradio_demo.py CHANGED
@@ -79,9 +79,9 @@ def check(input_image):
79
  def reset_feedback():
80
  return 3, ''
81
 
82
- @spaces.GPU(duration=420)
83
  def stage1_process(input_image, gamma_correction):
84
- print('Start stage1_process')
85
  if torch.cuda.device_count() == 0:
86
  gr.Warning('Set this space to GPU config to make it work.')
87
  return None, None
@@ -98,12 +98,12 @@ def stage1_process(input_image, gamma_correction):
98
  LQ = np.power(LQ, gamma_correction)
99
  LQ *= 255.0
100
  LQ = LQ.round().clip(0, 255).astype(np.uint8)
101
- print('End stage1_process')
102
  return LQ, gr.update(visible = True)
103
 
104
- @spaces.GPU(duration=420)
105
  def llave_process(input_image, temperature, top_p, qs=None):
106
- print('Start llave_process')
107
  if torch.cuda.device_count() == 0:
108
  gr.Warning('Set this space to GPU config to make it work.')
109
  return 'Set this space to GPU config to make it work.'
@@ -114,10 +114,10 @@ def llave_process(input_image, temperature, top_p, qs=None):
114
  captions = llava_agent.gen_image_caption([LQ], temperature=temperature, top_p=top_p, qs=qs)
115
  else:
116
  captions = ['LLaVA is not available. Please add text manually.']
117
- print('End llave_process')
118
  return captions[0]
119
 
120
- @spaces.GPU(duration=420)
121
  def stage2_process(
122
  noisy_image,
123
  denoise_image,
@@ -148,7 +148,7 @@ def stage2_process(
148
  output_format
149
  ):
150
  start = time.time()
151
- print('Start stage2_process')
152
  if torch.cuda.device_count() == 0:
153
  gr.Warning('Set this space to GPU config to make it work.')
154
  return None, None, None
@@ -213,7 +213,7 @@ def stage2_process(
213
  # All the results have the same size
214
  result_height, result_width, result_channel = np.array(results[0]).shape
215
 
216
- print('End stage2_process')
217
  end = time.time()
218
  secondes = int(end - start)
219
  minutes = math.floor(secondes / 60)
@@ -234,7 +234,7 @@ def stage2_process(
234
  return [noisy_image] + [results[0]], gr.update(format = output_format, value = [noisy_image] + results), gr.update(value = information, visible = True), event_id
235
 
236
  def load_and_reset(param_setting):
237
- print('Start load_and_reset')
238
  if torch.cuda.device_count() == 0:
239
  gr.Warning('Set this space to GPU config to make it work.')
240
  return None, None, None, None, None, None, None, None, None, None, None, None, None, None
@@ -264,7 +264,7 @@ def load_and_reset(param_setting):
264
  else:
265
  raise NotImplementedError
266
  gr.Info('The parameters are reset.')
267
- print('End load_and_reset')
268
  return edm_steps, s_cfg, s_stage2, s_stage1, s_churn, s_noise, a_prompt, n_prompt, color_fix_type, linear_CFG, \
269
  linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select
270
 
@@ -292,7 +292,7 @@ title_html = """
292
  LlaVa is not integrated in this demo. The content added by SUPIR is imagination, not real-world information.
293
  The aim of SUPIR is the beauty and the illustration.
294
  Most of the processes only last few minutes.
295
- This demo can handle huge images but the process will be aborted if it lasts more than 7 min.
296
 
297
  <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>
298
  """
@@ -327,7 +327,7 @@ with gr.Blocks(title="SUPIR") as interface:
327
  input_image = gr.Image(label="Input", show_label=True, type="numpy", height=600, elem_id="image-input")
328
  with gr.Group():
329
  prompt = gr.Textbox(label="Image description for LlaVa", value="", placeholder="A person, walking, in a town, Summer, photorealistic", lines=3, visible=False)
330
- upscale = gr.Radio([1, 2, 3, 4, 5, 6, 7, 8], label="Upscale factor", info="Resolution x1 to x8", value=2, interactive=True)
331
  a_prompt = gr.Textbox(label="Image description",
332
  info="Help the AI understand what the image represents; describe as much as possible",
333
  value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
@@ -336,7 +336,7 @@ with gr.Blocks(title="SUPIR") as interface:
336
  'hyper sharpness, perfect without deformations.',
337
  lines=3)
338
  a_prompt_hint = gr.HTML("You can use a <a href='"'https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b'"'>LlaVa space</a> to auto-generate the description of your image.")
339
- output_format = gr.Radio(["png", "webp", "jpeg", "gif", "bmp"], label="Image format for result", info="File extention", value="png", interactive=True)
340
 
341
  with gr.Accordion("Pre-denoising (optional)", open=False):
342
  gamma_correction = gr.Slider(label="Gamma Correction", info = "lower=lighter, higher=darker", minimum=0.1, maximum=2.0, value=1.0, step=0.1)
@@ -361,10 +361,10 @@ with gr.Blocks(title="SUPIR") as interface:
361
  num_samples = gr.Slider(label="Num Samples", info="Number of generated results", minimum=1, maximum=4 if not args.use_image_slider else 1
362
  , value=1, step=1)
363
  min_size = gr.Slider(label="Minimum size", info="Minimum height, minimum width of the result", minimum=32, maximum=4096, value=1024, step=32)
364
- downscale = gr.Radio([1, 2, 3, 4, 5, 6, 7, 8], label="Pre-downscale factor", info="Reducing blurred image reduce the process time", value=1, interactive=True)
365
  with gr.Row():
366
  with gr.Column():
367
- model_select = gr.Radio(["v0-Q", "v0-F"], label="Model Selection", info="Q=Quality, F=Fidelity", value="v0-Q",
368
  interactive=True)
369
  with gr.Column():
370
  color_fix_type = gr.Radio(["None", "AdaIn", "Wavelet"], label="Color-Fix Type", info="AdaIn=Improve following a style, Wavelet=For JPEG artifacts", value="Wavelet",
 
79
  def reset_feedback():
80
  return 3, ''
81
 
82
+ @spaces.GPU(duration=480)
83
  def stage1_process(input_image, gamma_correction):
84
+ print('stage1_process ==>>')
85
  if torch.cuda.device_count() == 0:
86
  gr.Warning('Set this space to GPU config to make it work.')
87
  return None, None
 
98
  LQ = np.power(LQ, gamma_correction)
99
  LQ *= 255.0
100
  LQ = LQ.round().clip(0, 255).astype(np.uint8)
101
+ print('<<== stage1_process')
102
  return LQ, gr.update(visible = True)
103
 
104
+ @spaces.GPU(duration=480)
105
  def llave_process(input_image, temperature, top_p, qs=None):
106
+ print('llave_process ==>>')
107
  if torch.cuda.device_count() == 0:
108
  gr.Warning('Set this space to GPU config to make it work.')
109
  return 'Set this space to GPU config to make it work.'
 
114
  captions = llava_agent.gen_image_caption([LQ], temperature=temperature, top_p=top_p, qs=qs)
115
  else:
116
  captions = ['LLaVA is not available. Please add text manually.']
117
+ print('<<== llave_process')
118
  return captions[0]
119
 
120
+ @spaces.GPU(duration=480)
121
  def stage2_process(
122
  noisy_image,
123
  denoise_image,
 
148
  output_format
149
  ):
150
  start = time.time()
151
+ print('stage2_process ==>>')
152
  if torch.cuda.device_count() == 0:
153
  gr.Warning('Set this space to GPU config to make it work.')
154
  return None, None, None
 
213
  # All the results have the same size
214
  result_height, result_width, result_channel = np.array(results[0]).shape
215
 
216
+ print('<<== stage2_process')
217
  end = time.time()
218
  secondes = int(end - start)
219
  minutes = math.floor(secondes / 60)
 
234
  return [noisy_image] + [results[0]], gr.update(format = output_format, value = [noisy_image] + results), gr.update(value = information, visible = True), event_id
235
 
236
  def load_and_reset(param_setting):
237
+ print('load_and_reset ==>>')
238
  if torch.cuda.device_count() == 0:
239
  gr.Warning('Set this space to GPU config to make it work.')
240
  return None, None, None, None, None, None, None, None, None, None, None, None, None, None
 
264
  else:
265
  raise NotImplementedError
266
  gr.Info('The parameters are reset.')
267
+ print('<<== load_and_reset')
268
  return edm_steps, s_cfg, s_stage2, s_stage1, s_churn, s_noise, a_prompt, n_prompt, color_fix_type, linear_CFG, \
269
  linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select
270
 
 
292
  LlaVa is not integrated in this demo. The content added by SUPIR is imagination, not real-world information.
293
  The aim of SUPIR is the beauty and the illustration.
294
  Most of the processes only last few minutes.
295
+ This demo can handle huge images but the process will be aborted if it lasts more than 8 min.
296
 
297
  <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>
298
  """
 
327
  input_image = gr.Image(label="Input", show_label=True, type="numpy", height=600, elem_id="image-input")
328
  with gr.Group():
329
  prompt = gr.Textbox(label="Image description for LlaVa", value="", placeholder="A person, walking, in a town, Summer, photorealistic", lines=3, visible=False)
330
+ upscale = gr.Radio([["x1", 1], ["x2", 2], ["x3", 3], ["x4", 4], ["x5", 5], ["x6", 6], ["x7", 7], ["x8", 8]], label="Upscale factor", info="Resolution x1 to x8", value=2, interactive=True)
331
  a_prompt = gr.Textbox(label="Image description",
332
  info="Help the AI understand what the image represents; describe as much as possible",
333
  value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
 
336
  'hyper sharpness, perfect without deformations.',
337
  lines=3)
338
  a_prompt_hint = gr.HTML("You can use a <a href='"'https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b'"'>LlaVa space</a> to auto-generate the description of your image.")
339
+ output_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="png", interactive=True)
340
 
341
  with gr.Accordion("Pre-denoising (optional)", open=False):
342
  gamma_correction = gr.Slider(label="Gamma Correction", info = "lower=lighter, higher=darker", minimum=0.1, maximum=2.0, value=1.0, step=0.1)
 
361
  num_samples = gr.Slider(label="Num Samples", info="Number of generated results", minimum=1, maximum=4 if not args.use_image_slider else 1
362
  , value=1, step=1)
363
  min_size = gr.Slider(label="Minimum size", info="Minimum height, minimum width of the result", minimum=32, maximum=4096, value=1024, step=32)
364
+ downscale = gr.Radio([["/1", 1], ["/2", 2], ["/3", 3], ["/4", 4], ["/5", 5], ["/6", 6], ["/7", 7], ["/8", 8]], label="Pre-downscale factor", info="Reducing blurred image reduce the process time", value=1, interactive=True)
365
  with gr.Row():
366
  with gr.Column():
367
+ model_select = gr.Radio([["💃 Quality", "v0-Q"], ["🎯 Fidelity", "v0-F"]], label="Model Selection", info="Pretrained model", value="v0-Q",
368
  interactive=True)
369
  with gr.Column():
370
  color_fix_type = gr.Radio(["None", "AdaIn", "Wavelet"], label="Color-Fix Type", info="AdaIn=Improve following a style, Wavelet=For JPEG artifacts", value="Wavelet",