Spaces:
mikitona
/
Running on Zero

mikitona commited on
Commit
fc23e64
·
verified ·
1 Parent(s): b080b67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -198,15 +198,12 @@ def restore_in_Xmin(
198
  output_format,
199
  allocation
200
  ):
201
- # 省略可能な詳細なログを出力
202
  print("Starting restoration process...")
203
- # 以下、省略: パラメータの表示や前処理
204
-
205
  input_format = re.sub(r"^.*\.([^\.]+)$", r"\1", noisy_image)
206
 
207
  if input_format not in ['png', 'webp', 'jpg', 'jpeg', 'gif', 'bmp', 'heic']:
208
  gr.Warning('Invalid image format. Please first convert into *.png, *.webp, *.jpg, *.jpeg, *.gif, *.bmp or *.heic.')
209
- return None, None, None
210
 
211
  if output_format == "input":
212
  if noisy_image is None:
@@ -233,11 +230,12 @@ def restore_in_Xmin(
233
  denoise_image = np.array(Image.open(noisy_image if denoise_image is None else denoise_image))
234
 
235
  if rotation == 90:
236
- denoise_image = np.rot90(denoise_image, k=-1)
237
  elif rotation == 180:
238
- denoise_image = np.rot90(denoise_image, k=2)
 
239
  elif rotation == -90:
240
- denoise_image = np.rot90(denoise_image, k=1)
241
 
242
  if 1 < downscale:
243
  input_height, input_width, input_channel = denoise_image.shape
@@ -267,7 +265,7 @@ def restore_in_Xmin(
267
  s_stage2, s_cfg, seed, s_churn, s_noise, color_fix_type, linear_CFG, linear_s_stage2, spt_linear_CFG,
268
  spt_linear_s_stage2, output_format
269
  )
270
- # 省略: 他のallocation条件
271
 
272
  # デフォルトの処理
273
  return restore_in_3min(
@@ -282,8 +280,6 @@ def restore_in_1min(*args, **kwargs):
282
  return restore_on_gpu(*args, **kwargs)
283
 
284
 
285
- # 他のrestore_in_Xmin関数も同様に定義
286
-
287
  def restore_on_gpu(
288
  noisy_image,
289
  input_image,
@@ -314,7 +310,8 @@ def restore_on_gpu(
314
  with torch.no_grad():
315
  input_image = upscale_image(input_image, upscale, unit_resolution=32, min_size=min_size)
316
  LQ = np.array(input_image) / 255.0
317
- LQ = (LQ ** gamma_correction) * 255.0
 
318
  LQ = LQ.round().clip(0, 255).astype(np.uint8)
319
  LQ = LQ / 255 * 2 - 1
320
  LQ = torch.tensor(LQ, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0).to(SUPIR_device)[:, :3, :, :]
@@ -401,6 +398,7 @@ title_html = """
401
  <p><center><a style="display:inline-block" href='https://github.com/Fanghua-Yu/SUPIR'><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/Fanghua-Yu/SUPIR?style=social"></a></center></p>
402
  """
403
 
 
404
  claim_md = """
405
  ## **Piracy**
406
  The images are not stored but the logs are saved during a month.
@@ -493,7 +491,7 @@ with gr.Blocks() as interface:
493
  reset_btn = gr.Button(value="🧹 Reinit page", variant="stop", elem_id="reset_button", visible=False)
494
 
495
  restore_information = gr.HTML(value="Restart the process to get another result.", visible=False)
496
- result_image = gr.Image(label='Result Image', show_label=True, interactive=False, elem_id="result_image")
497
 
498
  gr.Examples(
499
  examples=[
@@ -655,4 +653,4 @@ with gr.Blocks() as interface:
655
  allocation
656
  ], queue=False, show_progress=False)
657
 
658
- interface.queue(max_size=10).launch(show_error=True)
 
198
  output_format,
199
  allocation
200
  ):
 
201
  print("Starting restoration process...")
 
 
202
  input_format = re.sub(r"^.*\.([^\.]+)$", r"\1", noisy_image)
203
 
204
  if input_format not in ['png', 'webp', 'jpg', 'jpeg', 'gif', 'bmp', 'heic']:
205
  gr.Warning('Invalid image format. Please first convert into *.png, *.webp, *.jpg, *.jpeg, *.gif, *.bmp or *.heic.')
206
+ return None, gr.update(value="Invalid image format.", visible=True), gr.update(visible=True)
207
 
208
  if output_format == "input":
209
  if noisy_image is None:
 
230
  denoise_image = np.array(Image.open(noisy_image if denoise_image is None else denoise_image))
231
 
232
  if rotation == 90:
233
+ denoise_image = np.array(list(zip(*denoise_image[::-1])))
234
  elif rotation == 180:
235
+ denoise_image = np.array(list(zip(*denoise_image[::-1])))
236
+ denoise_image = np.array(list(zip(*denoise_image[::-1])))
237
  elif rotation == -90:
238
+ denoise_image = np.array(list(zip(*denoise_image))[::-1])
239
 
240
  if 1 < downscale:
241
  input_height, input_width, input_channel = denoise_image.shape
 
265
  s_stage2, s_cfg, seed, s_churn, s_noise, color_fix_type, linear_CFG, linear_s_stage2, spt_linear_CFG,
266
  spt_linear_s_stage2, output_format
267
  )
268
+ # 他のallocation条件は省略
269
 
270
  # デフォルトの処理
271
  return restore_in_3min(
 
280
  return restore_on_gpu(*args, **kwargs)
281
 
282
 
 
 
283
  def restore_on_gpu(
284
  noisy_image,
285
  input_image,
 
310
  with torch.no_grad():
311
  input_image = upscale_image(input_image, upscale, unit_resolution=32, min_size=min_size)
312
  LQ = np.array(input_image) / 255.0
313
+ LQ = np.power(LQ, gamma_correction)
314
+ LQ *= 255.0
315
  LQ = LQ.round().clip(0, 255).astype(np.uint8)
316
  LQ = LQ / 255 * 2 - 1
317
  LQ = torch.tensor(LQ, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0).to(SUPIR_device)[:, :3, :, :]
 
398
  <p><center><a style="display:inline-block" href='https://github.com/Fanghua-Yu/SUPIR'><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/Fanghua-Yu/SUPIR?style=social"></a></center></p>
399
  """
400
 
401
+
402
  claim_md = """
403
  ## **Piracy**
404
  The images are not stored but the logs are saved during a month.
 
491
  reset_btn = gr.Button(value="🧹 Reinit page", variant="stop", elem_id="reset_button", visible=False)
492
 
493
  restore_information = gr.HTML(value="Restart the process to get another result.", visible=False)
494
+ result_image = gr.Image(label='Result Image', show_label=True, interactive=False, elem_id='result_image')
495
 
496
  gr.Examples(
497
  examples=[
 
653
  allocation
654
  ], queue=False, show_progress=False)
655
 
656
+ interface.queue(10).launch(show_error=True)