-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (34 loc) · 1.12 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse, os
from ai import AiProcessor
from ai.model import MergeModel
from services.cloud_vision import CloudVisionService
from services.labels import LabelsService
import settings
def parse_args(parser: argparse.ArgumentParser):
# Input parameters
parser.add_argument('--img-path', type=str, required=True)
args = parser.parse_args()
return args
def nice_print(result, width=55, x="#"):
print(x*width)
print("{} AI OUTPUT".format(x), " "*(width-12), end='{}\n'.format(x))
print(x*width)
for feature, score in result.items():
txt = "# {}: {}".format(feature, score)
print(txt, " "*(width-len(txt)-1), end='{}\n'.format(x))
print(x*width)
def main():
# Dependencies
parser = argparse.ArgumentParser()
cv = CloudVisionService(settings.CV_KEY)
labels = LabelsService()
model = MergeModel(settings.MODEL_DIR)
ai = AiProcessor(model, cv, labels)
args = parse_args(parser)
# Run model
result = ai.process(args.img_path)
nice_print(result)
if __name__ == "__main__":
main()