| import streamlit as st |
| import pandas as pd |
| import requests |
|
|
| |
| st.title("π SuperKart Sales Prediction") |
|
|
| |
| st.subheader("π¦ Predict Sales for a Single Product") |
|
|
| |
| 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"]) |
|
|
| |
| 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 |
| }]) |
|
|
| |
| 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.") |
|
|
| |
| 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.") |
|
|