vinsensius13 commited on
Commit
61bb578
·
1 Parent(s): c05b93c

komitkomit

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. app.py +15 -8
Dockerfile CHANGED
@@ -7,4 +7,4 @@ RUN pip install -r requirements.txt
7
 
8
  COPY . .
9
 
10
- CMD ["python", "app.py"]
 
7
 
8
  COPY . .
9
 
10
+ CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app"]
app.py CHANGED
@@ -1,10 +1,9 @@
1
  from flask import Flask, request, jsonify
2
- import pickle
3
 
4
  app = Flask(__name__)
5
 
6
  # Load model
7
- import joblib
8
  model = joblib.load("models/model.pkl")
9
 
10
  @app.route("/")
@@ -13,10 +12,18 @@ def index():
13
 
14
  @app.route("/predict", methods=["POST"])
15
  def predict():
16
- data = request.get_json()
17
- features = [data["sepal_length"], data["sepal_width"], data["petal_length"], data["petal_width"]]
18
- prediction = model.predict([features])
19
- return jsonify({"prediction": prediction[0]})
 
 
 
 
 
 
 
 
20
 
21
- if __name__ == "__main__":
22
- app.run(host="0.0.0.0", port=7860)
 
1
  from flask import Flask, request, jsonify
2
+ import joblib
3
 
4
  app = Flask(__name__)
5
 
6
  # Load model
 
7
  model = joblib.load("models/model.pkl")
8
 
9
  @app.route("/")
 
12
 
13
  @app.route("/predict", methods=["POST"])
14
  def predict():
15
+ try:
16
+ data = request.get_json()
17
+ features = [
18
+ float(data["sepal_length"]),
19
+ float(data["sepal_width"]),
20
+ float(data["petal_length"]),
21
+ float(data["petal_width"]),
22
+ ]
23
+ prediction = model.predict([features])
24
+ return jsonify({"prediction": prediction[0]})
25
+ except Exception as e:
26
+ return jsonify({"error": str(e)}), 400
27
 
28
+ # NOTE: Don't run app here if you're using Gunicorn
29
+ # Gunicorn will handle the server initialization