hysts HF Staff commited on
Commit
1664861
·
1 Parent(s): cf746ac
.pre-commit-config.yaml CHANGED
@@ -1,6 +1,6 @@
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
@@ -13,48 +13,21 @@ repos:
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"]
 
1
  repos:
2
  - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v6.0.0
4
  hooks:
5
  - id: check-executables-have-shebangs
6
  - id: check-json
 
13
  args: ["--fix=lf"]
14
  - id: requirements-txt-fixer
15
  - id: trailing-whitespace
16
+ - repo: https://github.com/astral-sh/ruff-pre-commit
17
+ rev: v0.12.12
18
  hooks:
19
+ - id: ruff-check
20
+ args: ["--fix"]
21
+ - id: ruff-format
 
 
 
 
22
  - repo: https://github.com/pre-commit/mirrors-mypy
23
+ rev: v1.17.1
24
  hooks:
25
  - id: mypy
26
  args: ["--ignore-missing-imports"]
27
  additional_dependencies:
28
  [
29
  "types-python-slugify",
 
 
30
  "types-pytz",
31
+ "types-PyYAML",
32
+ "types-requests",
33
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.10
.vscode/extensions.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "recommendations": [
3
+ "ms-python.python",
4
+ "charliermarsh.ruff",
5
+ "streetsidesoftware.code-spell-checker",
6
+ "tamasfe.even-better-toml"
7
+ ]
8
+ }
.vscode/settings.json CHANGED
@@ -2,29 +2,16 @@
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
  }
 
2
  "editor.formatOnSave": true,
3
  "files.insertFinalNewline": false,
4
  "[python]": {
5
+ "editor.defaultFormatter": "charliermarsh.ruff",
6
  "editor.formatOnType": true,
7
  "editor.codeActionsOnSave": {
8
+ "source.fixAll.ruff": "explicit",
9
  "source.organizeImports": "explicit"
10
  }
11
  },
12
  "[jupyter]": {
13
  "files.insertFinalNewline": false
14
  },
 
 
 
 
 
 
 
 
 
 
15
  "notebook.output.scrolling": true,
16
+ "notebook.formatOnSave.enabled": true
 
 
 
 
17
  }
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 📚
4
  colorFrom: purple
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 4.36.1
8
  app_file: app.py
9
  pinned: false
10
  short_description: head pose estimation
 
4
  colorFrom: purple
5
  colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 5.44.1
8
  app_file: app.py
9
  pinned: false
10
  short_description: head pose estimation
app.py CHANGED
@@ -1,9 +1,7 @@
1
  #!/usr/bin/env python
2
 
3
- from __future__ import annotations
4
-
5
  import sys
6
- from typing import Callable
7
 
8
  import cv2
9
  import gradio as gr
@@ -12,17 +10,17 @@ import numpy as np
12
  import PIL.Image
13
  import spaces
14
  import torch
15
- import torch.nn as nn
16
- import torch.nn.functional as F
17
  import torchvision
18
- import torchvision.transforms as T
19
  from scipy.spatial.transform import Rotation
 
20
 
21
  sys.path.insert(0, "face_detection")
22
  sys.path.insert(0, "deep-head-pose/code")
23
 
24
- from hopenet import Hopenet
25
- from ibug.face_detection import RetinaFacePredictor
26
 
27
  DESCRIPTION = "# [Hopenet](https://github.com/natanielruiz/deep-head-pose)"
28
 
@@ -38,7 +36,7 @@ def load_model(model_name: str, device: torch.device) -> nn.Module:
38
 
39
 
40
  def create_transform() -> Callable:
41
- transform = T.Compose(
42
  [
43
  T.Resize(224),
44
  T.CenterCrop(224),
@@ -46,7 +44,6 @@ def create_transform() -> Callable:
46
  T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
47
  ]
48
  )
49
- return transform
50
 
51
 
52
  def crop_face(image: np.ndarray, box: tuple[int, int, int, int]) -> np.ndarray:
@@ -61,8 +58,7 @@ def crop_face(image: np.ndarray, box: tuple[int, int, int, int]) -> np.ndarray:
61
  y0 = max(y0, 0)
62
  x1 = min(x1, image.shape[1])
63
  y1 = min(y1, image.shape[0])
64
- image = image[y0:y1, x0:x1]
65
- return image
66
 
67
 
68
  def draw_axis(image: np.ndarray, pose: np.ndarray, origin: np.ndarray, length: int) -> None:
