Spaces:
Runtime error
Runtime error
update
Browse files- app.py +5 -38
- utils/functions.py +38 -1
app.py
CHANGED
@@ -8,6 +8,8 @@ from PIL import Image
|
|
8 |
import sys, os
|
9 |
from rembg import remove
|
10 |
from utils import functions
|
|
|
|
|
11 |
import os, sys
|
12 |
import argparse
|
13 |
|
@@ -18,43 +20,8 @@ logger.setLevel(DEBUG)
|
|
18 |
logger.addHandler(handler)
|
19 |
logger.propagate = False
|
20 |
|
21 |
-
# logger.debug('variable')
|
22 |
-
# logger.info('system')
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
def complete(work_dir):
|
27 |
-
work_dir = work_dir
|
28 |
-
# logger.debug(f"complete :", work_dir)
|
29 |
-
return work_dir
|
30 |
-
|
31 |
-
|
32 |
-
def clean(text_output):
|
33 |
-
# logger.debug(f"text_output : {text_output}")
|
34 |
-
|
35 |
-
if text_output!="idle_state":
|
36 |
-
logger.info(f"clean up : {text_output}.zip")
|
37 |
-
os.remove(f"{text_output}.zip")
|
38 |
-
return "idle_state"
|
39 |
-
else:
|
40 |
-
logger.info(f"reset")
|
41 |
-
return "idle_state"
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
def clean_by_name(text_output):
|
46 |
-
# logger.debug(f"text_output : {text_output}")
|
47 |
-
if text_output!="idle_state":
|
48 |
-
text_output, dir_name = text_output.split("+")
|
49 |
-
logger.info(f"clean up : {dir_name}.zip")
|
50 |
-
os.remove(f"{dir_name}.zip")
|
51 |
-
return "idle_state"
|
52 |
-
else:
|
53 |
-
logger.info(f"reset")
|
54 |
-
return "idle_state"
|
55 |
-
|
56 |
-
|
57 |
|
|
|
58 |
def run_rembg(img):
|
59 |
output = remove(img)
|
60 |
output_pil = Image.fromarray(output)
|
@@ -66,7 +33,7 @@ def run_rembg(img):
|
|
66 |
|
67 |
|
68 |
def from_zip(inputs):
|
69 |
-
work_dir =
|
70 |
os.makedirs(work_dir, exist_ok=True)
|
71 |
|
72 |
image_data_dict = {}
|
@@ -90,7 +57,7 @@ def from_zip(inputs):
|
|
90 |
image_files.append(image_name)
|
91 |
|
92 |
image_array = np.array(image)
|
93 |
-
logger.debug(f"image name : {image_name}")
|
94 |
category_dir = image_name.split("/")[0]
|
95 |
# image_name = image_name.split("/")[1]
|
96 |
os.makedirs(f"{work_dir}/{category_dir}", exist_ok=True)
|
|
|
8 |
import sys, os
|
9 |
from rembg import remove
|
10 |
from utils import functions
|
11 |
+
from utils.functions import complete, clean, clean_by_name, get_random_name
|
12 |
+
|
13 |
import os, sys
|
14 |
import argparse
|
15 |
|
|
|
20 |
logger.addHandler(handler)
|
21 |
logger.propagate = False
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
|
25 |
def run_rembg(img):
|
26 |
output = remove(img)
|
27 |
output_pil = Image.fromarray(output)
|
|
|
33 |
|
34 |
|
35 |
def from_zip(inputs):
|
36 |
+
work_dir = get_random_name()
|
37 |
os.makedirs(work_dir, exist_ok=True)
|
38 |
|
39 |
image_data_dict = {}
|
|
|
57 |
image_files.append(image_name)
|
58 |
|
59 |
image_array = np.array(image)
|
60 |
+
# logger.debug(f"image name : {image_name}")
|
61 |
category_dir = image_name.split("/")[0]
|
62 |
# image_name = image_name.split("/")[1]
|
63 |
os.makedirs(f"{work_dir}/{category_dir}", exist_ok=True)
|
utils/functions.py
CHANGED
@@ -1,4 +1,11 @@
|
|
1 |
-
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def get_random_name():
|
4 |
famous_painters = [
|
@@ -31,3 +38,33 @@ def get_random_name():
|
|
31 |
|
32 |
return random_painter+str(rand_num)
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, random
|
2 |
+
from logging import getLogger, StreamHandler, DEBUG
|
3 |
+
logger = getLogger(__name__)
|
4 |
+
handler = StreamHandler(); handler.setLevel(DEBUG)
|
5 |
+
logger.setLevel(DEBUG)
|
6 |
+
logger.addHandler(handler)
|
7 |
+
logger.propagate = False
|
8 |
+
|
9 |
|
10 |
def get_random_name():
|
11 |
famous_painters = [
|
|
|
38 |
|
39 |
return random_painter+str(rand_num)
|
40 |
|
41 |
+
|
42 |
+
def complete(work_dir):
|
43 |
+
work_dir = work_dir
|
44 |
+
# logger.debug(f"complete :", work_dir)
|
45 |
+
return work_dir
|
46 |
+
|
47 |
+
|
48 |
+
def clean(text_output):
|
49 |
+
# logger.debug(f"text_output : {text_output}")
|
50 |
+
|
51 |
+
if text_output!="idle_state":
|
52 |
+
logger.info(f"clean up : {text_output}.zip")
|
53 |
+
os.remove(f"{text_output}.zip")
|
54 |
+
return "idle_state"
|
55 |
+
else:
|
56 |
+
logger.info(f"reset")
|
57 |
+
return "idle_state"
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
def clean_by_name(text_output):
|
62 |
+
# logger.debug(f"text_output : {text_output}")
|
63 |
+
if text_output!="idle_state":
|
64 |
+
text_output, dir_name = text_output.split("+")
|
65 |
+
logger.info(f"clean up : {dir_name}.zip")
|
66 |
+
os.remove(f"{dir_name}.zip")
|
67 |
+
return "idle_state"
|
68 |
+
else:
|
69 |
+
logger.info(f"reset")
|
70 |
+
return "idle_state"
|