-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (41 loc) · 1.35 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
from flask import Flask, request, redirect
from flask_restful import Resource, Api
from flask_cors import CORS
import os
from predict import predict_breast_cancer
import pandas as pd
import json
app = Flask(__name__)
cors = CORS(app, resources={r"*": {"origins": "*"}})
api = Api(app)
class Test(Resource):
def get(self):
return 'Welcome to, Test App API!'
def post(self):
try:
value = request.get_json()
if (value):
return {'Post Values': value}, 201
return {"error": "Invalid format."}
except Exception as error:
return {'error': error}
class GetPredictionOutput(Resource):
def get(self):
return {"error": "Invalid Method."}
def post(self):
try:
data = request.get_json()
print(data)
# dict_data = json.loads(data)
# df = pd.DataFrame(dict_data.values(), columns=dict_data.keys())
# print(df)
predict = predict_breast_cancer(data)
predictOutput = predict
return json.dumps(predictOutput)
except Exception as error:
return {'error': error}
api.add_resource(Test, '/')
api.add_resource(GetPredictionOutput, '/predict')
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8000))
app.run(host='127.0.0.1', port=port)