Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,33 +23,28 @@ def health():
|
|
| 23 |
return "SuperKart Backend is running"
|
| 24 |
|
| 25 |
|
| 26 |
-
@app.route("/
|
| 27 |
def predict():
|
| 28 |
try:
|
| 29 |
load_model()
|
| 30 |
-
|
| 31 |
data = request.get_json(force=True)
|
| 32 |
-
|
|
|
|
| 33 |
sample = {
|
| 34 |
-
"Product_Weight": data[
|
| 35 |
-
"Product_Sugar_Content": data[
|
| 36 |
-
"Product_Allocated_Area": data[
|
| 37 |
-
"Product_Type": data[
|
| 38 |
-
"Product_MRP": data[
|
| 39 |
-
"Store_Establishment_Year": data[
|
| 40 |
-
"Store_Size": data[
|
| 41 |
-
"Store_Location_City_Type": data[
|
| 42 |
-
"Store_Type": data[
|
| 43 |
}
|
| 44 |
-
|
| 45 |
query_df = pd.DataFrame([sample])
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
return jsonify({"predictions": float(prediction)})
|
| 50 |
-
|
| 51 |
-
except KeyError as e:
|
| 52 |
-
return jsonify({"error": f"Missing field: {str(e)}"}), 400
|
| 53 |
except Exception as e:
|
| 54 |
return jsonify({"error": str(e)}), 500
|
| 55 |
|
|
|
|
| 23 |
return "SuperKart Backend is running"
|
| 24 |
|
| 25 |
|
| 26 |
+
@app.route("/predict", methods=["POST"]) # Changed from /v1/predict to match frontend
|
| 27 |
def predict():
|
| 28 |
try:
|
| 29 |
load_model()
|
|
|
|
| 30 |
data = request.get_json(force=True)
|
| 31 |
+
|
| 32 |
+
# Keys must be strings to match the JSON sent by Streamlit
|
| 33 |
sample = {
|
| 34 |
+
"Product_Weight": data["Product_Weight"][0],
|
| 35 |
+
"Product_Sugar_Content": data["Product_Sugar_Content"][0],
|
| 36 |
+
"Product_Allocated_Area": data["Product_Allocated_Area"][0],
|
| 37 |
+
"Product_Type": data["Product_Type"][0],
|
| 38 |
+
"Product_MRP": data["Product_MRP"][0],
|
| 39 |
+
"Store_Establishment_Year": data["Store_Establishment_Year"][0],
|
| 40 |
+
"Store_Size": data["Store_Size"][0],
|
| 41 |
+
"Store_Location_City_Type": data["Store_Location_City_Type"][0],
|
| 42 |
+
"Store_Type": data["Store_Type"][0]
|
| 43 |
}
|
| 44 |
+
|
| 45 |
query_df = pd.DataFrame([sample])
|
| 46 |
+
prediction = model.predict(query_df).tolist()
|
| 47 |
+
return jsonify({"predictions": prediction})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
return jsonify({"error": str(e)}), 500
|
| 50 |
|