Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -20,17 +20,23 @@ def home():
|
|
| 20 |
@app.route("/predict", methods=["POST"])
|
| 21 |
def predict():
|
| 22 |
try:
|
| 23 |
-
# Get JSON input
|
| 24 |
data = request.get_json(force=True)
|
| 25 |
-
features = np.array(data["features"])
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
return jsonify({"error": str(e)})
|
| 34 |
|
|
|
|
| 35 |
if __name__ == "__main__":
|
| 36 |
app.run(host="0.0.0.0", port=7860, debug=True)
|
|
|
|
| 20 |
@app.route("/predict", methods=["POST"])
|
| 21 |
def predict():
|
| 22 |
try:
|
|
|
|
| 23 |
data = request.get_json(force=True)
|
| 24 |
+
features = np.array(data["features"])
|
| 25 |
|
| 26 |
+
# Case 1: single row
|
| 27 |
+
if features.ndim == 1:
|
| 28 |
+
features = features.reshape(1, -1)
|
| 29 |
+
prediction = model.predict(features)[0]
|
| 30 |
+
return jsonify({"predicted_revenue": float(prediction)})
|
| 31 |
|
| 32 |
+
# Case 2: multiple rows
|
| 33 |
+
else:
|
| 34 |
+
predictions = model.predict(features).tolist()
|
| 35 |
+
return jsonify({"predictions": predictions})
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
return jsonify({"error": str(e)})
|
| 39 |
|
| 40 |
+
|
| 41 |
if __name__ == "__main__":
|
| 42 |
app.run(host="0.0.0.0", port=7860, debug=True)
|