-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (39 loc) · 1.53 KB
/
app.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
import os
from flask import Flask, request
from flask_pymongo import PyMongo
from dotenv.main import load_dotenv
# IMPORTING FROM MY FUNCTIONS
from components.model.model_predict import model_pred
from components.core.database import save_users_images, get_user_data, get_user_image_id, get_user_id
# MongoDB Details Are Saved In ENV File
load_dotenv('/components/utils/.env')
MONGO_DB_CREDENTIAL = os.getenv('MONGO_DB_CREDENTIAL')
app = Flask(__name__)
app.config['MONGO_URI'] = MONGO_DB_CREDENTIAL
mongo = PyMongo(app)
# SAVE THE USER INFORMATION TO MONGO_DB
@app.route('/', methods=['POST'])
def save_user_diabetic():
if request.method == 'GET':
return 'Send Your Post Request Here'
image = request.files['image']
user_name = request.values['user_name']
save_users_images(mongo, image, user_name)
id = get_user_id(mongo, user_name)
return 'User Registration Completed with Image Id {}'.format(id), 200
# GET THE USER INFORMATION FROM MONGO_DB
@app.route('/get_information', methods=['POST'])
def show_user_info():
user_name = request.values['user_name']
filename = get_user_data(mongo, user_name)
return mongo.send_file(filename)
@app.route('/predict', methods=['POST'])
def predict_info():
user_name = request.values['user_name']
filename = get_user_data(mongo, user_name)
images_byte = get_user_image_id(mongo, user_name)
res = model_pred(images_byte)
# print(res)
return 'The Stage Of Diabetic You Are At is {}'.format(res), 200
if __name__ == '__main__':
app.run(debug=True)