Skip to content

Commit 29b7540

Browse files
committed
jrf
1 parent c3b3f89 commit 29b7540

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

predict.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# api/predict.py
2+
import joblib
3+
import os
4+
import json
5+
6+
model_path = os.path.join(os.path.dirname(__file__), '..', 'model', 'xgb_model3.pkl')
7+
model = joblib.load(model_path)
8+
9+
def handler(request):
10+
try:
11+
body = request.json()
12+
features = [
13+
body['age'],
14+
body['avg_glucose_level'],
15+
body['hypertension'],
16+
body['heart_disease'],
17+
body['bmi']
18+
]
19+
prediction = model.predict([features])
20+
return {
21+
"statusCode": 200,
22+
"body": json.dumps({"prediction": int(prediction[0])})
23+
}
24+
except Exception as e:
25+
return {
26+
"statusCode": 500,
27+
"body": json.dumps({"error": str(e)})
28+
}

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
joblib
2+
scikit-learn
3+
numpy

vercel.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"functions": {
3+
"api/**/*.py": {
4+
"runtime": "python3.9"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)