diff --git a/.kokoro/cloudairway.py b/.kokoro/cloudairway.py new file mode 100644 index 0000000000..56b7a0f431 --- /dev/null +++ b/.kokoro/cloudairway.py @@ -0,0 +1,45 @@ +from flask import Flask, request, jsonify +from google.cloud import aiplatform + +app = Flask(__name__) + +# ✅ Replace these with your actual values (already given) +PROJECT_ID = "569713108976" +REGION = "us-central1" +ENDPOINT_ID = "1010876696926093312" + +# Initialize AI Platform client +client = aiplatform.gapic.PredictionServiceClient() +endpoint = f"projects/{PROJECT_ID}/locations/{REGION}/endpoints/{ENDPOINT_ID}" + +@app.route("/predict", methods=["POST"]) +def predict(): + """ + Expects JSON payload like: + { + "instances": [ + { + "hr_bpm": 80, + "spo2_pct": 95, + "bp_sys_mean": 120, + "bp_dia_mean": 80, + "rr_mean": 16, + "temp_mean": 36.8 + } + ] + } + """ + try: + input_data = request.json.get("instances", []) + if not input_data: + return jsonify({"error": "No instances provided"}), 400 + + response = client.predict(endpoint=endpoint, instances=input_data) + return jsonify({"predictions": response.predictions}) + except Exception as e: + return jsonify({"error": str(e)}), 500 + +if __name__ == "__main__": + import os + port = int(os.environ.get("PORT", 8080)) # Cloud Run requires this + app.run(host="0.0.0.0", port=port) diff --git a/.kokoro/cloudprj.py b/.kokoro/cloudprj.py new file mode 100644 index 0000000000..711ad5bc77 --- /dev/null +++ b/.kokoro/cloudprj.py @@ -0,0 +1,31 @@ +from flask import Flask, request, jsonify +from google.cloud import aiplatform + +app = Flask(__name__) + +PROJECT_ID = "569713108976" +REGION = "us-central1" +ENDPOINT_ID = "1010876696926093312" + +client = aiplatform.gapic.PredictionServiceClient() +endpoint = f"projects/{PROJECT_ID}/locations/{REGION}/endpoints/{ENDPOINT_ID}" + +@app.route("/") +def home(): + return "Airway prediction API is running!" + +@app.route("/predict", methods=["POST"]) +def predict(): + try: + input_data = request.json.get("instances", []) + if not input_data: + return jsonify({"error": "No instances provided"}), 400 + response = client.predict(endpoint=endpoint, instances=input_data) + return jsonify({"predictions": response.predictions}) + except Exception as e: + return jsonify({"error": str(e)}), 500 + +if __name__ == "__main__": + import os + port = int(os.environ.get("PORT", 8080)) + app.run(host="0.0.0.0", port=port) diff --git a/.kokoro/requirments.txt b/.kokoro/requirments.txt new file mode 100644 index 0000000000..764492350d --- /dev/null +++ b/.kokoro/requirments.txt @@ -0,0 +1,2 @@ +Flask +google-cloud-aiplatform diff --git a/req.py b/req.py new file mode 100644 index 0000000000..10ac6537c7 --- /dev/null +++ b/req.py @@ -0,0 +1,3 @@ +my-repo/ + ├── main.py + ├── requirements.txt