-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure_com.py
More file actions
34 lines (26 loc) · 794 Bytes
/
azure_com.py
File metadata and controls
34 lines (26 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import stickerify
from credentials import CREDENTIALS
from errors import NoFace
AZURE_LINK = CREDENTIALS["AZURE_LINK"]
def get_image_info(url):
r = requests.post(AZURE_LINK + url)
return r.json()
def get_sticker_from_photo(url):
image_info = get_image_info(url)
if ('emotion' in image_info):
max_val = 0
for key, value in image_info['emotion'].items():
if max_val < value:
(max_val, emotion) = (value, key)
else:
emotion = "not_detected"
if ('faceRectangle' in image_info):
coords = image_info['faceRectangle']
else:
coords = None
image_path = stickerify.sticker_from_rectangle(coords, url)
return {
"path": image_path,
"emotion": emotion,
}