Lokiiparihar commited on
Commit
b133196
·
verified ·
1 Parent(s): 1c65e07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -23,33 +23,28 @@ def health():
23
  return "SuperKart Backend is running"
24
 
25
 
26
- @app.route("/v1/predict", methods=["POST"])
27
  def predict():
28
  try:
29
  load_model()
30
-
31
  data = request.get_json(force=True)
32
-
 
33
  sample = {
34
- "Product_Weight": data[product_weight],
35
- "Product_Sugar_Content": data[product_sugar_content],
36
- "Product_Allocated_Area": data[product_allocated_area],
37
- "Product_Type": data[product_type],
38
- "Product_MRP": data[product_mrp],
39
- "Store_Establishment_Year": data[store_establishment_year],
40
- "Store_Size": data[store_size],
41
- "Store_Location_City_Type": data[store_location_city_type],
42
- "Store_Type": data[store_type]
43
  }
44
-
45
  query_df = pd.DataFrame([sample])
46
-
47
- prediction = model.predict(query_df).tolist()[0]
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