a b/prediction_api/src/controller.py
1
from flask import Blueprint, request, jsonify
2
from src.prediction_system import get_prediction, healthcheck
3
import json
4
5
model_controller = Blueprint('controller', __name__)
6
7
@model_controller.route('/predict', methods=['POST'])
8
def prediction_endpoint():
9
    if not request.is_json:
10
        return jsonify({'error': 'Invalid JSON data'}), 400
11
12
    data = json.loads(request.data)
13
14
    if 'array'in data:
15
        response = get_prediction(data)
16
        return jsonify(response)
17
    else:
18
        return jsonify({'error': 'Invalid or missing "array" field'}), 400
19
20
21
@model_controller.route('/healthcheck', methods=['GET'])
22
def healthcheck_endpoint():
23
    return jsonify({'model': healthcheck()}), 400
24
    
25