from flask import Flask, request, jsonify import tensorflow as tf import numpy as np import os app = Flask(__name__) # Load the model model_path = "sleep_cognition_model.h5" if not os.path.exists(model_path): raise FileNotFoundError(f"⚠️ Model file not found: {model_path}. Please check the path.") model = tf.keras.models.load_model(model_path) @app.route("/", methods=["GET"]) def home(): return jsonify({"message": "Sleep Cognition Model API is running!"}) @app.route("/predict", methods=["POST"]) def predict(): try: data = request.json["input"] data = np.array(data).reshape(1, -1) # Reshape input data if needed prediction = model.predict(data) return jsonify({"prediction": prediction.tolist()}) except Exception as e: return jsonify({"error": str(e)}), 400 if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True)