WissMah commited on
Commit
6d2df9a
·
verified ·
1 Parent(s): f5ef9ce

Update stroke-flask-docker/app.py

Browse files
Files changed (1) hide show
  1. stroke-flask-docker/app.py +4 -5
stroke-flask-docker/app.py CHANGED
@@ -2,6 +2,7 @@ from flask import Flask, render_template, request, jsonify
2
  import joblib
3
  import numpy as np
4
  import os
 
5
 
6
  APP_PORT = int(os.getenv("PORT", "8080"))
7
 
@@ -49,7 +50,6 @@ def index():
49
  "smoking_status": "never smoked",
50
  }
51
  return render_template("index.html", defaults=defaults)
52
-
53
  @app.route("/predict", methods=["POST"])
54
  def predict():
55
  try:
@@ -67,12 +67,11 @@ def predict():
67
 
68
  # ALWAYS send a DataFrame with named columns
69
  X = pd.DataFrame([{f: payload.get(f, None) for f in FEATURE_ORDER}])[FEATURE_ORDER]
70
-
71
  # quick sanity log (optional)
72
  # print("X type:", type(X), "cols:", list(X.columns))
73
 
74
- prob = float(pipeline.predict_proba(X)[0][1])
75
- pred = int(prob >= 0.5)
76
  result = {"stroke_probability": prob, "predicted_label": pred}
77
 
78
  return jsonify(result) if request.is_json else render_template("index.html", result=result, defaults=payload)
@@ -80,6 +79,6 @@ def predict():
80
  except Exception as e:
81
  return (jsonify({"error": str(e)}), 400) if request.is_json else \
82
  (render_template("index.html", error=str(e), defaults=payload), 400)
83
-
84
  if __name__ == "__main__":
85
  app.run(host="0.0.0.0", port=APP_PORT, debug=False)
 
2
  import joblib
3
  import numpy as np
4
  import os
5
+ import pandas as pd
6
 
7
  APP_PORT = int(os.getenv("PORT", "8080"))
8
 
 
50
  "smoking_status": "never smoked",
51
  }
52
  return render_template("index.html", defaults=defaults)
 
53
  @app.route("/predict", methods=["POST"])
54
  def predict():
55
  try:
 
67
 
68
  # ALWAYS send a DataFrame with named columns
69
  X = pd.DataFrame([{f: payload.get(f, None) for f in FEATURE_ORDER}])[FEATURE_ORDER]
70
+ prob = float(pipeline.predict_proba(X)[0][1])
71
  # quick sanity log (optional)
72
  # print("X type:", type(X), "cols:", list(X.columns))
73
 
74
+ pred = int(prob >= 0.3)
 
75
  result = {"stroke_probability": prob, "predicted_label": pred}
76
 
77
  return jsonify(result) if request.is_json else render_template("index.html", result=result, defaults=payload)
 
79
  except Exception as e:
80
  return (jsonify({"error": str(e)}), 400) if request.is_json else \
81
  (render_template("index.html", error=str(e), defaults=payload), 400)
82
+
83
  if __name__ == "__main__":
84
  app.run(host="0.0.0.0", port=APP_PORT, debug=False)