DD009 commited on
Commit
781eee4
·
verified ·
1 Parent(s): 0e2f4de

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +32 -30
app.py CHANGED
@@ -16,10 +16,10 @@ with col1:
16
  # Product Features
17
  st.markdown("**Product Details**")
18
  product_weight = st.slider("Product Weight (kg)", 4.0, 22.0, 12.66, 0.01)
19
- product_sugar = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
20
  product_area = st.slider("Allocated Area (sqm)", 0.004, 0.3, 0.05, 0.001)
21
  product_type = st.selectbox("Product Type", [
22
- "Frozen Foods", "Dairy", "Canned", "Baking Goods",
23
  "Health and Hygiene", "Snack Foods", "Meat", "Household"
24
  ])
25
  product_mrp = st.slider("Product MRP (price)", 31.0, 266.0, 147.0, 0.5)
@@ -27,26 +27,23 @@ with col1:
27
  with col2:
28
  # Store Features
29
  st.markdown("**Store Details**")
30
- store_id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
31
- current_year = datetime.now().year
32
- establishment_year = st.slider("Store Establishment Year",
33
- 1987, current_year, 2002)
34
- store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
35
  city_type = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
36
  store_type = st.selectbox("Store Type", [
37
- "Supermarket Type1", "Supermarket Type2",
38
  "Departmental Store", "Food Mart"
39
  ])
40
 
