maddykan101 commited on
Commit
80fc2cd
·
verified ·
1 Parent(s): ff28353

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -40
app.py CHANGED
@@ -5,51 +5,40 @@ import requests
5
  # Set the title of the Streamlit app
6
  st.title("Sales Prediction")
7
 
8
- # Section for online prediction
9
- st.subheader("Online Prediction")
 
 
 
 
 
 
 
 
 
10
 
11
- sample = {
12
- 'Product_Weight': property_data['Product_Weight'],
13
- 'Product_Allocated_Area': property_data['Product_Allocated_Area'],
14
- 'Product_MRP': property_data['Product_MRP'],
15
- 'Store_Establishment_Year': property_data['Store_Establishment_Year'],
16
- 'Product_Sugar_Content': property_data['Product_Sugar_Content'],
17
- 'Product_Type': property_data['Product_Type'],
18
- 'Store_Id': property_data['Store_Id'],
19
- 'Store_Size': property_data['Store_Size'],
20
- 'Store_Location_City_Type': property_data['Store_Location_City_Type'],
21
- 'Store_Type': property_data['Store_Type']
22
- }
23
-
24
- # Collect user input for property features
25
- product_weight = st.number_input("Weight of the product", min_value=0, value=2)
26
- Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=1, value=2)
27
- Product_MRP = st.number_input("Product_MRP", min_value=1, step=1, value=2)
28
- Store_Establishment_Year = st.selectbox("Store_Establishment_Year", ["strict", "flexible", "moderate"])
29
- Product_Sugar_Content = st.selectbox("Product_Sugar_Content", ["True", "False"])
30
- Product_Type = st.selectbox("Product_Type", ["False", "True"])
31
- Store_Size = st.number_input("Store_Size", min_value=0.0, max_value=100.0, step=1.0, value=90.0)
32
- Store_Location_City_Type = st.number_input("Store_Location_City_Type", min_value=0, step=1, value=1)
33
- Store_Type = st.number_input("Store_Type", min_value=0, step=1, value=1)
34
-
35
- # Convert user input into a DataFrame
36
- input_data = pd.DataFrame([{
37
  'Product_Weight': product_weight,
38
- 'Product_Allocated_Area': Product_Allocated_Area,
39
- 'Product_MRP': Product_MRP,
40
- 'Store_Establishment_Year': Store_Establishment_Year,
41
- 'Product_Sugar_Content': Product_Sugar_Content,
42
- 'Product_Type': Product_Type, # Convert to 't' or 'f'
43
- 'Store_Size': Store_Size,
44
- 'Store_Location_City_Type': Store_Location_City_Type,
45
- 'Store_Type': Store_Type
46
- }])
 
47
 
48
  # Make prediction when the "Predict" button is clicked
49
  if st.button("Predict"):
50
- response = requests.post("https://maddykan101-SalesPredictionBackend.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
 
 
 
51
  if response.status_code == 200:
52
- prediction = response.json()['Predicted Sakes']
53
  st.success(f"Predicted Sales: {prediction}")
54
  else:
55
- st.error("Error making prediction.")
 
5
  # Set the title of the Streamlit app
6
  st.title("Sales Prediction")
7
 
8
+ # Collect user input
9
+ product_weight = st.number_input("Weight of the product", min_value=0.0, value=2.0)
10
+ product_allocated_area = st.number_input("Product Allocated Area", min_value=1.0, value=2.0)
11
+ product_mrp = st.number_input("Product MRP", min_value=1.0, step=1.0, value=10.0)
12
+ store_establishment_year = st.selectbox("Store Establishment Year", [2005, 2010, 2015, 2020])
13
+ product_sugar_content = st.selectbox("Product Sugar Content", ["Low", "Normal", "High"])
14
+ product_type = st.selectbox("Product Type", ["Snack Foods", "Dairy", "Beverages"])
15
+ store_id = st.text_input("Store ID", value="STR001")
16
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
17
+ store_location_city_type = st.selectbox("Store Location City Type", ["Urban", "Semi-Urban", "Rural"])
18
+ store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Grocery Store"])
19
 
20
+ # Create input dictionary
21
+ input_data = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  'Product_Weight': product_weight,
23
+ 'Product_Allocated_Area': product_allocated_area,
24
+ 'Product_MRP': product_mrp,
25
+ 'Store_Establishment_Year': store_establishment_year,
26
+ 'Product_Sugar_Content': product_sugar_content,
27
+ 'Product_Type': product_type,
28
+ 'Store_Id': store_id,
29
+ 'Store_Size': store_size,
30
+ 'Store_Location_City_Type': store_location_city_type,
31
+ 'Store_Type': store_type
32
+ }
33
 
34
  # Make prediction when the "Predict" button is clicked
35
  if st.button("Predict"):
36
+ response = requests.post(
37
+ "https://maddykan101-SalesPredictionBackend.hf.space/v1/prediction",
38
+ json=input_data
39
+ )
40
  if response.status_code == 200:
41
+ prediction = response.json()['Predicted Sales '] # Adjust key if needed
42
  st.success(f"Predicted Sales: {prediction}")
43
  else:
44
+ st.error(f"Prediction failed: {response.status_code}")