Spaces:
Runtime error
Runtime error
update add function that cleans up files
Browse files
app.py
CHANGED
@@ -1,15 +1,28 @@
|
|
1 |
from zipfile import ZipFile
|
2 |
import numpy as np
|
3 |
-
from matplotlib import pyplot as plt
|
4 |
|
5 |
import os, shutil
|
6 |
|
7 |
import gradio as gr
|
8 |
-
from PIL import Image
|
9 |
import sys, os
|
10 |
from rembg import remove
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def run_rembg(img):
|
14 |
output = remove(img)
|
15 |
output_pil = Image.fromarray(output)
|
@@ -58,16 +71,11 @@ def load_zip(inputs):
|
|
58 |
|
59 |
image_name = image_name.replace("jpg", "png")
|
60 |
cropped_image.save(f"objects/{image_name}")
|
61 |
-
# plt.imsave(f"objects/{image_name}", img_array)
|
62 |
|
63 |
shutil.make_archive("objects", "zip", "objects")
|
64 |
-
# ここはresults
|
65 |
-
with ZipFile("results.zip", "w") as zip_file:
|
66 |
-
zip_file.write("objects.zip")
|
67 |
-
|
68 |
shutil.rmtree("objects")
|
69 |
-
|
70 |
-
return "
|
71 |
|
72 |
|
73 |
|
@@ -99,14 +107,21 @@ if __name__=="__main__":
|
|
99 |
with gr.Row():
|
100 |
image_input = gr.File(file_count="multiple")
|
101 |
image_output = gr.File()
|
|
|
102 |
|
103 |
btn = gr.Button("Run!")
|
104 |
|
105 |
btn.click(
|
106 |
fn=load_zip,
|
107 |
inputs=image_input,
|
108 |
-
outputs=image_output
|
109 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
|
112 |
with gr.Tab("Image"):
|
|
|
1 |
from zipfile import ZipFile
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
import os, shutil
|
5 |
|
6 |
import gradio as gr
|
7 |
+
from PIL import Image
|
8 |
import sys, os
|
9 |
from rembg import remove
|
10 |
|
11 |
|
12 |
+
def complete():
|
13 |
+
return "complete"
|
14 |
+
|
15 |
+
|
16 |
+
def clean(text_output):
|
17 |
+
if text_output=="complete":
|
18 |
+
print("clean up")
|
19 |
+
os.remove("objects.zip")
|
20 |
+
return ""
|
21 |
+
else:
|
22 |
+
pass
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
def run_rembg(img):
|
27 |
output = remove(img)
|
28 |
output_pil = Image.fromarray(output)
|
|
|
71 |
|
72 |
image_name = image_name.replace("jpg", "png")
|
73 |
cropped_image.save(f"objects/{image_name}")
|
|
|
74 |
|
75 |
shutil.make_archive("objects", "zip", "objects")
|
|
|
|
|
|
|
|
|
76 |
shutil.rmtree("objects")
|
77 |
+
|
78 |
+
return "objects.zip", complete()
|
79 |
|
80 |
|
81 |
|
|
|
107 |
with gr.Row():
|
108 |
image_input = gr.File(file_count="multiple")
|
109 |
image_output = gr.File()
|
110 |
+
text_output = gr.Textbox(visible=False)
|
111 |
|
112 |
btn = gr.Button("Run!")
|
113 |
|
114 |
btn.click(
|
115 |
fn=load_zip,
|
116 |
inputs=image_input,
|
117 |
+
outputs=[image_output, text_output]
|
118 |
)
|
119 |
+
text_output.change(
|
120 |
+
fn=clean,
|
121 |
+
inputs=text_output,
|
122 |
+
outputs=text_output
|
123 |
+
|
124 |
+
)
|
125 |
|
126 |
|
127 |
with gr.Tab("Image"):
|