@@ -134,13 +130,13 @@ def run(
134
 
135
  examples = [["images/pexels-ksenia-chernaya-8535230.jpg", "hopenet_alpha1"]]
136
 
137
- with gr.Blocks(css="style.css") as demo:
138
  gr.Markdown(DESCRIPTION)
139
  with gr.Row():
140
  with gr.Column():
141
  image = gr.Image(label="Input", type="numpy")
142
  model_name = gr.Radio(label="Model", choices=model_names, type="value", value=model_names[0])
143
- run_button = gr.Button("Run")
144
  with gr.Column():
145
  result = gr.Image(label="Output")
146
  gr.Examples(
@@ -153,8 +149,7 @@ with gr.Blocks(css="style.css") as demo:
153
  fn=run,
154
  inputs=[image, model_name],
155
  outputs=result,
156
- api_name="run",
157
  )
158
 
159
  if __name__ == "__main__":
160
- demo.queue().launch()
 
1
  #!/usr/bin/env python
2
 
 
 
3
  import sys
4
+ from collections.abc import Callable
5
 
6
  import cv2
7
  import gradio as gr
 
10
  import PIL.Image
11
  import spaces
12
  import torch
13
+ import torch.nn.functional as F # noqa: N812
 
14
  import torchvision
15
+ import torchvision.transforms as T # noqa: N812
16
  from scipy.spatial.transform import Rotation
17
+ from torch import nn
18
 
19
  sys.path.insert(0, "face_detection")
20
  sys.path.insert(0, "deep-head-pose/code")
21
 
22
+ from hopenet import Hopenet # pyright: ignore[reportMissingImports]
23
+ from ibug.face_detection import RetinaFacePredictor # pyright: ignore[reportMissingImports]
24
 
25
  DESCRIPTION = "# [Hopenet](https://github.com/natanielruiz/deep-head-pose)"
26
 
 
36
 
37
 
38
  def create_transform() -> Callable:
39
+ return T.Compose(
40
  [
41
  T.Resize(224),
42
  T.CenterCrop(224),
 
44
  T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
45
  ]
46
  )
 
47
 
48
 
49
  def crop_face(image: np.ndarray, box: tuple[int, int, int, int]) -> np.ndarray:
 
58
  y0 = max(y0, 0)
59
  x1 = min(x1, image.shape[1])
60
  y1 = min(y1, image.shape[0])
61
+ return image[y0:y1, x0:x1]
 
62
 
63
 
64
  def draw_axis(image: np.ndarray, pose: np.ndarray, origin: np.ndarray, length: int) -> None:
 
130
 
131
  examples = [["images/pexels-ksenia-chernaya-8535230.jpg", "hopenet_alpha1"]]
132
 
133
+ with gr.Blocks(css_paths="style.css") as demo:
134
  gr.Markdown(DESCRIPTION)
135
  with gr.Row():
136
  with gr.Column():
137
  image = gr.Image(label="Input", type="numpy")
138
  model_name = gr.Radio(label="Model", choices=model_names, type="value", value=model_names[0])
139
+ run_button = gr.Button()
140
  with gr.Column():
141
  result = gr.Image(label="Output")
142
  gr.Examples(
 
149
  fn=run,
150
  inputs=[image, model_name],
151
  outputs=result,
 
152
  )
153
 
154
  if __name__ == "__main__":
155
+ demo.launch()
pyproject.toml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "hopenet"
3
+ version = "0.1.0"
4
+ description = ""
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "gradio>=5.44.1",
9
+ "hf-transfer>=0.1.9",
10
+ "opencv-python-headless>=4.12.0.88",
11
+ "scipy>=1.15.3",
12
+ "spaces>=0.40.1",
13
+ "torch==2.8.0",
14
+ "torchvision>=0.23.0",
15
+ ]
16
+
17
+ [tool.ruff]
18
+ line-length = 119
19
+
20
+ [tool.ruff.lint]
21
+ select = ["ALL"]
22
+ ignore = [
23
+ "COM812", # missing-trailing-comma
24
+ "D203", # one-blank-line-before-class
25
+ "D213", # multi-line-summary-second-line
26
+ "E501", # line-too-long
27
+ "SIM117", # multiple-with-statements
28
+ #
29
+ "D100", # undocumented-public-module
30
+ "D101", # undocumented-public-class
31
+ "D102", # undocumented-public-method
32
+ "D103", # undocumented-public-function
33
+ "D104", # undocumented-public-package
34
+ "D105", # undocumented-magic-method
35
+ "D107", # undocumented-public-init
36
+ "EM101", # raw-string-in-exception
37
+ "FBT001", # boolean-type-hint-positional-argument
38
+ "FBT002", # boolean-default-value-positional-argument
39
+ "PD901", # pandas-df-variable-name
40
+ "PGH003", # blanket-type-ignore
41
+ "PLR0913", # too-many-arguments
42
+ "PLR0915", # too-many-statements
43
+ "TRY003", # raise-vanilla-args
44
+ ]
45
+ unfixable = [
46
+ "F401", # unused-import
47
+ ]
48
+
49
+ [tool.ruff.lint.pydocstyle]
50
+ convention = "google"
51
+
52
+ [tool.ruff.lint.per-file-ignores]
53
+ "*.ipynb" = ["T201", "T203"]
54
+
55
+ [tool.ruff.format]
56
+ docstring-code-format = true
requirements.txt CHANGED
@@ -1,7 +1,241 @@
1
- gradio==4.36.1
2
- numpy==1.26.4
3
- opencv-python-headless==4.10.0.82
4
- Pillow==10.3.0
5
- scipy==1.13.1
6
- torch==2.0.1
7
- torchvision==0.15.2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml -o requirements.txt
3
+ aiofiles==24.1.0
4
+ # via gradio
5
+ annotated-types==0.7.0
6
+ # via pydantic
7
+ anyio==4.10.0
8
+ # via
9
+ # gradio
10
+ # httpx
11
+ # starlette
12
+ brotli==1.1.0
13
+ # via gradio
14
+ certifi==2025.8.3
15
+ # via
16
+ # httpcore
17
+ # httpx
18
+ # requests
19
+ charset-normalizer==3.4.3
20
+ # via requests
21
+ click==8.2.1
22
+ # via
23
+ # typer
24
+ # uvicorn
25
+ exceptiongroup==1.3.0
26
+ # via anyio
27
+ fastapi==0.116.1
28
+ # via gradio
29
+ ffmpy==0.6.1
30
+ # via gradio
31
+ filelock==3.19.1
32
+ # via
33
+ # huggingface-hub
34
+ # torch
35
+ fsspec==2025.9.0
36
+ # via
37
+ # gradio-client
38
+ # huggingface-hub
39
+ # torch
40
+ gradio==5.44.1
41
+ # via
42
+ # hopenet (pyproject.toml)
43
+ # spaces
44
+ gradio-client==1.12.1
45
+ # via gradio
46
+ groovy==0.1.2
47
+ # via gradio
48
+ h11==0.16.0
49
+ # via
50
+ # httpcore
51
+ # uvicorn
52
+ hf-transfer==0.1.9
53
+ # via hopenet (pyproject.toml)
54
+ hf-xet==1.1.9
55
+ # via huggingface-hub
56
+ httpcore==1.0.9
57
+ # via httpx
58
+ httpx==0.28.1
59
+ # via
60
+ # gradio
61
+ # gradio-client
62
+ # safehttpx
63
+ # spaces
64
+ huggingface-hub==0.34.4
65
+ # via
66
+ # gradio
67
+ # gradio-client
68
+ idna==3.10
69
+ # via
70
+ # anyio
71
+ # httpx
72
+ # requests
73
+ jinja2==3.1.6
74
+ # via
75
+ # gradio
76
+ # torch
77
+ markdown-it-py==4.0.0
78
+ # via rich
79
+ markupsafe==3.0.2
80
+ # via
81
+ # gradio
82
+ # jinja2
83
+ mdurl==0.1.2
84
+ # via markdown-it-py
85
+ mpmath==1.3.0
86
+ # via sympy
87
+ networkx==3.4.2
88
+ # via torch
89
+ numpy==2.2.6
90
+ # via
91
+ # gradio
92
+ # opencv-python-headless
93
+ # pandas
94
+ # scipy
95
+ # torchvision
96
+ nvidia-cublas-cu12==12.8.4.1
97
+ # via
98
+ # nvidia-cudnn-cu12
99
+ # nvidia-cusolver-cu12
100
+ # torch
101
+ nvidia-cuda-cupti-cu12==12.8.90
102
+ # via torch
103
+ nvidia-cuda-nvrtc-cu12==12.8.93
104
+ # via torch
105
+ nvidia-cuda-runtime-cu12==12.8.90
106
+ # via torch
107
+ nvidia-cudnn-cu12==9.10.2.21
108
+ # via torch
109
+ nvidia-cufft-cu12==11.3.3.83
110
+ # via torch
111
+ nvidia-cufile-cu12==1.13.1.3
112
+ # via torch
113
+ nvidia-curand-cu12==10.3.9.90
114
+ # via torch
115
+ nvidia-cusolver-cu12==11.7.3.90
116
+ # via torch
117
+ nvidia-cusparse-cu12==12.5.8.93
118
+ # via
119
+ # nvidia-cusolver-cu12
120
+ # torch
121
+ nvidia-cusparselt-cu12==0.7.1
122
+ # via torch
123
+ nvidia-nccl-cu12==2.27.3
124
+ # via torch
125
+ nvidia-nvjitlink-cu12==12.8.93
126
+ # via
127
+ # nvidia-cufft-cu12
128
+ # nvidia-cusolver-cu12
129
+ # nvidia-cusparse-cu12
130
+ # torch
131
+ nvidia-nvtx-cu12==12.8.90
132
+ # via torch
133
+ opencv-python-headless==4.12.0.88
134
+ # via hopenet (pyproject.toml)
135
+ orjson==3.11.3
136
+ # via gradio
137
+ packaging==25.0
138
+ # via
139
+ # gradio
140
+ # gradio-client
141
+ # huggingface-hub
142
+ # spaces
143
+ pandas==2.3.2
144
+ # via gradio
145
+ pillow==10.3.0
146
+ # via
147
+ # gradio
148
+ # torchvision
149
+ psutil==5.9.8
150
+ # via spaces
151
+ pydantic==2.11.7
152
+ # via
153
+ # fastapi
154
+ # gradio
155
+ # spaces
156
+ pydantic-core==2.33.2
157
+ # via pydantic
158
+ pydub==0.25.1
159
+ # via gradio
160
+ pygments==2.19.2
161
+ # via rich
162
+ python-dateutil==2.9.0.post0
163
+ # via pandas
164
+ python-multipart==0.0.20
165
+ # via gradio
166
+ pytz==2025.2
167
+ # via pandas
168
+ pyyaml==6.0.2
169
+ # via
170
+ # gradio
171
+ # huggingface-hub
172
+ requests==2.32.5
173
+ # via
174
+ # huggingface-hub
175
+ # spaces
176
+ rich==14.1.0
177
+ # via typer
178
+ ruff==0.12.12
179
+ # via gradio
180
+ safehttpx==0.1.6
181
+ # via gradio
182
+ scipy==1.15.3
183
+ # via hopenet (pyproject.toml)
184
+ semantic-version==2.10.0
185
+ # via gradio
186
+ setuptools==80.9.0
187
+ # via triton
188
+ shellingham==1.5.4
189
+ # via typer
190
+ six==1.17.0
191
+ # via python-dateutil
192
+ sniffio==1.3.1
193
+ # via anyio
194
+ spaces==0.40.1
195
+ # via hopenet (pyproject.toml)
196
+ starlette==0.47.3
197
+ # via
198
+ # fastapi
199
+ # gradio
200
+ sympy==1.14.0
201
+ # via torch
202
+ tomlkit==0.13.3
203
+ # via gradio
204
+ torch==2.8.0
205
+ # via
206
+ # hopenet (pyproject.toml)
207
+ # torchvision
208
+ torchvision==0.23.0
209
+ # via hopenet (pyproject.toml)
210
+ tqdm==4.67.1
211
+ # via huggingface-hub
212
+ triton==3.4.0
213
+ # via torch
214
+ typer==0.17.3
215
+ # via gradio
216
+ typing-extensions==4.15.0
217
+ # via
218
+ # anyio
219
+ # exceptiongroup
220
+ # fastapi
221
+ # gradio
222
+ # gradio-client
223
+ # huggingface-hub
224
+ # pydantic
225
+ # pydantic-core
226
+ # spaces
227
+ # starlette
228
+ # torch
229
+ # typer
230
+ # typing-inspection
231
+ # uvicorn
232
+ typing-inspection==0.4.1
233
+ # via pydantic
234
+ tzdata==2025.2
235
+ # via pandas
236
+ urllib3==2.5.0
237
+ # via requests
238
+ uvicorn==0.35.0
239
+ # via gradio
240
+ websockets==15.0.1
241
+ # via gradio-client
uv.lock ADDED
The diff for this file is too large to render. See raw diff