Fabrice-TIERCELIN commited on
Commit
c657de6
·
verified ·
1 Parent(s): 3698990

return [gr.update(visible = True)] * 2

Browse files
Files changed (1) hide show
  1. gradio_demo.py +15 -7
gradio_demo.py CHANGED
@@ -67,12 +67,17 @@ if torch.cuda.device_count() > 0:
67
  else:
68
  llava_agent = None
69
 
 
 
 
 
 
70
  def rotate_anti_90(image_array):
71
  if image_array is None:
72
  raise gr.Error("Please provide an image to rotate.")
73
 
74
  image_pil = Image.fromarray(image_array)
75
- image_pil = Image.Image.rotate(image_pil, -90)
76
  image_array = np.array(image_pil)
77
  return image_array
78
 
@@ -81,7 +86,7 @@ def rotate_90(image_array):
81
  raise gr.Error("Please provide an image to rotate.")
82
 
83
  image_pil = Image.fromarray(image_array)
84
- image_pil = image_pil.rotate(90)
85
  image_array = np.array(image_pil)
86
  return image_array
87
 
@@ -492,7 +497,7 @@ title_html = """
492
  This demo can handle huge images but the process will be aborted if it lasts more than 10 min.
493
  Please leave a message in discussion if you encounter issues.
494
 
495
- <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>
496
  """
497
 
498
 
@@ -523,9 +528,9 @@ with gr.Blocks(title="SUPIR") as interface:
523
  input_image = gr.Image(label="Input", show_label=True, type="numpy", height=600, elem_id="image-input")
524
  with gr.Row():
525
  with gr.Column():
526
- rotate_anti_90_button = gr.Button(value="⤴ Rotate -90°", elem_id="rotate_anti_90_button")
527
  with gr.Column():
528
- rotate_90_button = gr.Button(value="⤵ Rotate +90°", elem_id="rotate_90_button")
529
  with gr.Group():
530
  prompt = gr.Textbox(label="Image description", info="Help the AI understand what the image represents; describe as much as possible, especially the details we can't see on the original image; I advise you to write in English because other languages may not be handled", value="", placeholder="A 27 years old woman, walking, in Santiago, morning, Summer, photorealistic", lines=3)
531
  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.")
@@ -720,9 +725,12 @@ with gr.Blocks(title="SUPIR") as interface:
720
  with gr.Row():
721
  gr.Markdown(claim_md)
722
 
723
- input_image.upload(fn = check, inputs = [
724
  input_image
725
- ], outputs = [], queue = False, show_progress = False)
 
 
 
726
 
727
  rotate_anti_90_button.click(fn = rotate_anti_90, inputs = [
728
  input_image
 
67
  else:
68
  llava_agent = None
69
 
70
+ def check_upload(input_image):
71
+ if input_image is None:
72
+ raise gr.Error("Please provide an image to restore.")
73
+ return [gr.update(visible = True)] * 2
74
+
75
  def rotate_anti_90(image_array):
76
  if image_array is None:
77
  raise gr.Error("Please provide an image to rotate.")
78
 
79
  image_pil = Image.fromarray(image_array)
80
+ image_pil = image_pil.rotate(90)
81
  image_array = np.array(image_pil)
82
  return image_array
83
 
 
86
  raise gr.Error("Please provide an image to rotate.")
87
 
88
  image_pil = Image.fromarray(image_array)
89
+ image_pil = image_pil.rotate(-90)
90
  image_array = np.array(image_pil)
91
  return image_array
92
 
 
497
  This demo can handle huge images but the process will be aborted if it lasts more than 10 min.
498
  Please leave a message in discussion if you encounter issues.
499
 
500
+ <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://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai">Local Install Guide</a></center></p>
501
  """
502
 
503
 
 
528
  input_image = gr.Image(label="Input", show_label=True, type="numpy", height=600, elem_id="image-input")
529
  with gr.Row():
530
  with gr.Column():
531
+ rotate_anti_90_button = gr.Button(value="⤴ Rotate -90°", elem_id="rotate_anti_90_button", visible=False)
532
  with gr.Column():
533
+ rotate_90_button = gr.Button(value="⤵ Rotate +90°", elem_id="rotate_90_button", visible=False)
534
  with gr.Group():
535
  prompt = gr.Textbox(label="Image description", info="Help the AI understand what the image represents; describe as much as possible, especially the details we can't see on the original image; I advise you to write in English because other languages may not be handled", value="", placeholder="A 27 years old woman, walking, in Santiago, morning, Summer, photorealistic", lines=3)
536
  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.")
 
725
  with gr.Row():
726
  gr.Markdown(claim_md)
727
 
728
+ input_image.upload(fn = check_upload, inputs = [
729
  input_image
730
+ ], outputs = [
731
+ rotate_anti_90_button,
732
+ rotate_90_button
733
+ ], queue = False, show_progress = False)
734
 
735
  rotate_anti_90_button.click(fn = rotate_anti_90, inputs = [
736
  input_image