Spaces:
Running
Running
Update
Browse files- .pre-commit-config.yaml +59 -34
- .style.yapf +0 -5
- .vscode/settings.json +30 -0
- README.md +1 -1
- app.py +29 -25
- requirements.txt +1 -1
- style.css +8 -0
.pre-commit-config.yaml
CHANGED
@@ -1,35 +1,60 @@
|
|
1 |
repos:
|
2 |
-
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
- repo: https://github.com/pre-commit/mirrors-mypy
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
repos:
|
2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
+
rev: v4.5.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.8.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.2.0
|
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.7.1
|
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: green
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: green
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.19.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -13,24 +13,22 @@ import gradio as gr
|
|
13 |
import huggingface_hub
|
14 |
import numpy as np
|
15 |
|
16 |
-
DESCRIPTION =
|
17 |
|
18 |
|
19 |
def load_sample_image_paths() -> list[pathlib.Path]:
|
20 |
-
image_dir = pathlib.Path(
|
21 |
if not image_dir.exists():
|
22 |
-
dataset_repo =
|
23 |
-
path = huggingface_hub.hf_hub_download(dataset_repo,
|
24 |
-
'images.tar.gz',
|
25 |
-
repo_type='dataset')
|
26 |
with tarfile.open(path) as f:
|
27 |
f.extractall()
|
28 |
-
return sorted(image_dir.glob(
|
29 |
|
30 |
|
31 |
def load_model() -> cv2.CascadeClassifier:
|
32 |
-
url =
|
33 |
-
path = pathlib.Path(
|
34 |
if not path.exists():
|
35 |
urllib.request.urlretrieve(url, path.as_posix())
|
36 |
return cv2.CascadeClassifier(path.as_posix())
|
@@ -39,10 +37,7 @@ def load_model() -> cv2.CascadeClassifier:
|
|
39 |
def detect(image_path: str, detector: cv2.CascadeClassifier) -> np.ndarray:
|
40 |
image = cv2.imread(image_path)
|
41 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
42 |
-
preds = detector.detectMultiScale(gray,
|
43 |
-
scaleFactor=1.1,
|
44 |
-
minNeighbors=5,
|
45 |
-
minSize=(24, 24))
|
46 |
|
47 |
res = image.copy()
|
48 |
for x, y, w, h in preds:
|
@@ -56,19 +51,28 @@ examples = [[path.as_posix()] for path in image_paths]
|
|
56 |
detector = load_model()
|
57 |
fn = functools.partial(detect, detector=detector)
|
58 |
|
59 |
-
with gr.Blocks(css=
|
60 |
gr.Markdown(DESCRIPTION)
|
61 |
with gr.Row():
|
62 |
with gr.Column():
|
63 |
-
image = gr.Image(label=
|
64 |
-
run_button = gr.Button(
|
65 |
with gr.Column():
|
66 |
-
result = gr.Image(label=
|
67 |
-
|
68 |
-
gr.Examples(
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
import huggingface_hub
|
14 |
import numpy as np
|
15 |
|
16 |
+
DESCRIPTION = "# [nagadomi/lbpcascade_animeface](https://github.com/nagadomi/lbpcascade_animeface)"
|
17 |
|
18 |
|
19 |
def load_sample_image_paths() -> list[pathlib.Path]:
|
20 |
+
image_dir = pathlib.Path("images")
|
21 |
if not image_dir.exists():
|
22 |
+
dataset_repo = "hysts/sample-images-TADNE"
|
23 |
+
path = huggingface_hub.hf_hub_download(dataset_repo, "images.tar.gz", repo_type="dataset")
|
|
|
|
|
24 |
with tarfile.open(path) as f:
|
25 |
f.extractall()
|
26 |
+
return sorted(image_dir.glob("*"))
|
27 |
|
28 |
|
29 |
def load_model() -> cv2.CascadeClassifier:
|
30 |
+
url = "https://raw.githubusercontent.com/nagadomi/lbpcascade_animeface/master/lbpcascade_animeface.xml"
|
31 |
+
path = pathlib.Path("lbpcascade_animeface.xml")
|
32 |
if not path.exists():
|
33 |
urllib.request.urlretrieve(url, path.as_posix())
|
34 |
return cv2.CascadeClassifier(path.as_posix())
|
|
|
37 |
def detect(image_path: str, detector: cv2.CascadeClassifier) -> np.ndarray:
|
38 |
image = cv2.imread(image_path)
|
39 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
40 |
+
preds = detector.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(24, 24))
|
|
|
|
|
|
|
41 |
|
42 |
res = image.copy()
|
43 |
for x, y, w, h in preds:
|
|
|
51 |
detector = load_model()
|
52 |
fn = functools.partial(detect, detector=detector)
|
53 |
|
54 |
+
with gr.Blocks(css="style.css") as demo:
|
55 |
gr.Markdown(DESCRIPTION)
|
56 |
with gr.Row():
|
57 |
with gr.Column():
|
58 |
+
image = gr.Image(label="Input", type="filepath")
|
59 |
+
run_button = gr.Button()
|
60 |
with gr.Column():
|
61 |
+
result = gr.Image(label="Result")
|
62 |
+
|
63 |
+
gr.Examples(
|
64 |
+
examples=examples,
|
65 |
+
inputs=image,
|
66 |
+
outputs=result,
|
67 |
+
fn=fn,
|
68 |
+
cache_examples=os.getenv("CACHE_EXAMPLES") == "1",
|
69 |
+
)
|
70 |
+
run_button.click(
|
71 |
+
fn=fn,
|
72 |
+
inputs=image,
|
73 |
+
outputs=result,
|
74 |
+
api_name="predict",
|
75 |
+
)
|
76 |
+
|
77 |
+
if __name__ == "__main__":
|
78 |
+
demo.queue(max_size=15).launch()
|
requirements.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
opencv-python-headless
|
|
|
1 |
+
opencv-python-headless==4.9.0.80
|
style.css
CHANGED
@@ -1,3 +1,11 @@
|
|
1 |
h1 {
|
2 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
}
|
|
|
1 |
h1 {
|
2 |
text-align: center;
|
3 |
+
display: block;
|
4 |
+
}
|
5 |
+
|
6 |
+
#duplicate-button {
|
7 |
+
margin: auto;
|
8 |
+
color: #fff;
|
9 |
+
background: #1565c0;
|
10 |
+
border-radius: 100vh;
|
11 |
}
|