AkhilRaja commited on
Commit
7f93b25
Β·
verified Β·
1 Parent(s): e7893ea

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -28
app.py CHANGED
@@ -1,35 +1,36 @@
1
- import streamlit as st
2
  import requests
 
3
  import pandas as pd
4
 
5
- # Backend API endpoint
6
- BACKEND_URL = "https://AkhilRaja-superkart-flask-api.hf.space/predict"
7
-
8
- st.set_page_config(page_title="SuperKart Predictor", page_icon="πŸ›’", layout="wide")
9
 
10
- st.title("πŸ›’ SuperKart Predictor")
11
- st.markdown("Enter values to get predictions from the Random Forest model.")
12
-
13
- # Example input fields (replace with your dataset's actual features)
14
- feature1 = st.number_input("Feature 1", value=0.0)
15
- feature2 = st.number_input("Feature 2", value=0.0)
16
- feature3 = st.number_input("Feature 3", value=0.0)
 
 
17
 
18
  if st.button("Predict"):
19
- # Create input payload
20
- data = pd.DataFrame([{
21
- "feature1": feature1,
22
- "feature2": feature2,
23
- "feature3": feature3
24
- }])
 
 
 
 
 
 
 
25
 
26
- # Send request to backend
27
- try:
28
- response = requests.post(BACKEND_URL, json=data.to_dict(orient="records"))
29
- if response.status_code == 200:
30
- result = response.json()
31
- st.success(f"βœ… Prediction: {result['predictions']}")
32
- else:
33
- st.error(f"❌ Error: {response.text}")
34
- except Exception as e:
35
- st.error(f"🚨 Failed to connect to backend: {e}")
 
 
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}")