Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Backend URL (Flask API you deployed earlier)
|
| 5 |
+
BACKEND_URL = "https://vilas97gupta-superkartbackend.hf.space/predict"
|
| 6 |
+
|
| 7 |
+
st.set_page_config(page_title="SuperKart Sales Predictor", layout="centered")
|
| 8 |
+
|
| 9 |
+
st.title("🛒 SuperKart Sales Prediction")
|
| 10 |
+
|
| 11 |
+
st.write("Fill in the details below to predict sales:")
|
| 12 |
+
|
| 13 |
+
# Input fields
|
| 14 |
+
product_sugar = st.selectbox("Product Sugar Content", ["Low", "Medium", "High"])
|
| 15 |
+
product_type = st.selectbox("Product Type", ["Snack", "Beverage", "Grocery", "Other"])
|
| 16 |
+
store_id = st.text_input("Store Id", "S1")
|
| 17 |
+
store_size = st.selectbox("Store Size", ["Small", "Medium", "Large"])
|
| 18 |
+
store_city_type = st.selectbox("Store City Type", ["Urban", "Suburban", "Rural"])
|
| 19 |
+
|
| 20 |
+
product_weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.1)
|
| 21 |
+
product_mrp = st.number_input("Product MRP (₹)", min_value=0.0, step=1.0)
|
| 22 |
+
store_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, step=1)
|
| 23 |
+
|
| 24 |
+
if st.button("🔮 Predict Sales"):
|
| 25 |
+
payload = {
|
| 26 |
+
"Product_Sugar_Content": product_sugar,
|
| 27 |
+
"Product_Type": product_type,
|
| 28 |
+
"Store_Id": store_id,
|
| 29 |
+
"Store_Size": store_size,
|
| 30 |
+
"Store_Location_City_Type": store_city_type,
|
| 31 |
+
"Product_Weight": product_weight,
|
| 32 |
+
"Product_MRP": product_mrp,
|
| 33 |
+
"Store_Establishment_Year": store_year
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
try:
|
| 37 |
+
resp = requests.post(BACKEND_URL, json=payload)
|
| 38 |
+
if resp.status_code == 200:
|
| 39 |
+
prediction = resp.json()["predictions"][0]
|
| 40 |
+
st.success(f"💰 Predicted Sales: {prediction:,.2f}")
|
| 41 |
+
else:
|
| 42 |
+
st.error(f"Backend error: {resp.text}")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
st.error(f"Request failed: {e}")
|