AkhilRaja commited on
Commit
3353e64
·
verified ·
1 Parent(s): 7f93b25

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +38 -36
app.py CHANGED
@@ -1,36 +1,38 @@
1
- import requests
2
- import streamlit as st
3
- import pandas as pd
4
-
5
- st.title("🛒 SuperKart Sales Predictor")
6
-
7
- # Collect inputs
8
- Product_Weight = st.number_input("Product Weight", 0.0, 50.0, 12.5)
9
- Product_Sugar_Content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
10
- Product_Allocated_Area = st.number_input("Allocated Area", 0.0, 1.0, 0.25)
11
- Product_Type = st.text_input("Product Type", "Snack foods")
12
- Product_MRP = st.number_input("MRP", 0.0, 500.0, 200.0)
13
- Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
14
- Store_Location_City_Type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
15
- Store_Type = st.text_input("Store Type", "Supermarket Type1")
16
-
17
- if st.button("Predict"):
18
- sample = [{
19
- "Product_Weight": Product_Weight,
20
- "Product_Sugar_Content": Product_Sugar_Content,
21
- "Product_Allocated_Area": Product_Allocated_Area,
22
- "Product_Type": Product_Type,
23
- "Product_MRP": Product_MRP,
24
- "Store_Size": Store_Size,
25
- "Store_Location_City_Type": Store_Location_City_Type,
26
- "Store_Type": Store_Type
27
- }]
28
-
29
- url = "https://akhilraja-superkart-flask-api.hf.space/predict"
30
- response = requests.post(url, json=sample)
31
-
32
- if response.status_code == 200:
33
- result = response.json()
34
- st.success(f"Predicted Sales: {result['predictions'][0]:.2f}")
35
- else:
36
- st.error(f"Error: {response.text}")
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ st.title("🛒 SuperKart Sales Predictor")
5
+
6
+ # Sidebar inputs
7
+ Product_Weight = st.sidebar.number_input("Product Weight", min_value=0.0, max_value=100.0, value=10.0)
8
+ Product_Sugar_Content = st.sidebar.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
9
+ Product_Allocated_Area = st.sidebar.number_input("Allocated Area", min_value=0.0, max_value=10.0, value=0.5)
10
+ Product_Type = st.sidebar.text_input("Product Type", "Snack foods")
11
+ Product_MRP = st.sidebar.number_input("MRP", min_value=0.0, max_value=1000.0, value=100.0)
12
+ Store_Size = st.sidebar.selectbox("Store Size", ["Small", "Medium", "High"])
13
+ Store_Location_City_Type = st.sidebar.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
14
+ Store_Type = st.sidebar.text_input("Store Type", "Supermarket Type1")
15
+
16
+ if st.button("Predict Sales"):
17
+ sample = [{
18
+ "Product_Weight": Product_Weight,
19
+ "Product_Sugar_Content": Product_Sugar_Content,
20
+ "Product_Allocated_Area": Product_Allocated_Area,
21
+ "Product_Type": Product_Type,
22
+ "Product_MRP": Product_MRP,
23
+ "Store_Size": Store_Size,
24
+ "Store_Location_City_Type": Store_Location_City_Type,
25
+ "Store_Type": Store_Type
26
+ }]
27
+
28
+ url = "https://akhilraja-superkart-flask-api.hf.space/predict"
29
+ try:
30
+ response = requests.post(url, json=sample)
31
+ response.raise_for_status()
32
+ prediction = response.json().get("predictions", [None])[0]
33
+ if prediction is not None:
34
+ st.success(f"Predicted Sales: {prediction:.2f}")
35
+ else:
36
+ st.error("No prediction returned.")
37
+ except Exception as e:
38
+ st.error(f"Error: {e}")