| import pickle |
| import numpy as np |
| from flask import Flask, request, jsonify |
|
|
| |
| MODEL_PATH = "/mnt/data/model.pkl" |
|
|
| app = Flask(__name__) |
|
|
| |
| with open(MODEL_PATH, 'rb') as file: |
| model = pickle.load(file) |
|
|
| @app.route('/predict', methods=['POST']) |
| def predict(): |
| try: |
| |
| input_data = request.get_json() |
| if not input_data: |
| return jsonify({"error": "Invalid input data"}), 400 |
| |
| |
| features = np.array(input_data['features']).reshape(1, -1) |
|
|
| |
| prediction = model.predict(features) |
| |
| |
| return jsonify({"prediction": prediction.tolist()}), 200 |
| except Exception as e: |
| return jsonify({"error": str(e)}), 500 |
|
|
| if __name__ == '__main__': |
| app.run(host='0.0.0.0', port=5000) |
|
|