|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import requests |
|
|
|
|
|
|
|
|
st.title("SuperKart Sales Prediction") |
|
|
|
|
|
|
|
|
st.subheader("Online Prediction") |
|
|
|
|
|
|
|
|
product_type = st.selectbox("Product Type", [ |
|
|
"Dairy", "Soft Drinks", "Meat", "Fruits and Vegetables", "Household", |
|
|
"Baking Goods", "Snack Foods", "Frozen Foods", "Breakfast", "Health and Hygiene", |
|
|
"Hard Drinks", "Others", "Seafood", "Starchy Foods", "Canned", "Breads" |
|
|
]) |
|
|
store_id = st.selectbox("Store ID", ["OUT004", "OUT001", "OUT003", "OUT002"]) |
|
|
|
|
|
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) |
|
|
product_weight = st.number_input("Product Weight (grams)", min_value=0.0, step=0.1, value=500.0) |
|
|
product_mrp = st.number_input("Product MRP (₹)", min_value=0.0, step=0.1, value=100.0) |
|
|
product_allocated_area = st.number_input("Allocated Shelf Area (sq cm)", min_value=0.0, step=1.0, value=100.0) |
|
|
|
|
|
store_type = st.selectbox("Store Type", ["Supermarket Type2", "Supermarket Type1", "Departmental Store", "Food Mart"]) |
|
|
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) |
|
|
store_location_city_type = st.selectbox("Store Location", ["Tier 2", "Tier 1", "Tier 3"]) |
|
|
store_establishment_year = st.number_input("Year of Store Establishment", min_value=1900, max_value=2025, step=1, value=2015) |
|
|
|
|
|
|
|
|
input_data = pd.DataFrame([{ |
|
|
'Product_Type': product_type, |
|
|
'Product_Sugar_Content': product_sugar_content, |
|
|
'Product_Weight': product_weight, |
|
|
'Product_MRP': product_mrp, |
|
|
'Product_Allocated_Area': product_allocated_area, |
|
|
'Store_Id': store_id, |
|
|
'Store_Type': store_type, |
|
|
'Store_Size': store_size, |
|
|
'Store_Location_City_Type': store_location_city_type, |
|
|
'Store_Establishment_Year': store_establishment_year |
|
|
}]) |
|
|
|
|
|
|
|
|
if st.button("Predict"): |
|
|
response = requests.post("https://Swetha2031-SuperKartSalesPredictionBackend.hf.space/v1/salestotal", json=input_data.to_dict(orient='records')[0]) |
|
|
if response.status_code == 200: |
|
|
prediction = response.json()['Predicted Sales (₹)'] |
|
|
st.success(f"Predicted Product Sales: ₹{prediction}") |
|
|
else: |
|
|
st.error("Error making prediction.") |
|
|
|
|
|
|
|
|
|
|
|
st.subheader("Batch Prediction") |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"]) |
|
|
|
|
|
|
|
|
if st.button("Predict Batch"): |
|
|
response = requests.post("https://Swetha2031-SuperKartSalesPredictionBackend.hf.space/v1/salesbatch", files={"file": uploaded_file}) |
|
|
if response.status_code == 200: |
|
|
predictions = response.json() |
|
|
|
|
|
|
|
|
df_predictions = pd.DataFrame(list(predictions.items()), columns=["Store ID", "Predicted Sales (₹)"]) |
|
|
|
|
|
|
|
|
if df_predictions["Predicted Sales (₹)"].gt(1e10).any(): |
|
|
st.warning("Some predictions are extremely large. This may indicate overflow or input scaling issues.") |
|
|
|
|
|
st.success("Batch predictions completed!") |
|
|
st.write(df_predictions) |
|
|
else: |
|
|
st.error("Error making batch prediction.") |
|
|
|