Update
Browse files- .gitattributes +1 -0
- .gitignore +0 -1
- README.md +1 -1
- app.py +25 -40
- images/pexels-ksenia-chernaya-8535230.jpg +3 -0
- requirements.txt +3 -3
- style.css +7 -0
.gitattributes
CHANGED
@@ -26,3 +26,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
26 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
26 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
images
|
|
|
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🏢
|
|
4 |
colorFrom: gray
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: gray
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.36.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -4,35 +4,13 @@ from __future__ import annotations
|
|
4 |
|
5 |
import functools
|
6 |
import os
|
7 |
-
import pathlib
|
8 |
-
import tarfile
|
9 |
|
10 |
import cv2
|
11 |
import gradio as gr
|
12 |
-
import huggingface_hub
|
13 |
import numpy as np
|
14 |
import onnxruntime as ort
|
15 |
|
16 |
-
|
17 |
-
DESCRIPTION = 'This is an unofficial demo for https://github.com/atksh/onnx-facial-lmk-detector.'
|
18 |
-
|
19 |
-
HF_TOKEN = os.getenv('HF_TOKEN')
|
20 |
-
|
21 |
-
|
22 |
-
def load_sample_images() -> list[pathlib.Path]:
|
23 |
-
image_dir = pathlib.Path('images')
|
24 |
-
if not image_dir.exists():
|
25 |
-
image_dir.mkdir()
|
26 |
-
dataset_repo = 'hysts/input-images'
|
27 |
-
filenames = ['001.tar']
|
28 |
-
for name in filenames:
|
29 |
-
path = huggingface_hub.hf_hub_download(dataset_repo,
|
30 |
-
name,
|
31 |
-
repo_type='dataset',
|
32 |
-
use_auth_token=HF_TOKEN)
|
33 |
-
with tarfile.open(path) as f:
|
34 |
-
f.extractall(image_dir.as_posix())
|
35 |
-
return sorted(image_dir.rglob('*.jpg'))
|
36 |
|
37 |
|
38 |
def run(image: np.ndarray, sess: ort.InferenceSession) -> np.ndarray:
|
@@ -58,20 +36,27 @@ sess = ort.InferenceSession('onnx-facial-lmk-detector/model.onnx',
|
|
58 |
sess_options=options,
|
59 |
providers=['CPUExecutionProvider'])
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
gr.
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
gr.
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
import functools
|
6 |
import os
|
|
|
|
|
7 |
|
8 |
import cv2
|
9 |
import gradio as gr
|
|
|
10 |
import numpy as np
|
11 |
import onnxruntime as ort
|
12 |
|
13 |
+
DESCRIPTION = '# [atksh/onnx-facial-lmk-detector](https://github.com/atksh/onnx-facial-lmk-detector)'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
def run(image: np.ndarray, sess: ort.InferenceSession) -> np.ndarray:
|
|
|
36 |
sess_options=options,
|
37 |
providers=['CPUExecutionProvider'])
|
38 |
|
39 |
+
fn = functools.partial(run, sess=sess)
|
40 |
+
|
41 |
+
examples = [['onnx-facial-lmk-detector/input.jpg'],
|
42 |
+
['images/pexels-ksenia-chernaya-8535230.jpg']]
|
43 |
+
|
44 |
+
with gr.Blocks(css='style.css') as demo:
|
45 |
+
gr.Markdown(DESCRIPTION)
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column():
|
48 |
+
image = gr.Image(label='Input', type='numpy')
|
49 |
+
run_button = gr.Button()
|
50 |
+
with gr.Column():
|
51 |
+
result = gr.Image(label='Output')
|
52 |
+
gallery = gr.Gallery(label='Aligned Faces')
|
53 |
+
gr.Examples(examples=examples,
|
54 |
+
inputs=image,
|
55 |
+
outputs=[result, gallery],
|
56 |
+
fn=fn,
|
57 |
+
cache_examples=os.getenv('CACHE_EXAMPLES') == '1')
|
58 |
+
run_button.click(fn=fn,
|
59 |
+
inputs=image,
|
60 |
+
outputs=[result, gallery],
|
61 |
+
api_name='run')
|
62 |
+
demo.queue(max_size=10).launch()
|
images/pexels-ksenia-chernaya-8535230.jpg
ADDED
Git LFS Details
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
numpy==1.
|
2 |
-
onnxruntime==1.
|
3 |
-
opencv-python-headless==4.
|
|
|
1 |
+
numpy==1.23.5
|
2 |
+
onnxruntime==1.15.0
|
3 |
+
opencv-python-headless==4.8.0.74
|
style.css
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
h1 {
|
2 |
+
text-align: center;
|
3 |
+
}
|
4 |
+
|
5 |
+
#duplicate-button {
|
6 |
+
margin: auto;
|
7 |
+
}
|