MonsterMMORPG commited on
Commit
779d534
·
verified ·
1 Parent(s): e78190e

Update giga_App.py

Browse files
Files changed (1) hide show
  1. giga_App.py +28 -20
giga_App.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
 
2
  from PIL import Image
3
  import numpy as np
4
  from aura_sr import AuraSR
5
  import torch
6
  import os
7
  import time
8
- from pathlib import Path
9
  import platform
10
  import argparse
11
 
@@ -16,6 +16,17 @@ def open_folder():
16
  elif platform.system() == "Linux":
17
  os.system(f'xdg-open "{open_folder_path}"')
18
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Force CPU usage
20
  torch.set_default_tensor_type(torch.FloatTensor)
21
 
@@ -34,7 +45,9 @@ def process_single_image(input_image_path, reduce_seams):
34
  raise gr.Error("Please provide an image to upscale.")
35
 
36
  # Send an initial progress update.
37
- yield [[], "Starting upscaling..."]
 
 
38
 
39
  # Load the image.
40
  pil_image = Image.open(input_image_path)
@@ -42,11 +55,9 @@ def process_single_image(input_image_path, reduce_seams):
42
  # Upscale using the chosen method.
43
  start_time = time.time()
44
  if reduce_seams:
45
- # Using upscale_4x_overlapped to reduce seam artifacts.
46
  print("using reduce seams")
47
  upscaled_image = aura_sr.upscale_4x_overlapped(pil_image)
48
  else:
49
- # Default upscaling method.
50
  upscaled_image = aura_sr.upscale_4x(pil_image)
51
  processing_time = time.time() - start_time
52
  print(f"Processing time: {processing_time:.2f} seconds")
@@ -66,8 +77,8 @@ def process_single_image(input_image_path, reduce_seams):
66
 
67
  upscaled_image.save(output_path)
68
 
69
- # Send the final progress update along with the before/after gallery.
70
- yield [[input_image_path, output_path],
71
  f"Upscaling complete in {processing_time:.2f} seconds"]
72
 
73
  def process_batch(input_folder, output_folder=None, reduce_seams=False):
@@ -84,7 +95,6 @@ def process_batch(input_folder, output_folder=None, reduce_seams=False):
84
  processed_files = 0
85
  results = []
86
 
87
- # Initial progress update.
88
  yield [results, "Starting batch processing..."]
89
 
90
  for filename in input_files:
@@ -107,16 +117,13 @@ def process_batch(input_folder, output_folder=None, reduce_seams=False):
107
  counter += 1
108
 
109
  upscaled_image.save(output_path)
110
-
111
  processed_files += 1
112
  results.append(output_path)
113
- # Yield progress update after processing each image.
114
  yield [results, f"Processed {processed_files}/{total_files}: {filename} in {processing_time:.2f} seconds"]
115
 
116
- # Final update.
117
  yield [results, f"Batch processing complete. {processed_files} images processed."]
118
 
