mohith96 commited on
Commit
344052b
·
verified ·
1 Parent(s): a70281e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -31,13 +31,13 @@ with col_right:
31
 
32
  # Create JSON payload
33
  payload = {
34
- #"Product_Id": product_id,
35
  "Product_Weight": weight,
36
  "Product_Sugar_Content": sugar_level,
37
  "Product_Allocated_Area": allocated_area,
38
  "Product_Type": category,
39
  "Product_MRP": mrp,
40
- #"Store_Id": store_id,
41
  "Store_Establishment_Year": establishment_year,
42
  "Store_Size": store_size,
43
  "Store_Location_City_Type": city_tier,
@@ -50,13 +50,19 @@ if st.button("Get Sales Prediction"):
50
  try:
51
  api_url = "https://mohith96-SuperKartBackend.hf.space/predict"
52
  response = requests.post(api_url, json=payload, timeout=10)
 
53
  if response.status_code == 200:
54
  result = response.json()
55
- if "Predicted_Sales_Product" in result:
56
- st.success(f"Predicted Sales: $ {result['Predicted_Sales_Product']:.2f}")
 
 
57
  else:
58
- st.warning(f"Unexpected response: {result}")
59
  else:
60
  st.error(f"API returned {response.status_code}: {response.text}")
 
 
 
61
  except Exception as error:
62
- st.error(f"Failed to reach API: {error}")
 
31
 
32
  # Create JSON payload
33
  payload = {
34
+ #"Product_ID": product_id,
35
  "Product_Weight": weight,
36
  "Product_Sugar_Content": sugar_level,
37
  "Product_Allocated_Area": allocated_area,
38
  "Product_Type": category,
39
  "Product_MRP": mrp,
40
+ #"Store_ID": store_id,
41
  "Store_Establishment_Year": establishment_year,
42
  "Store_Size": store_size,
43
  "Store_Location_City_Type": city_tier,
 
50
  try:
51
  api_url = "https://mohith96-SuperKartBackend.hf.space/predict"
52
  response = requests.post(api_url, json=payload, timeout=10)
53
+
54
  if response.status_code == 200:
55
  result = response.json()
56
+ predicted_value = result.get("Predicted_Sales") or result.get("Predicted_Sales_Product")
57
+
58
+ if predicted_value is not None:
59
+ st.success(f"Predicted Sales: $ {predicted_value:.2f}")
60
  else:
61
+ st.warning(f"Unexpected response format: {result}")
62
  else:
63
  st.error(f"API returned {response.status_code}: {response.text}")
64
+
65
+ except requests.exceptions.RequestException as req_err:
66
+ st.error(f"API request failed: {req_err}")
67
  except Exception as error:
68
+ st.error(f"Unexpected error: {error}")