gaviego commited on
Commit
c027140
1 Parent(s): 85af82b

Batch now generates zip

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -12,6 +12,7 @@ import torch.nn.functional as F
12
  import matplotlib.pyplot as plt
13
  import warnings
14
  import tempfile
 
15
 
16
  warnings.filterwarnings("ignore")
17
 
@@ -152,8 +153,13 @@ def bw_single(image_file):
152
  def batch(image_files):
153
  output = []
154
  for idx, file in enumerate(image_files):
155
- output.append(inference(file.name))
156
- return output
 
 
 
 
 
157
 
158
  with gr.Blocks() as iface:
159
  gr.Markdown("# Remove Background")
@@ -177,6 +183,8 @@ with gr.Blocks() as iface:
177
  images = gr.File(file_count="multiple", file_types=["image"])
178
  with gr.Column():
179
  gallery = gr.Gallery()
 
 
180
  with gr.Row():
181
  with gr.Column():
182
  batch_removebg = gr.Button("Batch Process")
@@ -184,7 +192,7 @@ with gr.Blocks() as iface:
184
  batch_clear = gr.Button("Clear")
185
  #Events
186
  single_removebg.click(inference, inputs=image, outputs=image_output)
187
- batch_removebg.click(batch, inputs=images, outputs=gallery)
188
  single_clear.click(lambda: None, None, image, queue=False)
189
  batch_clear.click(lambda: None, None, images, queue=False)
190
 
 
12
  import matplotlib.pyplot as plt
13
  import warnings
14
  import tempfile
15
+ from zipfile import ZipFile
16
 
17
  warnings.filterwarnings("ignore")
18
 
 
153
  def batch(image_files):
154
  output = []
155
  for idx, file in enumerate(image_files):
156
+ file = inference(file.name)
157
+ output.append(file)
158
+
159
+ with ZipFile("tmp.zip", "w") as zipObj:
160
+ for idx, file in enumerate(output):
161
+ zipObj.write(file, file.split("/")[-1])
162
+ return output,"tmp.zip"
163
 
164
  with gr.Blocks() as iface:
165
  gr.Markdown("# Remove Background")
 
183
  images = gr.File(file_count="multiple", file_types=["image"])
184
  with gr.Column():
185
  gallery = gr.Gallery()
186
+ file_list = gr.Files(interactive=False)
187
+
188
  with gr.Row():
189
  with gr.Column():
190
  batch_removebg = gr.Button("Batch Process")
 
192
  batch_clear = gr.Button("Clear")
193
  #Events
194
  single_removebg.click(inference, inputs=image, outputs=image_output)
195
+ batch_removebg.click(batch, inputs=images, outputs=[gallery,file_list])
196
  single_clear.click(lambda: None, None, image, queue=False)
197
  batch_clear.click(lambda: None, None, images, queue=False)
198