-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
77 lines (61 loc) · 2.46 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#from rapidconnect import RapidConnect
from os import path
from pprint import pprint
import json
app_dir = path.dirname(__file__)
image_dir = path.join(app_dir, 'images')
API_KEY = "########"
# rapidAPI Initialize
#rapid = RapidConnect('WasteZero', API_KEY)
# Opening text files and spliting them into words
with open('compost.txt', 'r+') as f:
compost = f.readlines()
compost = [x.lower() for x in compost]
compost = [x.strip() for x in compost]
with open('recyclables.txt', 'r+') as f:
recycable = f.readlines()
recycable = [x.lower() for x in recycable]
recycable = [x.strip() for x in recycable]
with open('landfill.txt', 'r+') as f:
landfill = f.readlines()
landfill = [x.lower() for x in landfill]
landfill = [x.strip() for x in landfill]
def sortImage(url):
tagImage = rapid.call('MicrosoftComputerVision', 'tagImage', {
'subscriptionKey':
API_KEY,
'image': url
})
describeImage = rapid.call('MicrosoftComputerVision', 'describeImage', {
'subscriptionKey':
API_KEY,
'image': url,
'maxCandidates': ''
})
tag = json.loads(tagImage)
describe = json.loads(describeImage)
pprint(tag['tags'])
pprint(describe['description']['captions'][0]['text'])
for i in range(len(tag['tags'])):
if tag['tags'][i]['name'] in compost:
print("ITEM: " + (tag['tags'][i]['name']).upper())
print("DESCRIPTION: " + describe['description']['captions'][0]
['text']
).upper()
return ("THIS ITEM GOES is ORGANIC")
break
elif tag['tags'][i]['name'] in recycable:
print("ITEM: " + (tag['tags'][i]['name']).upper())
print("DESCRIPTION: " + describe['description']['captions'][0]
['text']
).upper()
return ("THIS ITEM is Recycleable.")
break
elif tag['tags'][i]['name'] in landfill:
print("ITEM: " + (tag['tags'][i]['name']).upper())
print("DESCRIPTION: " + describe['description']['captions'][0]
['text']
).upper()
return print("THIS ITEM is PLASTIC")
break
print("THIS ITEM is PLASTIC")