Skip to content

Commit eda7d56

Browse files
committed
Black format
1 parent 21c1c9a commit eda7d56

File tree

4 files changed

+132
-18
lines changed

4 files changed

+132
-18
lines changed

.gitignore

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,118 @@ deepstack_python.egg-info*
2020
# should NOT be excluded as they contain compiler settings and other important
2121
# information for Eclipse / Flash Builder.
2222

23+
# Byte-compiled / optimized / DLL files
24+
__pycache__/
25+
*.py[cod]
26+
*$py.class
27+
28+
# C extensions
29+
*.so
30+
31+
# Distribution / packaging
32+
.Python
33+
build/
34+
develop-eggs/
35+
dist/
36+
downloads/
37+
eggs/
38+
.eggs/
39+
lib/
40+
lib64/
41+
parts/
42+
sdist/
43+
var/
44+
wheels/
45+
share/python-wheels/
46+
*.egg-info/
47+
.installed.cfg
48+
*.egg
49+
MANIFEST
50+
51+
# PyInstaller
52+
# Usually these files are written by a python script from a template
53+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
54+
*.manifest
55+
*.spec
56+
57+
# Installer logs
58+
pip-log.txt
59+
pip-delete-this-directory.txt
60+
61+
# Unit test / coverage reports
62+
htmlcov/
63+
.tox/
64+
.nox/
65+
.coverage
66+
.coverage.*
67+
.cache
68+
nosetests.xml
69+
coverage.xml
70+
*.cover
71+
.hypothesis/
72+
.pytest_cache/
73+
74+
# Translations
75+
*.mo
76+
*.pot
77+
78+
# Django stuff:
79+
*.log
80+
local_settings.py
81+
db.sqlite3
82+
83+
# Flask stuff:
84+
instance/
85+
.webassets-cache
86+
87+
# Scrapy stuff:
88+
.scrapy
89+
90+
# Sphinx documentation
91+
docs/_build/
92+
93+
# PyBuilder
94+
target/
95+
96+
# Jupyter Notebook
97+
.ipynb_checkpoints
98+
99+
# IPython
100+
profile_default/
101+
ipython_config.py
102+
103+
# pyenv
104+
.python-version
105+
106+
# celery beat schedule file
107+
celerybeat-schedule
108+
109+
# SageMath parsed files
110+
*.sage.py
111+
112+
# Environments
113+
.env
114+
.venv
115+
env/
116+
venv/
117+
ENV/
118+
env.bak/
119+
venv.bak/
120+
121+
# Spyder project settings
122+
.spyderproject
123+
.spyproject
124+
125+
# Rope project settings
126+
.ropeproject
127+
128+
# mkdocs documentation
129+
/site
130+
131+
# mypy
132+
.mypy_cache/
133+
.dmypy.json
134+
dmypy.json
135+
136+
# Pyre type checker
137+
.pyre/
-6 Bytes
Binary file not shown.

deepstack/core.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from PIL import Image
77

88
## Const
9-
CLASSIFIER = 'deepstack'
9+
CLASSIFIER = "deepstack"
1010
HTTP_OK = 200
1111
HTTP_BAD_REQUEST = 400
1212
HTTP_UNAUTHORIZED = 401
@@ -18,8 +18,11 @@ def get_matched_faces(predictions: dict):
1818
Get the predicted faces and their confidence.
1919
"""
2020
try:
21-
matched_faces = {face['userid']: round(face['confidence']*100, 1)
22-
for face in predictions if not face['userid'] == 'unknown'}
21+
matched_faces = {
22+
face["userid"]: round(face["confidence"] * 100, 1)
23+
for face in predictions
24+
if not face["userid"] == "unknown"
25+
}
2326
return matched_faces
2427
except:
2528
return {}
@@ -34,7 +37,7 @@ def is_valid_image(file_path: str):
3437
pass
3538

3639
image_extension = imghdr.what(file_path)
37-
if image_extension in ['jpeg', '.jpg', '.png']:
40+
if image_extension in ["jpeg", ".jpg", ".png"]:
3841
return True
3942
return False
4043
except Exception as exc:
@@ -45,11 +48,7 @@ def is_valid_image(file_path: str):
4548
def post_image(url: str, image: bytes):
4649
"""Post an image to the classifier."""
4750
try:
48-
response = requests.post(
49-
url,
50-
files={"image": image},
51-
timeout=TIMEOUT
52-
)
51+
response = requests.post(url, files={"image": image}, timeout=TIMEOUT)
5352
return response
5453
except requests.exceptions.ConnectionError:
5554
print("ConnectionError: Is %s running?", CLASSIFIER)
@@ -59,13 +58,14 @@ def post_image(url: str, image: bytes):
5958
return None
6059

6160

62-
class DeepstackFace():
61+
class DeepstackFace:
6362
"""Work with faces."""
6463

6564
def __init__(self, ip_address: str, port: str):
6665

6766
self._url_check = "http://{}:{}/v1/vision/face/recognize".format(
68-
ip_address, port)
67+
ip_address, port
68+
)
6969

7070
self._faces = None
7171
self._matched = {}
@@ -78,8 +78,7 @@ def process_file(self, file_path: str):
7878

7979
def process_image_bytes(self, image_bytes: bytes):
8080
"""Process an image."""
81-
response = post_image(
82-
self._url_check, image_bytes)
81+
response = post_image(self._url_check, image_bytes)
8382
if response:
8483
if response.status_code == HTTP_OK:
8584
predictions_json = response.json()["predictions"]
@@ -94,7 +93,7 @@ def process_image_bytes(self, image_bytes: bytes):
9493
def attributes(self):
9594
"""Return the classifier attributes."""
9695
return {
97-
'faces': self._faces,
98-
'matched_faces': self._matched,
99-
'total_matched_faces': len(self._matched),
96+
"faces": self._faces,
97+
"matched_faces": self._matched,
98+
"total_matched_faces": len(self._matched),
10099
}

usage.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"output_type": "stream",
4242
"text": [
4343
"{'faces': 2, 'matched_faces': {}, 'total_matched_faces': 0}\n",
44-
"CPU times: user 362 ms, sys: 47.5 ms, total: 409 ms\n",
45-
"Wall time: 12.8 s\n"
44+
"CPU times: user 367 ms, sys: 52.6 ms, total: 420 ms\n",
45+
"Wall time: 14.9 s\n"
4646
]
4747
},
4848
{

0 commit comments

Comments
 (0)