-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_tags.py
60 lines (52 loc) · 1.65 KB
/
generate_tags.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import httplib, urllib, base64
import os, requests, cv2, base64
from helper import processRequest
def generate_tags(photoUrl):
imageTags = processRequest(
'https://westus.api.cognitive.microsoft.com/vision/v1.0/describe',
{"url": photoUrl},
{},
{#Header
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '72608f3be7934eaeb9ea0ecf60e585da',
},
#Params
urllib.urlencode({
'maxCandidates': '1',
})
)
imageTags = imageTags['description']['tags']
stringToSearch = ""
numberOfTags = len(imageTags)/3
if (numberOfTags > 5):
numberOfTags = 5
for index in range(0, numberOfTags):
stringToSearch += imageTags[index] + " "
# stringToSearch += "text only quotes"
return stringToSearch
##Not needed because faceGenerate includes emotionGenerate
# def emotionGenerate():
# emotionList = processRequest(body, {},
# {#Header
# 'Content-Type': 'application/json',
# 'Ocp-Apim-Subscription-Key': '4aad93e39f894f4ba3ca5fb92bede45f',
# },
# #Params
# urllib.urlencode({
# 'faceRectangle': None,
# }),
# 'https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize')
# print (emotionList)
# def faceGenerate():
# faceList = processRequest(body, {},
# {#Header
# 'Content-Type': 'application/json',
# 'Ocp-Apim-Subscription-Key': 'c629a44202f148d7a4b8f4540c22d4cd',
# },
# #Params
# urllib.urlencode({
# }),
# 'https://westus.api.cognitive.microsoft.com/face/v1.0/detect')
# print (faceList)
if __name__ == "__main__":
print tagGenerate()