File size: 2,472 Bytes
bcd5b8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import streamlit as st
import pandas as pd
import requests

# Set the title of the Streamlit app
st.title("πŸ›’ SuperKart Sales Prediction")

# Section for online prediction
st.subheader("πŸ“¦ Predict Sales for a Single Product")

# Collect user input
product_weight = st.number_input("Product Weight (in kg)", min_value=0.0, value=1.0)
sugar_content = st.selectbox("Product Sugar Content", ["Low", "Medium", "High"])
allocated_area = st.selectbox("Allocated Shelf Area", ["Small", "Medium", "Large"])
product_type = st.selectbox("Product Type", ["Dairy", "Beverages", "Snacks", "Frozen Foods", "Others"])
product_mrp = st.number_input("Product MRP (β‚Ή)", min_value=1.0, value=100.0)

store_year = st.number_input("Store Establishment Year", min_value=1980, max_value=2025, value=2010)
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
city_type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Grocery Store", "Others"])

# Prepare input data
input_data = pd.DataFrame([{
    'Product_Weight': product_weight,
    'Product_Sugar_Content': sugar_content,
    'Product_Allocated_Area': allocated_area,
    'Product_Type': product_type,
    'Product_MRP': product_mrp,
    'Store_Establishment_Year': store_year,
    'Store_Size': store_size,
    'Store_Location_City_Type': city_type,
    'Store_Type': store_type
}])

# Predict single product sales
if st.button("Predict Sales"):
    response = requests.post(
        "/v1/sales",
        json=input_data.to_dict(orient='records')[0]
    )
    if response.status_code == 200:
        prediction = response.json()['Predicted sales (in dollars)']
        st.success(f"🧾 Predicted Sales: β‚Ή{prediction}")
    else:
        st.error("❌ Error making prediction. Check backend logs.")

# Section for batch prediction
st.subheader("πŸ“‚ Predict Sales for Multiple Products (Batch)")

uploaded_file = st.file_uploader("Upload CSV file with product-store data", type=["csv"])

if uploaded_file is not None:
    if st.button("Predict Batch"):
        response = requests.post(
            "/v1/salesbatch",
            files={"file": uploaded_file}
        )
        if response.status_code == 200:
            predictions = response.json()
            st.success("βœ… Batch prediction completed!")
            st.write(predictions)
        else:
            st.error("❌ Failed to process batch prediction.")