Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +30 -17
src/streamlit_app.py
CHANGED
|
@@ -1,34 +1,47 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
# Hugging Face backend API endpoint
|
| 5 |
-
API_URL = "https://Akshat747-SuperKart.hf.space/predict"
|
| 6 |
|
| 7 |
st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide")
|
| 8 |
|
| 9 |
-
st.title("SuperKart Sales Predictor")
|
| 10 |
-
|
| 11 |
st.write("Enter product & store details below to predict sales:")
|
| 12 |
|
| 13 |
# Input fields
|
| 14 |
-
product_weight = st.number_input("Product Weight", min_value=0.0)
|
| 15 |
allocated_area = st.number_input("Product Allocated Area", min_value=0)
|
| 16 |
-
mrp = st.number_input("Product MRP", min_value=0.0)
|
| 17 |
sugar_content = st.selectbox("Product Sugar Content", ["Low", "Regular", "No Sugar"])
|
| 18 |
product_type = st.text_input("Product Type", "Snack Foods")
|
| 19 |
store_size = st.selectbox("Store Size", ["small", "medium", "high"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"Store_Type": store_type
|
| 21 |
}
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
else:
|
| 32 |
-
st.error(f"Error
|
| 33 |
-
|
| 34 |
-
st.error("
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
# ✅ Hugging Face backend API endpoint (Flask)
|
| 5 |
+
API_URL = "https://Akshat747-SuperKart.hf.space/predict" # change this after deploying Flask backend
|
| 6 |
|
| 7 |
st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide")
|
| 8 |
|
| 9 |
+
st.title("🛒 SuperKart Sales Predictor")
|
|
|
|
| 10 |
st.write("Enter product & store details below to predict sales:")
|
| 11 |
|
| 12 |
# Input fields
|
| 13 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, format="%.2f")
|
| 14 |
allocated_area = st.number_input("Product Allocated Area", min_value=0)
|
| 15 |
+
mrp = st.number_input("Product MRP", min_value=0.0, format="%.2f")
|
| 16 |
sugar_content = st.selectbox("Product Sugar Content", ["Low", "Regular", "No Sugar"])
|
| 17 |
product_type = st.text_input("Product Type", "Snack Foods")
|
| 18 |
store_size = st.selectbox("Store Size", ["small", "medium", "high"])
|
| 19 |
+
est_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2012)
|
| 20 |
+
location_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 21 |
+
store_type = st.selectbox("Store Type", ["Supermarket", "Grocery", "Convenience"])
|
| 22 |
+
|
| 23 |
+
if st.button("Predict Sales"):
|
| 24 |
+
payload = {
|
| 25 |
+
"Product_Weight": product_weight,
|
| 26 |
+
"Product_Allocated_Area": allocated_area,
|
| 27 |
+
"Product_MRP": mrp,
|
| 28 |
+
"Product_Sugar_Content": sugar_content,
|
| 29 |
+
"Product_Type": product_type,
|
| 30 |
+
"Store_Size": store_size,
|
| 31 |
+
"Store_Establishment_Year": est_year,
|
| 32 |
+
"Store_Location_City_Type": location_type,
|
| 33 |
"Store_Type": store_type
|
| 34 |
}
|
| 35 |
|
| 36 |
+
try:
|
| 37 |
+
response = requests.post(API_URL, json=payload)
|
| 38 |
+
if response.status_code == 200:
|
| 39 |
+
result = response.json()
|
| 40 |
+
if "prediction" in result:
|
| 41 |
+
st.success(f"✅ Predicted Sales: **{result['prediction']:.2f} units**")
|
| 42 |
+
else:
|
| 43 |
+
st.error(f"⚠️ Error: {result}")
|
| 44 |
else:
|
| 45 |
+
st.error(f"⚠️ Backend Error {response.status_code}")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
st.error(f"⚠️ Connection failed: {e}")
|