erikjacobs commited on
Commit
e0dc946
·
verified ·
1 Parent(s): 2d145ac

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -8,7 +8,7 @@ import os
8
  # Page configuration
9
  st.set_page_config(
10
  page_title=\"SuperKart Sales Predictor\",
11
- page_icon=\"🛒\",
12
  layout=\"wide\",
13
  initial_sidebar_state=\"expanded\"
14
  )
@@ -16,7 +16,7 @@ st.set_page_config(
16
  # Get backend URL from environment or use default
17
  BACKEND_URL = os.getenv('BACKEND_URL', 'https://erikjacobs-superkart-backend.hf.space')
18
 
19
- st.title(\"🛒 SuperKart Sales Predictor\")
20
  st.write(\"Predict sales revenue based on product and store characteristics\")
21
 
22
  # Sidebar for navigation
@@ -38,16 +38,16 @@ def check_backend_health():
38
  health_status, health_info = check_backend_health()
39
 
40
  if not health_status:
41
- st.error(f\"⚠️ Backend service is not available: {health_info}\")
42
  st.info(\"The backend service may be starting up. Please wait a moment and refresh.\")
43
  else:
44
- st.success(\" Backend service is healthy\")
45
 
46
  if page == \"Single Prediction\":
47
  st.header(\"Single Sales Prediction\")
48
-
49
  col1, col2 = st.columns(2)
50
-
51
  with col1:
52
  st.subheader(\"Product Information\")
53
  product_weight = st.number_input(\"Product Weight\", min_value=0.0, max_value=50.0, value=12.0)
@@ -59,17 +59,17 @@ if page == \"Single Prediction\":
59
  \"Hard Drinks\", \"Breakfast\", \"Snack Foods\", \"Bread\", \"Seafood\", \"Others\"
60
  ])
61
  product_mrp = st.number_input(\"Product MRP\", min_value=0.0, max_value=500.0, value=150.0)
62
-
63
  with col2:
64
  st.subheader(\"Store Information\")
65
- store_establishment_year = st.number_input(\"Store Establishment Year\",
66
  min_value=1980, max_value=2024, value=2000)
67
  store_size = st.selectbox(\"Store Size\", [\"Small\", \"Medium\", \"High\"])
68
  store_location_city_type = st.selectbox(\"City Type\", [\"Tier 1\", \"Tier 2\", \"Tier 3\"])
69
  store_type = st.selectbox(\"Store Type\", [
70
  \"Supermarket Type1\", \"Supermarket Type2\", \"Departmental Store\", \"Food Mart\"
71
  ])
72
-
73
  if st.button(\"Predict Sales\", type=\"primary\"):
74
  if not health_status:
75
  st.error(\"Cannot make prediction - backend service is not available\")
@@ -86,19 +86,19 @@ if page == \"Single Prediction\":
86
  \"Store_Location_City_Type\": store_location_city_type,
87
  \"Store_Type\": store_type
88
  }
89
-
90
  try:
91
  with st.spinner(\"Making prediction...\"):
92
- response = requests.post(f\"{BACKEND_URL}/predict\",
93
- json=prediction_data,
94
  timeout=30)
95
-
96
  if response.status_code == 200:
97
  result = response.json()
98
  prediction = result['prediction']
99
-
100
- st.success(f\"🎯 Predicted Sales Revenue: ${prediction:,.2f}\")
101
-
102
  # Display additional info
103
  col1, col2, col3 = st.columns(3)
104
  with col1:
@@ -107,48 +107,48 @@ if page == \"Single Prediction\":
107
  st.metric(\"Model Type\", result.get('model_type', 'Unknown'))
108
  with col3:
109
  st.metric(\"Timestamp\", result.get('timestamp', 'Unknown'))
110
-
111
  else:
112
  st.error(f\"Prediction failed: {response.text}\")
113
-
114
  except Exception as e:
115
  st.error(f\"Error making prediction: {str(e)}\")
116
 
117
  elif page == \"Model Info\":
118
  st.header(\"Model Information\")
119
-
120
  if not health_status:
121
  st.error(\"Cannot get model info - backend service is not available\")
122
  else:
123
  try:
124
  response = requests.get(f\"{BACKEND_URL}/model_info\", timeout=10)
125
-
126
  if response.status_code == 200:
127
  model_info = response.json()
128
-
129
  col1, col2 = st.columns(2)
130
-
131
  with col1:
132
  st.subheader(\"Model Details\")
133
  st.write(f\"**Model Type:** {model_info.get('model_type', 'Unknown')}\")
134
  st.write(f\"**Training Samples:** {model_info.get('training_samples', 'Unknown'):,}\")
135
  st.write(f\"**Test Samples:** {model_info.get('test_samples', 'Unknown'):,}\")
136
-
137
  with col2:
138
  st.subheader(\"Performance Metrics\")
139
  st.write(f\"**R² Score:** {model_info.get('test_r2_score', 0):.4f}\")
140
  st.write(f\"**RMSE:** {model_info.get('test_rmse', 0):.4f}\")
141
  st.write(f\"**MAE:** {model_info.get('test_mae', 0):.4f}\")
142
-
143
  if 'features' in model_info:
144
  st.subheader(\"Model Features\")
145
  features = model_info['features']
146
  st.write(f\"Total features: {len(features)}\")
147
  st.write(features)
148
-
149
  else:
150
  st.error(f\"Failed to get model info: {response.text}\")
151
-
152
  except Exception as e:
153
  st.error(f\"Error getting model info: {str(e)}\")
154
 
 
8
  # Page configuration
9
  st.set_page_config(
10
  page_title=\"SuperKart Sales Predictor\",
11
+ page_icon=\"\",
12
  layout=\"wide\",
13
  initial_sidebar_state=\"expanded\"
14
  )
 
16
  # Get backend URL from environment or use default
17
  BACKEND_URL = os.getenv('BACKEND_URL', 'https://erikjacobs-superkart-backend.hf.space')
18
 
19
+ st.title(\" SuperKart Sales Predictor\")
20
  st.write(\"Predict sales revenue based on product and store characteristics\")
21
 
22
  # Sidebar for navigation
 
38
  health_status, health_info = check_backend_health()
39
 
40
  if not health_status:
41
+ st.error(f\" Backend service is not available: {health_info}\")
42
  st.info(\"The backend service may be starting up. Please wait a moment and refresh.\")
43
  else:
44
+ st.success(\" Backend service is healthy\")
45
 
46
  if page == \"Single Prediction\":
47
  st.header(\"Single Sales Prediction\")
48
+
49
  col1, col2 = st.columns(2)
50
+
51
  with col1:
52
  st.subheader(\"Product Information\")
53
  product_weight = st.number_input(\"Product Weight\", min_value=0.0, max_value=50.0, value=12.0)
 
59
  \"Hard Drinks\", \"Breakfast\", \"Snack Foods\", \"Bread\", \"Seafood\", \"Others\"
60
  ])
61
  product_mrp = st.number_input(\"Product MRP\", min_value=0.0, max_value=500.0, value=150.0)
62
+
63
  with col2:
64
  st.subheader(\"Store Information\")
65
+ store_establishment_year = st.number_input(\"Store Establishment Year\",
66
  min_value=1980, max_value=2024, value=2000)
67
  store_size = st.selectbox(\"Store Size\", [\"Small\", \"Medium\", \"High\"])
68
  store_location_city_type = st.selectbox(\"City Type\", [\"Tier 1\", \"Tier 2\", \"Tier 3\"])
69
  store_type = st.selectbox(\"Store Type\", [
70
  \"Supermarket Type1\", \"Supermarket Type2\", \"Departmental Store\", \"Food Mart\"
71
  ])
72
+
73
  if st.button(\"Predict Sales\", type=\"primary\"):
74
  if not health_status:
75
  st.error(\"Cannot make prediction - backend service is not available\")
 
86
  \"Store_Location_City_Type\": store_location_city_type,
87
  \"Store_Type\": store_type
88
  }
89
+
90
  try:
91
  with st.spinner(\"Making prediction...\"):
92
+ response = requests.post(f\"{BACKEND_URL}/predict\",
93
+ json=prediction_data,
94
  timeout=30)
95
+
96
  if response.status_code == 200:
97
  result = response.json()
98
  prediction = result['prediction']
99
+
100
+ st.success(f\" Predicted Sales Revenue: ${prediction:,.2f}\")
101
+
102
  # Display additional info
103
  col1, col2, col3 = st.columns(3)
104
  with col1:
 
107
  st.metric(\"Model Type\", result.get('model_type', 'Unknown'))
108
  with col3:
109
  st.metric(\"Timestamp\", result.get('timestamp', 'Unknown'))
110
+
111
  else:
112
  st.error(f\"Prediction failed: {response.text}\")
113
+
114
  except Exception as e:
115
  st.error(f\"Error making prediction: {str(e)}\")
116
 
117
  elif page == \"Model Info\":
118
  st.header(\"Model Information\")
119
+
120
  if not health_status:
121
  st.error(\"Cannot get model info - backend service is not available\")
122
  else:
123
  try:
124
  response = requests.get(f\"{BACKEND_URL}/model_info\", timeout=10)
125
+
126
  if response.status_code == 200:
127
  model_info = response.json()
128
+
129
  col1, col2 = st.columns(2)
130
+
131
  with col1:
132
  st.subheader(\"Model Details\")
133
  st.write(f\"**Model Type:** {model_info.get('model_type', 'Unknown')}\")
134
  st.write(f\"**Training Samples:** {model_info.get('training_samples', 'Unknown'):,}\")
135
  st.write(f\"**Test Samples:** {model_info.get('test_samples', 'Unknown'):,}\")
136
+
137
  with col2:
138
  st.subheader(\"Performance Metrics\")
139
  st.write(f\"**R² Score:** {model_info.get('test_r2_score', 0):.4f}\")
140
  st.write(f\"**RMSE:** {model_info.get('test_rmse', 0):.4f}\")
141
  st.write(f\"**MAE:** {model_info.get('test_mae', 0):.4f}\")
142
+
143
  if 'features' in model_info:
144
  st.subheader(\"Model Features\")
145
  features = model_info['features']
146
  st.write(f\"Total features: {len(features)}\")
147
  st.write(features)
148
+
149
  else:
150
  st.error(f\"Failed to get model info: {response.text}\")
151
+
152
  except Exception as e:
153
  st.error(f\"Error getting model info: {str(e)}\")
154