119
- title = """<h1 align="center">AuraSR Giga Upscaler V2 by SECourses - Upscales to 4x</h1>
120
  <p><center>AuraSR: new open source super-resolution upscaler based on GigaGAN. Works perfect on some images and fails on some images so give it a try</center></p>
121
  <p><center>Works very fast and very VRAM friendly</center></p>
122
  <h2 align="center">Latest version on : <a href="https://www.patreon.com/posts/110060645">https://www.patreon.com/posts/110060645</a></h2>
@@ -132,43 +139,44 @@ def create_demo():
132
  input_image = gr.Image(label="Input Image", type="filepath")
133
  reduce_seams = gr.Checkbox(
134
  label="Reduce Seam Artifacts",
135
- value=False,
136
  info="upscale_4x upscales the image in tiles that do not overlap. This can result in seams. Use upscale_4x_overlapped to reduce seams. This will double the time upscaling by taking an additional pass and averaging the results."
137
  )
138
  process_btn = gr.Button(value="Upscale Image", variant="primary")
139
  with gr.Column(scale=1):
140
- output_gallery = gr.Gallery(label="Before / After", columns=2)
 
 
141
  progress_text = gr.Markdown("Progress messages will appear here.")
142
  btn_open_outputs = gr.Button("Open Outputs Folder", variant="primary")
143
  btn_open_outputs.click(fn=open_folder)
144
-
145
- # The function now yields two outputs: a gallery and a progress message.
146
  process_btn.click(
147
  fn=process_single_image,
148
  inputs=[input_image, reduce_seams],
149
- outputs=[output_gallery, progress_text]
150
  )
151
-
152
  with gr.Tab("Batch Processing"):
153
  with gr.Row():
154
  input_folder = gr.Textbox(label="Input Folder Path")
155
  output_folder = gr.Textbox(label="Output Folder Path (Optional)")
156
  reduce_seams_batch = gr.Checkbox(
157
  label="Reduce Seam Artifacts",
158
- value=False,
159
  info="upscale_4x upscales the image in tiles that do not overlap. This can result in seams. Use upscale_4x_overlapped to reduce seams. This will double the time upscaling by taking an additional pass and averaging the results."
160
  )
161
  batch_process_btn = gr.Button(value="Process Batch", variant="primary")
162
  with gr.Column():
163
  output_gallery_batch = gr.Gallery(label="Processed Images")
164
  progress_text_batch = gr.Markdown("Progress messages will appear here.")
165
-
166
  batch_process_btn.click(
167
  fn=process_batch,
168
  inputs=[input_folder, output_folder, reduce_seams_batch],
169
  outputs=[output_gallery_batch, progress_text_batch]
170
  )
171
-
172
  return demo
173
 
174
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from gradio_imageslider import ImageSlider
3
  from PIL import Image
4
  import numpy as np
5
  from aura_sr import AuraSR
6
  import torch
7
  import os
8
  import time
 
9
  import platform
10
  import argparse
11
 
 
16
  elif platform.system() == "Linux":
17
  os.system(f'xdg-open "{open_folder_path}"')
18
 
19
+ def get_placeholder_image():
20
+ """
21
+ Creates a placeholder image (if not already present) and returns its file path.
22
+ This placeholder is a blank (white) image that will be used for progress updates.
23
+ """
24
+ placeholder_path = "placeholder.png"
25
+ if not os.path.exists(placeholder_path):
26
+ placeholder = Image.new("RGB", (256, 256), (255, 255, 255))
27
+ placeholder.save(placeholder_path)
28
+ return placeholder_path
29
+
30
  # Force CPU usage
31
  torch.set_default_tensor_type(torch.FloatTensor)
32
 
 
45
  raise gr.Error("Please provide an image to upscale.")
46
 
47
  # Send an initial progress update.
48
+ # Instead of (None, None), we use the placeholder image file paths.
49
+ placeholder = get_placeholder_image()
50
+ yield [(placeholder, placeholder), "Starting upscaling..."]
51
 
52
  # Load the image.
53
  pil_image = Image.open(input_image_path)
 
55
  # Upscale using the chosen method.
56
  start_time = time.time()
57
  if reduce_seams:
 
58
  print("using reduce seams")
59
  upscaled_image = aura_sr.upscale_4x_overlapped(pil_image)
60
  else:
 
61
  upscaled_image = aura_sr.upscale_4x(pil_image)
62
  processing_time = time.time() - start_time
63
  print(f"Processing time: {processing_time:.2f} seconds")
 
77
 
78
  upscaled_image.save(output_path)
79
 
80
+ # Send the final progress update along with the before/after slider images.
81
+ yield [(input_image_path, output_path),
82
  f"Upscaling complete in {processing_time:.2f} seconds"]
83
 
84
  def process_batch(input_folder, output_folder=None, reduce_seams=False):
 
95
  processed_files = 0
96
  results = []
97
 
 
98
  yield [results, "Starting batch processing..."]
99
 
100
  for filename in input_files:
 
117
  counter += 1
118
 
119
  upscaled_image.save(output_path)
 
120
  processed_files += 1
121
  results.append(output_path)
 
122
  yield [results, f"Processed {processed_files}/{total_files}: {filename} in {processing_time:.2f} seconds"]
123
 
 
124
  yield [results, f"Batch processing complete. {processed_files} images processed."]
125
 
126
+ title = """<h1 align="center">AuraSR Giga Upscaler V3 by SECourses - Upscales to 4x</h1>
127
  <p><center>AuraSR: new open source super-resolution upscaler based on GigaGAN. Works perfect on some images and fails on some images so give it a try</center></p>
128
  <p><center>Works very fast and very VRAM friendly</center></p>
129
  <h2 align="center">Latest version on : <a href="https://www.patreon.com/posts/110060645">https://www.patreon.com/posts/110060645</a></h2>
 
139
  input_image = gr.Image(label="Input Image", type="filepath")
140
  reduce_seams = gr.Checkbox(
141
  label="Reduce Seam Artifacts",
142
+ value=True,
143
  info="upscale_4x upscales the image in tiles that do not overlap. This can result in seams. Use upscale_4x_overlapped to reduce seams. This will double the time upscaling by taking an additional pass and averaging the results."
144
  )
145
  process_btn = gr.Button(value="Upscale Image", variant="primary")
146
  with gr.Column(scale=1):
147
+ # Use the ImageSlider component for comparing before & after images.
148
+ # "filepath" type means the component expects image file paths.
149
+ output_slider = ImageSlider(label="Before / After", type="filepath", slider_color="blue")
150
  progress_text = gr.Markdown("Progress messages will appear here.")
151
  btn_open_outputs = gr.Button("Open Outputs Folder", variant="primary")
152
  btn_open_outputs.click(fn=open_folder)
153
+
 
154
  process_btn.click(
155
  fn=process_single_image,
156
  inputs=[input_image, reduce_seams],
157
+ outputs=[output_slider, progress_text]
158
  )
159
+
160
  with gr.Tab("Batch Processing"):
161
  with gr.Row():
162
  input_folder = gr.Textbox(label="Input Folder Path")
163
  output_folder = gr.Textbox(label="Output Folder Path (Optional)")
164
  reduce_seams_batch = gr.Checkbox(
165
  label="Reduce Seam Artifacts",
166
+ value=True,
167
  info="upscale_4x upscales the image in tiles that do not overlap. This can result in seams. Use upscale_4x_overlapped to reduce seams. This will double the time upscaling by taking an additional pass and averaging the results."
168
  )
169
  batch_process_btn = gr.Button(value="Process Batch", variant="primary")
170
  with gr.Column():
171
  output_gallery_batch = gr.Gallery(label="Processed Images")
172
  progress_text_batch = gr.Markdown("Progress messages will appear here.")
173
+
174
  batch_process_btn.click(
175
  fn=process_batch,
176
  inputs=[input_folder, output_folder, reduce_seams_batch],
177
  outputs=[output_gallery_batch, progress_text_batch]
178
  )
179
+
180
  return demo
181
 
182
  if __name__ == "__main__":