Lokiiparihar commited on
Commit
e62687d
·
verified ·
1 Parent(s): 68fc041

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +59 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,60 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import requests
3
+ import json
4
+
5
+ st.set_page_config(page_title="SuperKart Sales Prediction", layout="centered")
6
+
7
+ st.title("🛒 SuperKart Sales Prediction")
8
+ st.write("Enter product and store features below to get a sales forecast.")
9
+
10
+ # --- INPUT FIELDS ---
11
+ product_weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.1, value=12.0)
12
+ product_sugar = st.selectbox("Product Sugar Content", [0, 1])
13
+ product_alloc_area = st.number_input("Allocated Display Area (sq. m)", min_value=0.0, step=0.01, value=0.05)
14
+ product_mrp = st.number_input("Product MRP", min_value=1.0, step=0.5, value=150.0)
15
+ store_size = st.selectbox("Store Size", [0, 1, 2]) # small/medium/high
16
+ store_city_type = st.selectbox("Store Location City Type", [0, 1, 2]) # a/b/c
17
+ store_type = st.selectbox("Store Type", [0, 1, 2, 3])
18
+ store_age = st.slider("Store Age (Years)", 0, 30, 10)
19
+
20
+ product_type = st.selectbox("Product Category", [
21
+ "Breads", "Breakfast", "Canned", "Dairy", "Frozen Foods", "Fruits and Vegetables",
22
+ "Hard Drinks", "Health and Hygiene", "Household", "Meat", "Others", "Seafood",
23
+ "Snack Foods", "Soft Drinks", "Starchy Foods"
24
+ ])
25
+
26
+ # Create one-hot encoded product types
27
+ product_type_features = {f"Product_Type_{pt}": int(pt == product_type) for pt in [
28
+ "Breads", "Breakfast", "Canned", "Dairy", "Frozen Foods", "Fruits and Vegetables",
29
+ "Hard Drinks", "Health and Hygiene", "Household", "Meat", "Others", "Seafood",
30
+ "Snack Foods", "Soft Drinks", "Starchy Foods"
31
+ ]}
32
+
33
+ # --- PAYLOAD CREATION ---
34
+ input_data = {
35
+ "Product_Weight": product_weight,
36
+ "Product_Sugar_Content": product_sugar,
37
+ "Product_Allocated_Area": product_alloc_area,
38
+ "Product_MRP": product_mrp,
39
+ "Store_Size": store_size,
40
+ "Store_Location_City_Type": store_city_type,
41
+ "Store_Type": store_type,
42
+ "Store_Age": store_age,
43
+ **product_type_features
44
+ }
45
+
46
+ # --- API CALL ---
47
+ if st.button("Predict Sales"):
48
+ with st.spinner("Fetching prediction from backend..."):
49
+ try:
50
+ response = requests.post(
51
+ "https://lokiiparihar-superkartbackendmodaldeploy-xgboost.hf.space/predict",
52
+ json=input_data
53
+ )
54
+ if response.status_code == 200:
55
+ prediction = response.json().get("prediction", "N/A")
56
+ st.success(f"🧮 Estimated Sales: **{prediction:.2f} units**")
57
+ else:
58
+ st.error(f"❌ API Error: {response.status_code}")
59
+ except Exception as e:
60
+ st.error(f"Request failed: {e}")