MonsterMMORPG commited on
Commit
987b3cc
·
verified ·
1 Parent(s): 5cedabe

Update giga_App.py

Browse files
Files changed (1) hide show
  1. giga_App.py +26 -2
giga_App.py CHANGED
@@ -9,6 +9,9 @@ import time
9
  import platform
10
  import argparse
11
 
 
 
 
12
  def open_folder():
13
  open_folder_path = os.path.abspath("outputs")
14
  if platform.system() == "Windows":
@@ -82,6 +85,10 @@ def process_single_image(input_image_path, reduce_seams):
82
  f"Upscaling complete in {processing_time:.2f} seconds"]
83
 
84
  def process_batch(input_folder, output_folder=None, reduce_seams=False):
 
 
 
 
85
  if not input_folder:
86
  raise gr.Error("Please provide an input folder path.")
87
 
@@ -98,6 +105,11 @@ def process_batch(input_folder, output_folder=None, reduce_seams=False):
98
  yield [results, "Starting batch processing..."]
99
 
100
  for filename in input_files:
 
 
 
 
 
101
  input_path = os.path.join(input_folder, filename)
102
  pil_image = Image.open(input_path)
103
 
@@ -123,7 +135,12 @@ def process_batch(input_folder, output_folder=None, reduce_seams=False):
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/121441873">https://www.patreon.com/posts/121441873</a></h2>
@@ -166,7 +183,9 @@ def create_demo():
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.")
@@ -176,6 +195,11 @@ def create_demo():
176
  inputs=[input_folder, output_folder, reduce_seams_batch],
177
  outputs=[output_gallery_batch, progress_text_batch]
178
  )
 
 
 
 
 
179
 
180
  return demo
181
 
 
9
  import platform
10
  import argparse
11
 
12
+ # Global variable to control batch processing cancellation.
13
+ stop_batch_flag = False
14
+
15
  def open_folder():
16
  open_folder_path = os.path.abspath("outputs")
17
  if platform.system() == "Windows":
 
85
  f"Upscaling complete in {processing_time:.2f} seconds"]
86
 
87
  def process_batch(input_folder, output_folder=None, reduce_seams=False):
88
+ global stop_batch_flag
89
+ # Reset the stop flag for each new batch process.
90
+ stop_batch_flag = False
91
+
92
  if not input_folder:
93
  raise gr.Error("Please provide an input folder path.")
94
 
 
105
  yield [results, "Starting batch processing..."]
106
 
107
  for filename in input_files:
108
+ # Check if the stop flag has been set.
109
+ if stop_batch_flag:
110
+ yield [results, "Batch processing cancelled by user."]
111
+ return
112
+
113
  input_path = os.path.join(input_folder, filename)
114
  pil_image = Image.open(input_path)
115
 
 
135
 
136
  yield [results, f"Batch processing complete. {processed_files} images processed."]
137
 
138
+ def stop_batch_process():
139
+ global stop_batch_flag
140
+ stop_batch_flag = True
141
+ return "Stop button clicked. Cancelling batch processing..."
142
+
143
+ title = """<h1 align="center">AuraSR Giga Upscaler V4 by SECourses - Upscales to 4x</h1>
144
  <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>
145
  <p><center>Works very fast and very VRAM friendly</center></p>
146
  <h2 align="center">Latest version on : <a href="https://www.patreon.com/posts/121441873">https://www.patreon.com/posts/121441873</a></h2>
 
183
  value=True,
184
  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."
185
  )
186
+ with gr.Row():
187
+ batch_process_btn = gr.Button(value="Process Batch", variant="primary")
188
+ stop_batch_btn = gr.Button(value="Stop Batch Processing", variant="secondary")
189
  with gr.Column():
190
  output_gallery_batch = gr.Gallery(label="Processed Images")
191
  progress_text_batch = gr.Markdown("Progress messages will appear here.")
 
195
  inputs=[input_folder, output_folder, reduce_seams_batch],
196
  outputs=[output_gallery_batch, progress_text_batch]
197
  )
198
+ stop_batch_btn.click(
199
+ fn=stop_batch_process,
200
+ inputs=[],
201
+ outputs=[progress_text_batch]
202
+ )
203
 
204
  return demo
205