-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·82 lines (57 loc) · 1.95 KB
/
main.py
File metadata and controls
executable file
·82 lines (57 loc) · 1.95 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
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
78
79
80
81
82
import sys
import json
import os
from flask import Flask
from flask_restful import reqparse, abort, Api, Resource
from flask import request, jsonify
import base64
import yaml
import logging
from logging.config import dictConfig
from storage import Azure_Storage
import numpy as np
import uuid
app = Flask(__name__)
api = Api(app)
verbose = True
parser = reqparse.RequestParser()
azure_storage = Azure_Storage()
class SkinLesionAnalysis(Resource):
def post(self):
params = request.get_json(force=True)
#params = json.dumps(params)
img = base64.decodebytes(bytes(params['image'],"utf-8"))
#img = np.frombuffer(img,dtype=np.float32).tobytes()
task_id = str(uuid.uuid4())
task = {"task_id":task_id}
task_msg = json.dumps(task)
azure_storage.put_image(task_id,img)
azure_storage.put_task(task_msg)
ret = {}
ret["task_id"] = task_id
ret["status"] = "pending"
ret["result"] = "Not_Available"
resp = jsonify(ret)
resp.headers["Access-Control-Allow-Origin"] = "*"
resp.headers["dataType"] = "json"
return resp
def get(self):
parser.add_argument('task_id')
args = parser.parse_args()
task_id = args["task_id"]
ret = {}
results = azure_storage.get_classification_result(task_id)
if results is not None:
ret = {"task_id":task_id, "status":"completed", "result":results}
else:
ret = {"task_id":task_id, "status":"pending or wrong task_id", "result":"NA"}
resp = jsonify(ret)
resp.headers["Access-Control-Allow-Origin"] = "*"
resp.headers["dataType"] = "json"
return resp
##
## Actually setup the Api resource routing here
##
api.add_resource(SkinLesionAnalysis, '/SkinLesionAnalysis')
if __name__ == '__main__':
app.run(debug=True,host="0.0.0.0",port="6006",threaded=True,use_reloader=False)