omaralaa2004 commited on
Commit
b31a381
·
verified ·
1 Parent(s): 163e647

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -56,19 +56,20 @@ init_db()
56
 
57
  @app.route('/')
58
  def home():
 
59
  return render_template('index.html')
60
 
61
  @app.route('/predict', methods=['POST'])
62
  def predict():
63
  global model
64
- print("Received predict request")
65
  if model is None:
66
  try:
67
  model = joblib.load('stroke_prediction_model.pkl')
68
- print("Model loaded successfully during first predict request.")
69
  except Exception as e:
70
  print(f"Error loading model: {str(e)}")
71
- return jsonify({'success': False, 'error': 'Model failed to load'}), 500
72
 
73
  try:
74
  data = request.json
@@ -158,7 +159,7 @@ def predict():
158
  print(f"Prediction success: probability={probability}%, prediction={risk_prediction}")
159
  return jsonify({
160
  'success': True,
161
- 'prediction': risk_prediction, # Simplified output
162
  'probability': round(probability),
163
  'contributingFactors': contributing_factors
164
  })
 
56
 
57
  @app.route('/')
58
  def home():
59
+ print("Serving home page")
60
  return render_template('index.html')
61
 
62
  @app.route('/predict', methods=['POST'])
63
  def predict():
64
  global model
65
+ print("Received predict request at /predict endpoint")
66
  if model is None:
67
  try:
68
  model = joblib.load('stroke_prediction_model.pkl')
69
+ print("Model loaded successfully during first predict request")
70
  except Exception as e:
71
  print(f"Error loading model: {str(e)}")
72
+ return jsonify({'success': False, 'error': f'Model failed to load: {str(e)}'}), 500
73
 
74
  try:
75
  data = request.json
 
159
  print(f"Prediction success: probability={probability}%, prediction={risk_prediction}")
160
  return jsonify({
161
  'success': True,
162
+ 'prediction': risk_prediction,
163
  'probability': round(probability),
164
  'contributingFactors': contributing_factors
165
  })