Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="SuperKart Sales Predictor", page_icon="🛒")
|
| 5 |
+
st.title("🛒 SuperKart Sales Prediction")
|
| 6 |
+
st.markdown("Enter product and store details below to get the predicted sales.")
|
| 7 |
+
|
| 8 |
+
with st.form("prediction_form"):
|
| 9 |
+
Product_Weight = st.number_input("Product Weight", value=12.0)
|
| 10 |
+
Product_Sugar_Content = st.selectbox("Sugar Content", [0, 1])
|
| 11 |
+
Product_Allocated_Area = st.number_input("Allocated Area", value=0.05)
|
| 12 |
+
Product_MRP = st.number_input("Product MRP", value=150.0)
|
| 13 |
+
Store_Size = st.selectbox("Store Size", [0, 1, 2])
|
| 14 |
+
Store_Location_City_Type = st.selectbox("City Type", [0, 1, 2])
|
| 15 |
+
Store_Type = st.selectbox("Store Type", [0, 1, 2, 3])
|
| 16 |
+
Store_Age = st.slider("Store Age (years)", 0, 50, 10)
|
| 17 |
+
|
| 18 |
+
product_types = [
|
| 19 |
+
"Product_Type_Breads", "Product_Type_Breakfast", "Product_Type_Canned",
|
| 20 |
+
"Product_Type_Dairy", "Product_Type_Frozen_Foods", "Product_Type_Fruits_and_Vegetables",
|
| 21 |
+
"Product_Type_Hard_Drinks", "Product_Type_Health_and_Hygiene", "Product_Type_Household",
|
| 22 |
+
"Product_Type_Meat", "Product_Type_Others", "Product_Type_Seafood",
|
| 23 |
+
"Product_Type_Snack_Foods", "Product_Type_Soft_Drinks", "Product_Type_Starchy_Foods"
|
| 24 |
+
]
|
| 25 |
+
selected_type = st.selectbox("Product Type", product_types)
|
| 26 |
+
|
| 27 |
+
submitted = st.form_submit_button("Predict Sales")
|
| 28 |
+
|
| 29 |
+
if submitted:
|
| 30 |
+
input_data = {
|
| 31 |
+
"Product_Weight": Product_Weight,
|
| 32 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 33 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 34 |
+
"Product_MRP": Product_MRP,
|
| 35 |
+
"Store_Size": Store_Size,
|
| 36 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 37 |
+
"Store_Type": Store_Type,
|
| 38 |
+
"Store_Age": Store_Age
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
for pt in product_types:
|
| 42 |
+
input_data[pt] = 1 if pt == selected_type else 0
|
| 43 |
+
|
| 44 |
+
api_url = "https://lokiiparihar-SuperkartBackendModalDeploy-XGBoost.hf.space/predict" # Replace with actual backend
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
with st.spinner("Predicting..."):
|
| 48 |
+
res = requests.post(api_url, json=input_data)
|
| 49 |
+
res.raise_for_status()
|
| 50 |
+
st.success(f"✅ Predicted Sales: {res.json()['prediction']:.2f} units")
|
| 51 |
+
except Exception as e:
|
| 52 |
+
st.error(f"Prediction failed: {e}")
|