hysts HF staff commited on
Commit
a5c1f85
1 Parent(s): 6813e85
Files changed (4) hide show
  1. .pre-commit-config.yaml +35 -0
  2. .style.yapf +5 -0
  3. README.md +1 -1
  4. app.py +34 -59
.pre-commit-config.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.2.0
4
+ hooks:
5
+ - id: check-executables-have-shebangs
6
+ - id: check-json
7
+ - id: check-merge-conflict
8
+ - id: check-shebang-scripts-are-executable
9
+ - id: check-toml
10
+ - id: check-yaml
11
+ - id: double-quote-string-fixer
12
+ - id: end-of-file-fixer
13
+ - id: mixed-line-ending
14
+ args: ['--fix=lf']
15
+ - id: requirements-txt-fixer
16
+ - id: trailing-whitespace
17
+ - repo: https://github.com/myint/docformatter
18
+ rev: v1.4
19
+ hooks:
20
+ - id: docformatter
21
+ args: ['--in-place']
22
+ - repo: https://github.com/pycqa/isort
23
+ rev: 5.12.0
24
+ hooks:
25
+ - id: isort
26
+ - repo: https://github.com/pre-commit/mirrors-mypy
27
+ rev: v0.991
28
+ hooks:
29
+ - id: mypy
30
+ args: ['--ignore-missing-imports']
31
+ - repo: https://github.com/google/yapf
32
+ rev: v0.32.0
33
+ hooks:
34
+ - id: yapf
35
+ args: ['--parallel', '--in-place']
.style.yapf ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ [style]
2
+ based_on_style = pep8
3
+ blank_line_before_nested_class_or_def = false
4
+ spaces_before_comment = 2
5
+ split_before_logical_operator = true
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 😻
4
  colorFrom: yellow
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 3.0.5
8
  app_file: app.py
9
  pinned: false
10
  ---
 
4
  colorFrom: yellow
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 3.19.1
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py CHANGED
@@ -2,16 +2,17 @@
2
 
3
  from __future__ import annotations
4
 
5
- import argparse
6
  import os
7
  import pathlib
 
8
  import subprocess
9
  import tarfile
10
 
11
  if os.environ.get('SYSTEM') == 'spaces':
12
- subprocess.call('pip uninstall -y opencv-python'.split())
13
- subprocess.call('pip uninstall -y opencv-python-headless'.split())
14
- subprocess.call('pip install opencv-python-headless==4.5.5.64'.split())
 
15
 
16
  import gradio as gr
17
  import huggingface_hub
@@ -24,22 +25,8 @@ mp_face_mesh = mp.solutions.face_mesh
24
 
25
  TITLE = 'MediaPipe Face Mesh'
26
  DESCRIPTION = 'https://google.github.io/mediapipe/'
27
- ARTICLE = '<center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.mediapipe-face-mesh" alt="visitor badge"/></center>'
28
 
29
- TOKEN = os.environ['TOKEN']
30
-
31
-
32
- def parse_args() -> argparse.Namespace:
33
- parser = argparse.ArgumentParser()
34
- parser.add_argument('--theme', type=str)
35
- parser.add_argument('--live', action='store_true')
36
- parser.add_argument('--share', action='store_true')
37
- parser.add_argument('--port', type=int)
38
- parser.add_argument('--disable-queue',
39
- dest='enable_queue',
40
- action='store_false')
41
- parser.add_argument('--allow-flagging', type=str, default='never')
42
- return parser.parse_args()
43
 
44
 
45
  def load_sample_images() -> list[pathlib.Path]:
@@ -52,7 +39,7 @@ def load_sample_images() -> list[pathlib.Path]:
52
  path = huggingface_hub.hf_hub_download(dataset_repo,
53
  name,
54
  repo_type='dataset',
55
- use_auth_token=TOKEN)
56
  with tarfile.open(path) as f:
57
  f.extractall(image_dir.as_posix())
