hysts HF staff commited on
Commit
12e65fc
1 Parent(s): e3a9731
Files changed (6) hide show
  1. .pre-commit-config.yaml +59 -34
  2. .style.yapf +0 -5
  3. .vscode/settings.json +30 -0
  4. README.md +1 -1
  5. app.py +26 -30
  6. requirements.txt +3 -3
.pre-commit-config.yaml CHANGED
@@ -1,35 +1,60 @@
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']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.6.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: end-of-file-fixer
12
+ - id: mixed-line-ending
13
+ args: ["--fix=lf"]
14
+ - id: requirements-txt-fixer
15
+ - id: trailing-whitespace
16
+ - repo: https://github.com/myint/docformatter
17
+ rev: v1.7.5
18
+ hooks:
19
+ - id: docformatter
20
+ args: ["--in-place"]
21
+ - repo: https://github.com/pycqa/isort
22
+ rev: 5.13.2
23
+ hooks:
24
+ - id: isort
25
+ args: ["--profile", "black"]
26
+ - repo: https://github.com/pre-commit/mirrors-mypy
27
+ rev: v1.10.0
28
+ hooks:
29
+ - id: mypy
30
+ args: ["--ignore-missing-imports"]
31
+ additional_dependencies:
32
+ [
33
+ "types-python-slugify",
34
+ "types-requests",
35
+ "types-PyYAML",
36
+ "types-pytz",
37
+ ]
38
+ - repo: https://github.com/psf/black
39
+ rev: 24.4.2
40
+ hooks:
41
+ - id: black
42
+ language_version: python3.10
43
+ args: ["--line-length", "119"]
44
+ - repo: https://github.com/kynan/nbstripout
45
+ rev: 0.7.1
46
+ hooks:
47
+ - id: nbstripout
48
+ args:
49
+ [
50
+ "--extra-keys",
51
+ "metadata.interpreter metadata.kernelspec cell.metadata.pycharm",
52
+ ]
53
+ - repo: https://github.com/nbQA-dev/nbQA
54
+ rev: 1.8.5
55
+ hooks:
56
+ - id: nbqa-black
57
+ - id: nbqa-pyupgrade
58
+ args: ["--py37-plus"]
59
+ - id: nbqa-isort
60
+ args: ["--float-to-top"]
.style.yapf DELETED
@@ -1,5 +0,0 @@
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
 
 
 
 
 
 
.vscode/settings.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "files.insertFinalNewline": false,
4
+ "[python]": {
5
+ "editor.defaultFormatter": "ms-python.black-formatter",
6
+ "editor.formatOnType": true,
7
+ "editor.codeActionsOnSave": {
8
+ "source.organizeImports": "explicit"
9
+ }
10
+ },
11
+ "[jupyter]": {
12
+ "files.insertFinalNewline": false
13
+ },
14
+ "black-formatter.args": [
15
+ "--line-length=119"
16
+ ],
17
+ "isort.args": ["--profile", "black"],
18
+ "flake8.args": [
19
+ "--max-line-length=119"
20
+ ],
21
+ "ruff.lint.args": [
22
+ "--line-length=119"
23
+ ],
24
+ "notebook.output.scrolling": true,
25
+ "notebook.formatOnCellExecution": true,
26
+ "notebook.formatOnSave.enabled": true,
27
+ "notebook.codeActionsOnSave": {
28
+ "source.organizeImports": "explicit"
29
+ }
30
+ }
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 😻
4
  colorFrom: yellow
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 3.36.1
8
  app_file: app.py
9
  pinned: false
10
  ---
 
4
  colorFrom: yellow
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 4.33.0
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py CHANGED
@@ -12,8 +12,8 @@ mp_drawing = mp.solutions.drawing_utils
12
  mp_drawing_styles = mp.solutions.drawing_styles
13
  mp_face_mesh = mp.solutions.face_mesh
14
 
15
- TITLE = 'MediaPipe Face Mesh'
16
- DESCRIPTION = 'https://google.github.io/mediapipe/'
17
 
18
 
