csankaran3 commited on
Commit
8be5a76
·
verified ·
1 Parent(s): bc4c759

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import joblib
5
+ import requests
6
+
7
+
8
+ # Streamlit UI for Customer Churn Prediction
9
+ st.title("Product Sales Prediction App")
10
+ st.write("The Product Sales Prediction App is a tool for businesses to forecast future sales and plan operations more effectively.")
11
+ st.write("Kindly enter the product details to predict the expected sales revenue")
12
+
13
+ # Collect user input
14
+ ProductWeight = st.number_input("Product Weight (weight of the product)", min_value=4.0, max_value=22.0, value=12.6)
15
+ ProductSugarContent = st.selectbox("Product Sugar Content(sugar content of the product)", ["Low Sugar", "Regular", "No sugar"])
16
+ ProductAllocatedArea = st.number_input("Product Allocated Area (ratio of the allocated display area of each product to the total display area )", min_value=0.00, max_value=0.29, value=0.06)
17
+ ProductType = st.selectbox("Product Type", ['Baking Goods', 'Breads', 'Breakfast', 'Canned',
18
+ 'Dairy', 'Frozen Food', 'Fruits and Vegetables',
19
+ 'Hard Drinks', 'Health and Hygiene', 'Household',
20
+ 'Meat', 'Others', 'Seafood', 'Snack foods',
21
+ 'Soft Drinks', 'Starchy Foods'])
22
+ ProductMRP = st.number_input("Product MRP(maximum retail price of each product)", min_value=31.0, max_value=266.0, value=141.0)
23
+ StoreID = st.selectbox("Store Id",['OUT001', 'OUT002', 'OUT003', 'OUT004'] )
24
+ StoreEstablishmentYear = st.number_input("Store Establishment Year (the year in which the store was established)", min_value=1987, max_value=2009, value=2000)
25
+ StoreSize= st.selectbox("Store Size", ['Small','Medium', 'High'])
26
+ StoreLocationCityType = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 2', 'Tier 3'])
27
+ StoreType = st.selectbox("Store Type",['Departmental Store', 'Food Mart', 'Supermarket Type 1', 'Supermarket Type 2'])
28
+
29
+ # Convert categorical inputs to match model training
30
+ input_data = pd.DataFrame([{
31
+ 'Product_Weight': ProductWeight,
32
+ 'Product_Sugar_Content': ProductSugarContent,
33
+ 'Product_Allocated_Area': ProductAllocatedArea,
34
+ 'Product_Type': ProductType,
35
+ 'Product_MRP': ProductMRP,
36
+ 'Store_Id': StoreID,
37
+ 'Store_Establishment_Year': StoreEstablishmentYear,
38
+ 'Store_Size': StoreSize,
39
+ 'Store_Location_City_Type': StoreLocationCityType,
40
+ 'Store_Type': StoreType
41
+ }])
42
+
43
+
44
+ if st.button("Predict", type='primary'):
45
+ headers = {'Content-Type': 'application/json'}
46
+ response = requests.post("https://csankaran3-backend.hf.space/v1/product", json=input_data.to_dict(orient='records')[0],headers=headers) # enter user name and space name before running the cell
47
+ if response.status_code == 200:
48
+ result = response.json()
49
+ predicted_sales = result['Predicted Sales'] # Extract only the value
50
+ st.write(f"Based on the information provided, the predicted product sale is {predicted_sales}.")
51
+ else:
52
+ st.error("Error in API request")
53
+
54
+
55
+ # Section for batch prediction
56
+ st.subheader("Batch Prediction")
57
+
58
+ # Allow users to upload a CSV file for batch prediction
59
+ uploaded_file = st.file_uploader("Upload CSV file for batch sales prediction", type=["csv"])
60
+
61
+ # Make batch prediction when the "Predict Batch" button is clicked
62
+ if uploaded_file is not None:
63
+ if st.button("Predict Batch"):
64
+ response = requests.post("https://csankaran3-backend.hf.space/v1/productbatch", files={"file": uploaded_file}) # Send file to Flask API
65
+ if response.status_code == 200:
66
+ predictions = response.json()['Predicted Sales']
67
+ st.success("Batch predictions completed!")
68
+ st.write(predictions) # Display the predictions
69
+ else:
70
+ st.error("Error making batch prediction.")