58
  return sorted(image_dir.rglob('*.jpg'))
@@ -104,42 +91,30 @@ def run(
104
  return res[:, :, ::-1]
105
 
106
 
107
- def main():
108
- args = parse_args()
109
-
110
- image_paths = load_sample_images()
111
- examples = [[path.as_posix(), 5, 0.5, True, True, True]
112
- for path in image_paths]
113
-
114
- gr.Interface(
115
- run,
116
- [
117
- gr.inputs.Image(type='numpy', label='Input'),
118
- gr.inputs.Slider(
119
- 0, 10, step=1, default=5, label='Max Number of Faces'),
120
- gr.inputs.Slider(0,
121
- 1,
122
- step=0.05,
123
- default=0.5,
124
- label='Minimum Detection Confidence'),
125
- gr.inputs.Checkbox(default=True, label='Show Tesselation'),
126
- gr.inputs.Checkbox(default=True, label='Show Contours'),
127
- gr.inputs.Checkbox(default=True, label='Show Irises'),
128
- ],
129
- gr.outputs.Image(type='numpy', label='Output'),
130
- examples=examples,
131
- title=TITLE,
132
- description=DESCRIPTION,
133
- article=ARTICLE,
134
- theme=args.theme,
135
- allow_flagging=args.allow_flagging,
136
- live=args.live,
137
- ).launch(
138
- enable_queue=args.enable_queue,
139
- server_port=args.port,
140
- share=args.share,
141
- )
142
-
143
-
144
- if __name__ == '__main__':
145
- main()
 
2
 
3
  from __future__ import annotations
4
 
 
5
  import os
6
  import pathlib
7
+ import shlex
8
  import subprocess
9
  import tarfile
10
 
11
  if os.environ.get('SYSTEM') == 'spaces':
12
+ subprocess.call(shlex.split('pip uninstall -y opencv-python'))
13
+ subprocess.call(shlex.split('pip uninstall -y opencv-python-headless'))
14
+ subprocess.call(
15
+ shlex.split('pip install opencv-python-headless==4.5.5.64'))
16
 
17
  import gradio as gr
18
  import huggingface_hub
 
25
 
26
  TITLE = 'MediaPipe Face Mesh'
27
  DESCRIPTION = 'https://google.github.io/mediapipe/'
 
28
 
29
+ HF_TOKEN = os.getenv('HF_TOKEN')
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
 
32
  def load_sample_images() -> list[pathlib.Path]:
 
39
  path = huggingface_hub.hf_hub_download(dataset_repo,
40
  name,
41
  repo_type='dataset',
42
+ use_auth_token=HF_TOKEN)
43
  with tarfile.open(path) as f:
44
  f.extractall(image_dir.as_posix())
45
  return sorted(image_dir.rglob('*.jpg'))
 
91
  return res[:, :, ::-1]
92
 
93
 
94
+ image_paths = load_sample_images()
95
+ examples = [[path.as_posix(), 5, 0.5, True, True, True]
96
+ for path in image_paths]
97
+
98
+ gr.Interface(
99
+ fn=run,
100
+ inputs=[
101
+ gr.Image(label='Input', type='numpy'),
102
+ gr.Slider(label='Max Number of Faces',
103
+ minimum=0,
104
+ maximum=10,
105
+ step=1,
106
+ value=5),
107
+ gr.Slider(label='Minimum Detection Confidence',
108
+ minimum=0,
109
+ maximum=1,
110
+ step=0.05,
111
+ value=0.5),
112
+ gr.Checkbox(label='Show Tesselation', value=True),
113
+ gr.Checkbox(label='Show Contours', value=True),
114
+ gr.Checkbox(label='Show Irises', value=True),
115
+ ],
116
+ outputs=gr.Image(label='Output', type='numpy'),
117
+ examples=examples,
118
+ title=TITLE,
119
+ description=DESCRIPTION,
120
+ ).launch(show_api=False)