19
  def run(
@@ -25,10 +25,11 @@ def run(
25
  show_irises: bool,
26
  ) -> np.ndarray:
27
  with mp_face_mesh.FaceMesh(
28
- static_image_mode=True,
29
- max_num_faces=max_num_faces,
30
- refine_landmarks=True,
31
- min_detection_confidence=min_detection_confidence) as face_mesh:
 
32
  results = face_mesh.process(image)
33
 
34
  res = image[:, :, ::-1].copy()
@@ -40,51 +41,46 @@ def run(
40
  landmark_list=face_landmarks,
41
  connections=mp_face_mesh.FACEMESH_TESSELATION,
42
  landmark_drawing_spec=None,
43
- connection_drawing_spec=mp_drawing_styles.
44
- get_default_face_mesh_tesselation_style())
45
  if show_contours:
46
  mp_drawing.draw_landmarks(
47
  image=res,
48
  landmark_list=face_landmarks,
49
  connections=mp_face_mesh.FACEMESH_CONTOURS,
50
  landmark_drawing_spec=None,
51
- connection_drawing_spec=mp_drawing_styles.
52
- get_default_face_mesh_contours_style())
53
  if show_irises:
54
  mp_drawing.draw_landmarks(
55
  image=res,
56
  landmark_list=face_landmarks,
57
  connections=mp_face_mesh.FACEMESH_IRISES,
58
  landmark_drawing_spec=None,
59
- connection_drawing_spec=mp_drawing_styles.
60
- get_default_face_mesh_iris_connections_style())
61
 
62
  return res[:, :, ::-1]
63
 
64
 
65
- image_paths = sorted(pathlib.Path('images').rglob('*.jpg'))
66
  examples = [[path, 5, 0.5, True, True, True] for path in image_paths]
67
 
68
- gr.Interface(
69
  fn=run,
70
  inputs=[
71
- gr.Image(label='Input', type='numpy'),
72
- gr.Slider(label='Max Number of Faces',
73
- minimum=0,
74
- maximum=10,
75
- step=1,
76
- value=5),
77
- gr.Slider(label='Minimum Detection Confidence',
78
- minimum=0,
79
- maximum=1,
80
- step=0.05,
81
- value=0.5),
82
- gr.Checkbox(label='Show Tesselation', value=True),
83
- gr.Checkbox(label='Show Contours', value=True),
84
- gr.Checkbox(label='Show Irises', value=True),
85
  ],
86
- outputs=gr.Image(label='Output', height=500),
87
  examples=examples,
88
  title=TITLE,
89
  description=DESCRIPTION,
90
- ).queue().launch()
 
 
 
 
12
  mp_drawing_styles = mp.solutions.drawing_styles
13
  mp_face_mesh = mp.solutions.face_mesh
14
 
15
+ TITLE = "MediaPipe Face Mesh"
16
+ DESCRIPTION = "https://google.github.io/mediapipe/"
17
 
18
 
19
  def run(
 
25
  show_irises: bool,
26
  ) -> np.ndarray:
27
  with mp_face_mesh.FaceMesh(
28
+ static_image_mode=True,
29
+ max_num_faces=max_num_faces,
30
+ refine_landmarks=True,
31
+ min_detection_confidence=min_detection_confidence,
32
+ ) as face_mesh:
33
  results = face_mesh.process(image)
34
 
35
  res = image[:, :, ::-1].copy()
 
41
  landmark_list=face_landmarks,
42
  connections=mp_face_mesh.FACEMESH_TESSELATION,
43
  landmark_drawing_spec=None,
44
+ connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_tesselation_style(),
45
+ )
46
  if show_contours:
47
  mp_drawing.draw_landmarks(
48
  image=res,
49
  landmark_list=face_landmarks,
50
  connections=mp_face_mesh.FACEMESH_CONTOURS,
51
  landmark_drawing_spec=None,
52
+ connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_contours_style(),
53
+ )
54
  if show_irises:
55
  mp_drawing.draw_landmarks(
56
  image=res,
57
  landmark_list=face_landmarks,
58
  connections=mp_face_mesh.FACEMESH_IRISES,
59
  landmark_drawing_spec=None,
60
+ connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_iris_connections_style(),
61
+ )
62
 
63
  return res[:, :, ::-1]
64
 
65
 
66
+ image_paths = sorted(pathlib.Path("images").rglob("*.jpg"))
67
  examples = [[path, 5, 0.5, True, True, True] for path in image_paths]
68
 
69
+ demo = gr.Interface(
70
  fn=run,
71
  inputs=[
72
+ gr.Image(label="Input", type="numpy"),
73
+ gr.Slider(label="Max Number of Faces", minimum=0, maximum=10, step=1, value=5),
74
+ gr.Slider(label="Minimum Detection Confidence", minimum=0, maximum=1, step=0.05, value=0.5),
75
+ gr.Checkbox(label="Show Tesselation", value=True),
76
+ gr.Checkbox(label="Show Contours", value=True),
77
+ gr.Checkbox(label="Show Irises", value=True),
 
 
 
 
 
 
 
 
78
  ],
79
+ outputs=gr.Image(label="Output"),
80
  examples=examples,
81
  title=TITLE,
82
  description=DESCRIPTION,
83
+ )
84
+
85
+ if __name__ == "__main__":
86
+ demo.queue().launch()
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- mediapipe==0.10.1
2
- numpy==1.23.5
3
- opencv-python-headless==4.8.0.74
 
1
+ mediapipe==0.10.14
2
+ numpy==1.26.4
3
+ opencv-python-headless==4.10.0.82