singhina commited on
Commit
09df773
·
1 Parent(s): fd746ba

Deploy Flask backend to ExtraaLeanBackend

Browse files
Files changed (5) hide show
  1. Dockerfile +7 -0
  2. app.py +25 -0
  3. best_model.pkl +3 -0
  4. huggingface.yml +2 -0
  5. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+ WORKDIR /app
3
+ COPY requirements.txt .
4
+ RUN pip install --no-cache-dir -r requirements.txt
5
+ COPY app.py best_model.pkl .
6
+ EXPOSE 7860
7
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import joblib, pandas as pd, os
3
+
4
+ app = Flask(__name__)
5
+ # Load the serialized preprocessing+model pipeline
6
+ model = joblib.load("best_model.pkl")
7
+
8
+ @app.route("/predict", methods=["POST"])
9
+ def predict():
10
+ # Expect JSON body with feature keys matching training data
11
+ data = request.get_json()
12
+ df = pd.DataFrame([data])
13
+ # Predict class and probability
14
+ pred = int(model.predict(df)[0])
15
+ prob = float(model.predict_proba(df)[0, 1])
16
+ return jsonify({"prediction": pred, "probability": prob})
17
+
18
+ @app.route("/health", methods=["GET"])
19
+ def health():
20
+ return jsonify({"status": "ok"})
21
+
22
+ if __name__ == "__main__":
23
+ # Use PORT env var if provided, otherwise default to 7860
24
+ port = int(os.environ.get("PORT", 7860))
25
+ app.run(host="0.0.0.0", port=port)
best_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:32695d2da09f00f6bb8bdc5e845aee2a82991205c7749a18144d249710604c95
3
+ size 5700267
huggingface.yml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ app_port: 7860
2
+ sdk: docker
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ flask
2
+ joblib
3
+ pandas
4
+ scikit-learn
5
+ numpy