File size: 2,133 Bytes
d30a597
 
 
 
 
 
 
 
 
9d389ca
 
 
 
3d27f5a
9d389ca
 
8d079e5
9d389ca
 
 
d30a597
 
 
9d389ca
 
 
 
 
 
8d079e5
9d389ca
 
 
d30a597
 
 
 
ac35b35
d30a597
 
5e9738e
bfba04d
d30a597
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st
import pandas as pd
import requests

# Streamlit UI for Customer Churn Prediction
st.title("Product Sales Prediction App")
st.write("This tool predicts production sales prediction. Enter the required information below.")

# Collect user input based on dataset columns
weight = st.number_input("Product_Weight", min_value=1.0)
sugarcontent = st.selectbox("Product_Sugar_Content", ["Low Sugar", "No Sugar", "Regular Sugar", "reg"])
area = st.number_input("Product_Allocated_Area", min_value=1, max_value=9999999)
producttype = st.selectbox("Product_Type", ["Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "Snack Foods", "Meat", "Household", "Hard Drinks", "Fruits and Vegetables",
"Breads", "Others", "Starchy Foods", "Seafood"])
productmrp = st.number_input("Product_MRP", value=100)
year = st.number_input("Store_Establishment_Year", value=2007)
storeid = st.selectbox("Store_Id", ["OUT001", "OUT002", "OUT003", "OUT004"])
storesize = st.selectbox("Store_Size", ["Small", "Medium", "High"])
citytype = st.selectbox("Store_Location_City_Type", ["Tier1", "Tier2", "Tier3"])
storetype = st.selectbox("Store_Type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", "Departmental Store"])

# Convert categorical inputs to match model training
customer_data = {
    'Product_Weight': weight,
    'Product_Sugar_Content':sugarcontent,
    'Product_Allocated_Area': area,
    'Product_Type': producttype,
    'Product_MRP': productmrp,
    'Store_Establishment_Year': year,
    'Store_Id': storeid,
    'Store_Size': storesize,
    'Store_Location_City_Type': citytype,
    'Store_Type': storetype,
}


if st.button("Predict", type='primary'):
    response = requests.post("https://sp1505-backend.hf.space/v1/product", json=customer_data)    # enter user name and space name before running the cell
    if response.status_code == 200:
        result = response.json()
        sales_prediction = result["Predicted_Sales"]  # Extract only the value
        st.write(f"Based on the information provided, the sales is {sales_prediction}.")
    else:
        st.error("Error in API request")