Spaces:
Build error
Build error
Update
Browse files
app.py
CHANGED
@@ -9,9 +9,9 @@ import pathlib
|
|
9 |
import subprocess
|
10 |
import tarfile
|
11 |
|
12 |
-
import mim
|
13 |
-
|
14 |
if os.environ.get('SYSTEM') == 'spaces':
|
|
|
|
|
15 |
mim.uninstall('mmcv-full', confirm_yes=True)
|
16 |
mim.install('mmcv-full==1.3.16', is_yes=True)
|
17 |
|
@@ -26,22 +26,15 @@ import huggingface_hub
|
|
26 |
import numpy as np
|
27 |
import torch
|
28 |
|
29 |
-
REPO_URL = 'https://github.com/hysts/anime-face-detector'
|
30 |
TITLE = 'hysts/anime-face-detector'
|
31 |
-
DESCRIPTION =
|
32 |
-
ARTICLE =
|
33 |
|
34 |
TOKEN = os.environ['TOKEN']
|
35 |
|
36 |
|
37 |
def parse_args() -> argparse.Namespace:
|
38 |
parser = argparse.ArgumentParser()
|
39 |
-
parser.add_argument('--face-score-slider-step', type=float, default=0.05)
|
40 |
-
parser.add_argument('--face-score-threshold', type=float, default=0.5)
|
41 |
-
parser.add_argument('--landmark-score-slider-step',
|
42 |
-
type=float,
|
43 |
-
default=0.05)
|
44 |
-
parser.add_argument('--landmark-score-threshold', type=float, default=0.3)
|
45 |
parser.add_argument('--device', type=str, default='cpu')
|
46 |
parser.add_argument('--theme', type=str)
|
47 |
parser.add_argument('--live', action='store_true')
|
@@ -99,13 +92,10 @@ def detect(
|
|
99 |
color = (0, 0, 255)
|
100 |
pt = np.round(pt).astype(int)
|
101 |
cv2.circle(res, tuple(pt), line_width, color, cv2.FILLED)
|
102 |
-
res
|
103 |
-
return res
|
104 |
|
105 |
|
106 |
def main():
|
107 |
-
gr.close_all()
|
108 |
-
|
109 |
args = parse_args()
|
110 |
device = torch.device(args.device)
|
111 |
|
@@ -120,12 +110,7 @@ def main():
|
|
120 |
func = functools.update_wrapper(func, detect)
|
121 |
|
122 |
image_paths = load_sample_image_paths()
|
123 |
-
examples = [[
|
124 |
-
path.as_posix(),
|
125 |
-
'yolov3',
|
126 |
-
args.face_score_threshold,
|
127 |
-
args.landmark_score_threshold,
|
128 |
-
] for path in image_paths]
|
129 |
|
130 |
gr.Interface(
|
131 |
func,
|
@@ -135,16 +120,11 @@ def main():
|
|
135 |
type='value',
|
136 |
default='yolov3',
|
137 |
label='Detector'),
|
138 |
-
gr.inputs.Slider(
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
gr.inputs.Slider(0,
|
144 |
-
1,
|
145 |
-
step=args.landmark_score_slider_step,
|
146 |
-
default=args.landmark_score_threshold,
|
147 |
-
label='Landmark Score Threshold'),
|
148 |
],
|
149 |
gr.outputs.Image(type='numpy', label='Output'),
|
150 |
examples=examples,
|
|
|
9 |
import subprocess
|
10 |
import tarfile
|
11 |
|
|
|
|
|
12 |
if os.environ.get('SYSTEM') == 'spaces':
|
13 |
+
import mim
|
14 |
+
|
15 |
mim.uninstall('mmcv-full', confirm_yes=True)
|
16 |
mim.install('mmcv-full==1.3.16', is_yes=True)
|
17 |
|
|
|
26 |
import numpy as np
|
27 |
import torch
|
28 |
|
|
|
29 |
TITLE = 'hysts/anime-face-detector'
|
30 |
+
DESCRIPTION = 'This is a demo for https://github.com/hysts/anime-face-detector.'
|
31 |
+
ARTICLE = '<center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.anime-face-detector" alt="visitor badge"/></center>'
|
32 |
|
33 |
TOKEN = os.environ['TOKEN']
|
34 |
|
35 |
|
36 |
def parse_args() -> argparse.Namespace:
|
37 |
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
parser.add_argument('--device', type=str, default='cpu')
|
39 |
parser.add_argument('--theme', type=str)
|
40 |
parser.add_argument('--live', action='store_true')
|
|
|
92 |
color = (0, 0, 255)
|
93 |
pt = np.round(pt).astype(int)
|
94 |
cv2.circle(res, tuple(pt), line_width, color, cv2.FILLED)
|
95 |
+
return res[:, :, ::-1]
|
|
|
96 |
|
97 |
|
98 |
def main():
|
|
|
|
|
99 |
args = parse_args()
|
100 |
device = torch.device(args.device)
|
101 |
|
|
|
110 |
func = functools.update_wrapper(func, detect)
|
111 |
|
112 |
image_paths = load_sample_image_paths()
|
113 |
+
examples = [[path.as_posix(), 'yolov3', 0.5, 0.3] for path in image_paths]
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
gr.Interface(
|
116 |
func,
|
|
|
120 |
type='value',
|
121 |
default='yolov3',
|
122 |
label='Detector'),
|
123 |
+
gr.inputs.Slider(
|
124 |
+
0, 1, step=0.05, default=0.5, label='Face Score Threshold'),
|
125 |
+
gr.inputs.Slider(
|
126 |
+
0, 1, step=0.05, default=0.3,
|
127 |
+
label='Landmark Score Threshold'),
|
|
|
|
|
|
|
|
|
|
|
128 |
],
|
129 |
gr.outputs.Image(type='numpy', label='Output'),
|
130 |
examples=examples,
|