hysts HF staff commited on
Commit
c6df2ea
·
1 Parent(s): 5cf0d37
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 +2 -2
  5. app.py +16 -24
  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,9 +4,9 @@ emoji: 📚
4
  colorFrom: yellow
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 3.36.1
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
4
  colorFrom: yellow
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 4.33.0
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
app.py CHANGED
@@ -2,26 +2,22 @@
2
 
3
  from __future__ import annotations
4
 
5
- import os
6
  import pathlib
7
 
8
  import gradio as gr
9
- import huggingface_hub
10
  import mediapipe as mp
11
  import numpy as np
12
 
13
  mp_face_detection = mp.solutions.face_detection
14
  mp_drawing = mp.solutions.drawing_utils
15
 
16
- TITLE = 'MediaPipe Face Detection'
17
- DESCRIPTION = 'https://google.github.io/mediapipe/'
18
 
19
 
20
- def run(image: np.ndarray, model_selection: int,
21
- min_detection_confidence: float) -> np.ndarray:
22
  with mp_face_detection.FaceDetection(
23
- model_selection=model_selection,
24
- min_detection_confidence=min_detection_confidence
25
  ) as face_detection:
26
  results = face_detection.process(image)
27
 
@@ -33,29 +29,25 @@ def run(image: np.ndarray, model_selection: int,
33
 
34
 
35
  model_types = [
36
- 'Short-range model (best for faces within 2 meters)',
37
- 'Full-range model (best for faces within 5 meters)',
38
  ]
39
 
40
- image_paths = sorted(pathlib.Path('images').rglob('*.jpg'))
41
  examples = [[path, model_types[0], 0.5] for path in image_paths]
42
 
43
- gr.Interface(
44
  fn=run,
45
  inputs=[
46
- gr.Image(label='Input', type='numpy'),
47
- gr.Radio(label='Model',
48
- choices=model_types,
49
- type='index',
50
- value=model_types[0]),
51
- gr.Slider(label='Minimum Detection Confidence',
52
- minimum=0,
53
- maximum=1,
54
- step=0.05,
55
- value=0.5),
56
  ],
57
- outputs=gr.Image(label='Output'),
58
  examples=examples,
59
  title=TITLE,
60
  description=DESCRIPTION,
61
- ).queue().launch()
 
 
 
 
2
 
3
  from __future__ import annotations
4
 
 
5
  import pathlib
6
 
7
  import gradio as gr
 
8
  import mediapipe as mp
9
  import numpy as np
10
 
11
  mp_face_detection = mp.solutions.face_detection
12
  mp_drawing = mp.solutions.drawing_utils
13
 
14
+ TITLE = "MediaPipe Face Detection"
15
+ DESCRIPTION = "https://google.github.io/mediapipe/"
16
 
17
 
18
+ def run(image: np.ndarray, model_selection: int, min_detection_confidence: float) -> np.ndarray:
 
19
  with mp_face_detection.FaceDetection(
20
+ model_selection=model_selection, min_detection_confidence=min_detection_confidence
 
21
  ) as face_detection:
22
  results = face_detection.process(image)
23
 
 
29
 
30
 
31
  model_types = [
32
+ "Short-range model (best for faces within 2 meters)",
33
+ "Full-range model (best for faces within 5 meters)",
34
  ]
35
 
36
+ image_paths = sorted(pathlib.Path("images").rglob("*.jpg"))
37
  examples = [[path, model_types[0], 0.5] for path in image_paths]
38
 
39
+ demo = gr.Interface(
40
  fn=run,
41
  inputs=[
42
+ gr.Image(label="Input", type="numpy"),
43
+ gr.Radio(label="Model", choices=model_types, type="index", value=model_types[0]),
44
+ gr.Slider(label="Minimum Detection Confidence", minimum=0, maximum=1, step=0.05, value=0.5),
 
 
 
 
 
 
 
45
  ],
46
+ outputs=gr.Image(label="Output"),
47
  examples=examples,
48
  title=TITLE,
49
  description=DESCRIPTION,
50
+ )
51
+
52
+ if __name__ == "__main__":
53
+ 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