6Morpheus6 commited on
Commit
d858831
·
verified ·
1 Parent(s): 44f737a

download option

Browse files

New UI:
- download element
- output folder
- max image element height (no more scrolling needed)

Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import spaces
2
  import gradio as gr
3
  from gradio_imageslider import ImageSlider
@@ -21,6 +23,14 @@ aura_sr = AuraSR.from_pretrained("fal/AuraSR-v2", device=DEVICE)
21
  # Restore original torch.load
22
  torch.load = original_load
23
 
 
 
 
 
 
 
 
 
24
  def process_image(input_image):
25
  if input_image is None:
26
  raise gr.Error("Please provide an image to upscale.")
@@ -34,7 +44,12 @@ def process_image(input_image):
34
  # Convert result to numpy array if it's not already
35
  result_array = np.array(upscaled_image)
36
 
37
- return [input_image, result_array]
 
 
 
 
 
38
 
39
  @spaces.GPU
40
  def process_image_on_gpu(pil_image):
@@ -48,21 +63,28 @@ title = """<h1 align="center">AuraSR-v2 - An open reproduction of the GigaGAN Up
48
  </center></p>
49
  """
50
 
51
- with gr.Blocks() as demo:
 
 
 
 
 
 
52
 
53
  gr.HTML(title)
54
 
55
  with gr.Row():
56
  with gr.Column(scale=1):
57
- input_image = gr.Image(label="Input Image", type="numpy")
58
  process_btn = gr.Button("Upscale Image")
59
  with gr.Column(scale=1):
60
- output_slider = ImageSlider(label="Before / After", type="numpy")
 
61
 
62
  process_btn.click(
63
  fn=process_image,
64
  inputs=[input_image],
65
- outputs=output_slider
66
  )
67
 
68
  # Add examples
 
1
+ import os
2
+ import time
3
  import spaces
4
  import gradio as gr
5
  from gradio_imageslider import ImageSlider
 
23
  # Restore original torch.load
24
  torch.load = original_load
25
 
26
+ # Create output folder if not exists
27
+ output_folder = '../outputs'
28
+ os.makedirs(output_folder, exist_ok=True)
29
+
30
+ def generate_output_filename():
31
+ timestamp = time.strftime("%Y%m%d-%H%M%S")
32
+ return f"upscaled_{timestamp}.png"
33
+
34
  def process_image(input_image):
35
  if input_image is None:
36
  raise gr.Error("Please provide an image to upscale.")
 
44
  # Convert result to numpy array if it's not already
45
  result_array = np.array(upscaled_image)
46
 
47
+ # Save result as PNG
48
+ output_filename = generate_output_filename()
49
+ output_path = os.path.join(output_folder, output_filename)
50
+ upscaled_image.save(output_path, format="PNG")
51
+
52
+ return [input_image, result_array], output_path
53
 
54
  @spaces.GPU
55
  def process_image_on_gpu(pil_image):
 
63
  </center></p>
64
  """
65
 
66
+ css = """
67
+ .img { max-height: 80vh !Important }
68
+ #slider-container { overflow: hidden; display: flex; justify-content: center }
69
+ #row-height { height: 65px !important }
70
+ """
71
+
72
+ with gr.Blocks(css=css) as demo:
73
 
74
  gr.HTML(title)
75
 
76
  with gr.Row():
77
  with gr.Column(scale=1):
78
+ input_image = gr.Image(label="Input Image", type="numpy", elem_classes="img")
79
  process_btn = gr.Button("Upscale Image")
80
  with gr.Column(scale=1):
81
+ output_slider = ImageSlider(label="Before / After", type="numpy", elem_classes="img", elem_id="slider-container")
82
+ download_btn = gr.File(label="Download Image", elem_id="row-height")
83
 
84
  process_btn.click(
85
  fn=process_image,
86
  inputs=[input_image],
87
+ outputs=[output_slider, download_btn]
88
  )
89
 
90
  # Add examples