Diff of /api/app/routes.py [000000] .. [0241e6]

Switch to unified view

a b/api/app/routes.py
1
from flask import Blueprint, request, jsonify
2
import joblib
3
import os
4
5
from app.load_model import model
6
7
blueprint = Blueprint('blue_print', __name__)
8
9
# Prediction request
10
@blueprint.route('/predict', methods=['POST'])
11
def predict():
12
    # Get the new value
13
    gender = request.json.get('gender')
14
    age = request.json.get('age')
15
    smoking = request.json.get('smoking')
16
    yellow_skin = request.json.get('yellow_skin')
17
    fatigue = request.json.get('fatigue')
18
    wheezing = request.json.get('wheezing')
19
    coughing = request.json.get('coughing')
20
    shortness_of_breath = request.json.get('shortness_of_breath')
21
    swallowing_difficulty = request.json.get('swallowing_difficulty')
22
    chest_pain = request.json.get('chest_pain')
23
    chronic_disease = request.json.get('chronic_disease')
24
25
    # Value type request
26
    def convert_data(data):
27
        if isinstance(data, int):
28
           return int(data)
29
        
30
        elif isinstance(data, str):
31
           return str(data)
32
33
    # Input data for prediction
34
    data = [
35
            convert_data(gender), 
36
            convert_data(age), 
37
            convert_data(smoking), 
38
            convert_data(yellow_skin), 
39
            convert_data(fatigue), 
40
            convert_data(wheezing), 
41
            convert_data(coughing), 
42
            convert_data(shortness_of_breath), 
43
            convert_data(swallowing_difficulty), 
44
            convert_data(chest_pain), 
45
            convert_data(chronic_disease)
46
           ]
47
48
    pred = model.predict([data])[0] # Predict new data
49
    proba = model.predict_proba([data])[0][pred] # Get the prediction outcome
50
51
    return jsonify({'prediction': int(pred), 'proba': float(proba)}), 200