41
- # Prepare input data
42
  input_data = {
43
  "product_weight": product_weight,
44
- "product_sugar_content": product_sugar,
45
  "product_allocated_area": product_area,
46
- "product_type": product_type,
47
  "product_mrp": product_mrp,
48
- "store_id": store_id,
49
  "store_establishment_year": establishment_year,
 
 
50
  "store_size": store_size,
51
  "store_location_city_type": city_type,
52
  "store_type": store_type
@@ -55,16 +52,14 @@ input_data = {
55
  # Make prediction when the "Predict" button is clicked
56
  if st.button("Predict Sales"):
57
  try:
58
- response = requests.post("http://DD009-SuperKartBackend.hf.space/v1/sales", json=input_data)
59
  if response.status_code == 200:
60
  result = response.json()
61
  st.success(f"Predicted Sales Total: ${result['predicted_sales']}")
62
 
63
- # Display additional metrics
64
- st.markdown("**Additional Metrics**")
65
- st.write(f"- Store Age: {result['store_age']} years")
66
- st.write(f"- Product Density: {result['product_density']} kg/sqm")
67
- st.write(f"- Price per Unit Weight: ${result['price_per_weight']}/kg")
68
  else:
69
  st.error(f"Error making prediction: {response.json().get('error', 'Unknown error')}")
70
  except Exception as e:
@@ -74,22 +69,31 @@ if st.button("Predict Sales"):
74
  st.subheader("Batch Prediction")
75
  st.write("Upload a CSV file containing multiple product-store combinations")
76
 
 
 
 
 
 
 
 
 
 
77
  # File uploader for batch predictions
78
  uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
79
 
80
  if uploaded_file is not None:
81
  if st.button("Predict Batch Sales"):
82
  try:
83
- files = {'file': uploaded_file.getvalue()}
84
- response = requests.post("http://DD009-SuperKartBackend.hf.space/v1/salesbatch", files=files)
85
-
86
  if response.status_code == 200:
87
  results = response.json()['predictions']
88
  results_df = pd.DataFrame(results)
89
-
90
  st.success("Batch predictions completed!")
91
  st.dataframe(results_df)
92
-
93
  # Download button for results
94
  csv = results_df.to_csv(index=False)
95
  st.download_button(
@@ -105,20 +109,18 @@ if uploaded_file is not None:
105
 
106
  # Add sample data section
107
  st.sidebar.markdown("### Sample Data")
108
- if st.sidebar.button("Load Sample Data"):
109
  sample_data = {
110
  "product_weight": 12.66,
111
- "product_sugar_content": "Low Sugar",
112
  "product_allocated_area": 0.027,
113
- "product_type": "Frozen Foods",
114
  "product_mrp": 117.08,
115
- "store_id": "OUT004",
116
  "store_establishment_year": 2009,
 
 
117
  "store_size": "Medium",
118
  "store_location_city_type": "Tier 2",
119
  "store_type": "Supermarket Type2"
120
  }
121
 
122
- # Update all widgets with sample data
123
- st.experimental_set_query_params(**sample_data)
124
- st.experimental_rerun()
 
16
  # Product Features
17
  st.markdown("**Product Details**")
18
  product_weight = st.slider("Product Weight (kg)", 4.0, 22.0, 12.66, 0.01)
19
+ product_sugar = st.selectbox("Sugar Content", ["Low", "Medium", "High"])
20
  product_area = st.slider("Allocated Area (sqm)", 0.004, 0.3, 0.05, 0.001)
21
  product_type = st.selectbox("Product Type", [
22
+ "Frozen Foods", "Dairy", "Canned", "Baking Goods",
23
  "Health and Hygiene", "Snack Foods", "Meat", "Household"
24
  ])
25
  product_mrp = st.slider("Product MRP (price)", 31.0, 266.0, 147.0, 0.5)
 
27
  with col2:
28
  # Store Features
29
  st.markdown("**Store Details**")
30
+ establishment_year = st.slider("Store Establishment Year",
31
+ 1987, datetime.now().year, 2002)
32
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "Large"])
 
 
33
  city_type = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
34
  store_type = st.selectbox("Store Type", [
35
+ "Supermarket Type1", "Supermarket Type2",
36
  "Departmental Store", "Food Mart"
37
  ])
38
 
39
+ # Prepare input data (only including features used in the backend)
40
  input_data = {
41
  "product_weight": product_weight,
 
42
  "product_allocated_area": product_area,
 
43
  "product_mrp": product_mrp,
 
44
  "store_establishment_year": establishment_year,
45
+ "product_sugar_content": product_sugar,
46
+ "product_type": product_type,
47
  "store_size": store_size,
48
  "store_location_city_type": city_type,
49
  "store_type": store_type
 
52
  # Make prediction when the "Predict" button is clicked
53
  if st.button("Predict Sales"):
54
  try:
55
+ response = requests.post("http://localhost:5000/v1/sales", json=input_data)
56
  if response.status_code == 200:
57
  result = response.json()
58
  st.success(f"Predicted Sales Total: ${result['predicted_sales']}")
59
 
60
+ # Display features used
61
+ st.markdown("**Features Used**")
62
+ st.write(", ".join(result['features_used']))
 
 
63
  else:
64
  st.error(f"Error making prediction: {response.json().get('error', 'Unknown error')}")
65
  except Exception as e:
 
69
  st.subheader("Batch Prediction")
70
  st.write("Upload a CSV file containing multiple product-store combinations")
71
 
72
+ # Instructions for CSV format
73
+ st.markdown("""
74
+ **CSV File Requirements:**
75
+ - Must contain these exact columns:
76
+ - Product_Weight, Product_Allocated_Area, Product_MRP
77
+ - Store_Establishment_Year, Product_Sugar_Content, Product_Type
78
+ - Store_Size, Store_Location_City_Type, Store_Type
79
+ """)
80
+
81
  # File uploader for batch predictions
82
  uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
83
 
84
  if uploaded_file is not None:
85
  if st.button("Predict Batch Sales"):
86
  try:
87
+ files = {'file': uploaded_file}
88
+ response = requests.post("http://localhost:5000/v1/salesbatch", files=files)
89
+
90
  if response.status_code == 200:
91
  results = response.json()['predictions']
92
  results_df = pd.DataFrame(results)
93
+
94
  st.success("Batch predictions completed!")
95
  st.dataframe(results_df)
96
+
97
  # Download button for results
98
  csv = results_df.to_csv(index=False)
99
  st.download_button(
 
109
 
110
  # Add sample data section
111
  st.sidebar.markdown("### Sample Data")
112
+ if st.sidebar.button("Show Sample Input"):
113
  sample_data = {
114
  "product_weight": 12.66,
 
115
  "product_allocated_area": 0.027,
 
116
  "product_mrp": 117.08,
 
117
  "store_establishment_year": 2009,
118
+ "product_sugar_content": "Low",
119
+ "product_type": "Frozen Foods",
120
  "store_size": "Medium",
121
  "store_location_city_type": "Tier 2",
122
  "store_type": "Supermarket Type2"
123
  }
124
 
125
+ st.sidebar.json(sample_data)
126
+