hysts HF Staff commited on
Commit
2343867
·
1 Parent(s): 7c19286
Files changed (5) hide show
  1. .pre-commit-config.yaml +35 -0
  2. .style.yapf +5 -0
  3. README.md +1 -1
  4. app.py +15 -48
  5. images/README.md +0 -1
.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: pink
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 3.0.5
8
  app_file: app.py
9
  pinned: false
10
  ---
 
4
  colorFrom: pink
5
  colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 3.19.1
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py CHANGED
@@ -2,7 +2,6 @@
2
 
3
  from __future__ import annotations
4
 
5
- import argparse
6
  import functools
7
  import os
8
  import pathlib
@@ -19,23 +18,8 @@ import gradio as gr
19
  import numpy as np
20
  import torch
21
 
22
- TITLE = '1adrianb/face-alignment'
23
  DESCRIPTION = 'This is an unofficial demo for https://github.com/1adrianb/face-alignment.'
24
- ARTICLE = '<center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.1adrianb-face-alignment" alt="visitor badge"/></center>'
25
-
26
-
27
- def parse_args() -> argparse.Namespace:
28
- parser = argparse.ArgumentParser()
29
- parser.add_argument('--device', type=str, default='cpu')
30
- parser.add_argument('--theme', type=str)
31
- parser.add_argument('--live', action='store_true')
32
- parser.add_argument('--share', action='store_true')
33
- parser.add_argument('--port', type=int)
34
- parser.add_argument('--disable-queue',
35
- dest='enable_queue',
36
- action='store_false')
37
- parser.add_argument('--allow-flagging', type=str, default='never')
38
- return parser.parse_args()
39
 
40
 
41
  def detect(
@@ -58,36 +42,19 @@ def detect(
58
  return res
59
 
60
 
61
- def main():
62
- args = parse_args()
63
- device = torch.device(args.device)
64
-
65
- detector = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D,
66
- device=device.type)
67
-
68
- func = functools.partial(detect, detector=detector, device=device)
69
- func = functools.update_wrapper(func, detect)
70
-
71
- image_paths = sorted(pathlib.Path('images').glob('*.jpg'))
72
- examples = [[path.as_posix()] for path in image_paths]
73
-
74
- gr.Interface(
75
- func,
76
- gr.inputs.Image(type='numpy', label='Input'),
77
- gr.outputs.Image(type='numpy', label='Output'),
78
- examples=examples,
79
- title=TITLE,
80
- description=DESCRIPTION,
81
- article=ARTICLE,
82
- theme=args.theme,
83
- allow_flagging=args.allow_flagging,
84
- live=args.live,
85
- ).launch(
86
- enable_queue=args.enable_queue,
87
- server_port=args.port,
88
- share=args.share,
89
- )
90
 
 
 
91
 
92
- if __name__ == '__main__':
93
- main()
 
 
 
 
 
 
 
2
 
3
  from __future__ import annotations
4
 
 
5
  import functools
6
  import os
7
  import pathlib
 
18
  import numpy as np
19
  import torch
20
 
21
+ TITLE = 'face-alignment'
22
  DESCRIPTION = 'This is an unofficial demo for https://github.com/1adrianb/face-alignment.'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
 
25
  def detect(
 
42
  return res
43
 
44
 
45
+ device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
46
+ detector = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D,
47
+ device=device.type)
48
+ func = functools.partial(detect, detector=detector, device=device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ image_paths = sorted(pathlib.Path('images').glob('*.jpg'))
51
+ examples = [[path.as_posix()] for path in image_paths]
52
 
53
+ gr.Interface(
54
+ fn=func,
55
+ inputs=gr.Image(label='Input', type='numpy'),
56
+ outputs=gr.Image(label='Output', type='numpy'),
57
+ examples=examples,
58
+ title=TITLE,
59
+ description=DESCRIPTION,
60
+ ).launch(show_api=False)
images/README.md CHANGED
@@ -1,4 +1,3 @@
1
  These images are from the following public domain:
2
 
3
  - https://www.pexels.com/photo/children-with-her-students-holding-different-color-bells-8535230/
4
-
 
1
  These images are from the following public domain:
2
 
3
  - https://www.pexels.com/photo/children-with-her-students-holding-different-color-bells-8535230/