Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,69 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
if
|
| 7 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%%writefile frontend_files/app.py
|
| 2 |
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
# Set the title of the Streamlit app
|
| 7 |
+
st.title("SuperKart Product Sales Prediction")
|
| 8 |
+
|
| 9 |
+
# Section for online prediction
|
| 10 |
+
st.subheader("Online Prediction")
|
| 11 |
+
|
| 12 |
+
# Collect user input for product/store features
|
| 13 |
+
Product_Weight = st.number_input("Product Weight (kg)", min_value=0.0, value=12.5)
|
| 14 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular", "reg"])
|
| 15 |
+
Product_Allocated_Area = st.number_input("Allocated Shelf Area", min_value=0.0, value=0.05)
|
| 16 |
+
Product_Type = st.selectbox("Product Type", [
|
| 17 |
+
"Fruits and Vegetables", "Dairy", "Canned", "Baking Goods",
|
| 18 |
+
"Snack Foods", "Health and Hygiene", "Household", "Frozen Foods", "Meat", "Soft Drinks", "Breads", "Hard Drinks", "Starchy Foods", "Breakfast", "Seafood"
|
| 19 |
+
])
|
| 20 |
+
Product_MRP = st.number_input("Product MRP (₹)", min_value=0.0, value=150.0)
|
| 21 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 22 |
+
Store_Location_City_Type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 23 |
+
Store_Type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", "Departmental Store"])
|
| 24 |
+
Store_Establishment_Year = st.slider("Store Establishment Year", min_value=1987, max_value=2025, value=2005)
|
| 25 |
+
Store_Age = 2025 - Store_Establishment_Year
|
| 26 |
+
|
| 27 |
+
# Convert user input into a DataFrame
|
| 28 |
+
input_data = pd.DataFrame([{
|
| 29 |
+
'Product_Weight': Product_Weight,
|
| 30 |
+
'Product_Sugar_Content': Product_Sugar_Content,
|
| 31 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 32 |
+
'Product_Type': Product_Type,
|
| 33 |
+
'Product_MRP': Product_MRP,
|
| 34 |
+
'Store_Size': Store_Size,
|
| 35 |
+
'Store_Location_City_Type': Store_Location_City_Type,
|
| 36 |
+
'Store_Type': Store_Type,
|
| 37 |
+
'Store_Age': Store_Age
|
| 38 |
+
}])
|
| 39 |
+
|
| 40 |
+
# Make prediction when the "Predict" button is clicked
|
| 41 |
+
if st.button("Predict"):
|
| 42 |
+
response = requests.post(
|
| 43 |
+
"https://PStark-SuperKartSalesPrediction-backend.hf.space/v1/sales",
|
| 44 |
+
json=input_data.to_dict(orient='records')[0]
|
| 45 |
+
)
|
| 46 |
+
if response.status_code == 200:
|
| 47 |
+
prediction = response.json()['Predicted Sales (₹)']
|
| 48 |
+
st.success(f"🧾 Predicted Product Sales: ₹{prediction}")
|
| 49 |
+
else:
|
| 50 |
+
st.error("Error making prediction.")
|
| 51 |
+
|
| 52 |
+
# Section for batch prediction
|
| 53 |
+
st.subheader("Batch Prediction")
|
| 54 |
|
| 55 |
+
# Allow users to upload a CSV file for batch prediction
|
| 56 |
+
uploaded_file = st.file_uploader("Upload a CSV file for batch sales prediction", type=["csv"])
|
| 57 |
|
| 58 |
+
if uploaded_file is not None:
|
| 59 |
+
if st.button("Predict Batch"):
|
| 60 |
+
response = requests.post(
|
| 61 |
+
"https://PStark-SuperKartSalesPrediction.hf.space/v1/salesbatch",
|
| 62 |
+
files={"file": uploaded_file}
|
| 63 |
+
)
|
| 64 |
+
if response.status_code == 200:
|
| 65 |
+
predictions = response.json()
|
| 66 |
+
st.success("Batch predictions completed!")
|
| 67 |
+
st.write(predictions)
|
| 68 |
+
else:
|
| 69 |
+
st.error("Error making batch prediction.")
|