-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
42 lines (34 loc) · 1.05 KB
/
Copy pathanalysis.py
File metadata and controls
42 lines (34 loc) · 1.05 KB
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
import config
import httplib
import urllib
import base64
import sys
import requests
# #### HTTP Headers + Encoding the URL
def vision(filepath):
file = open(filepath, 'rb').read()
files = {'file': file}
headers = {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': config.api_key
}
params = urllib.urlencode ({
## I will tweak these lolssss
'visualFeatures': 'Categories,Tags,Description',
'language': 'en'
})
# #### Image URL and API Call
#body = "{'url': 'http://data.whicdn.com/images/21298747/thumb.jpg'}"
body = file
try:
conn = httplib.HTTPSConnection('westus.api.cognitive.microsoft.com')
conn.request("POST", "/vision/v1.0/analyze?%s" % params, body, headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
return data
except Exception as e:
print("[Errno {0}] {1}".format(e.message, e.message))
# For DEMO purposes
# vision('demo.jpg')