JohnsonSAimlarge's picture
Upload folder using huggingface_hub
df127ca verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("Superkart product sales Prediction")
# Section for online prediction
st.subheader("Online Prediction")
# Collect user input for product features
Product_Id = st.text_input("Product ID", value="PROD001")
Product_Weight = st.number_input("Product Weight",min_value=1, step=1, value=0)
Product_Sugar_Content = st.selectbox("Sugar content", ['Low Sugar', 'Regular', 'No Sugar'])
Product_Allocated_Area = st.number_input("Product_Allocated_Area", min_value=1, step=1, value=0)
Product_Type = st.selectbox("Product Type", [
'Meat', 'Snack Foods', 'Hard Drinks', 'Dairy', 'Canned', 'Soft Drinks',
'Health and Hygiene', 'Baking Goods', 'Bread', 'Breakfast', 'Frozen Foods',
'Fruits and Vegetables', 'Household', 'Seafood', 'Starchy Foods', 'Others'
] )
Product_MRP = st.number_input("Product_MRP", min_value=1, step=0.1, value=0)
Store_Id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
Store_Establishment_Year = st.number_input("Store Established Year", min_value=1900, max_value=2050, step=1, value=2025)
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High" ])
Store_Location_City_Type = st.selectbox("Store Location City Type",["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
"Product_Id": Product_Id,
'Product_Weight': Product_Weight,
'Product_Sugar_Content': Product_Sugar_Content,
'Product_Allocated_Area': Product_Allocated_Area,
'Product_Type': Product_Type,
'Product_MRP': Product_MRP,
'Store_Id': Store_Id,
'Store_Establishment_Year': Store_Establishment_Year,
'Store_Size': Store_Size,
'Store_Location_City_Type': Store_Location_City_Type,
'Store_Type': Store_Type
}])
# Make prediction when the "Predict" button is clicked
if st.button("Predict Sales"):
try:
response = requests.post(
"https://JohnsonSAimlarge-Salesforecastprediction.hf.space/v1/sales",
json=input_data.to_dict(orient='records')[0]
)
if response.status_code == 200:
predicted = response.json()['Sales']
st.success(f"💰 Predicted Sales: ₹{predicted}")
else:
st.error(f"❌ Backend error: {response.text}")
except Exception as e:
st.error(f"⚠️ Request failed: {e}")
# Section: Batch prediction
st.subheader("📄 Batch Prediction (CSV Upload)")
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
if uploaded_file is not None:
if st.button("Predict Batch Sales"):
try:
response = requests.post(
"https://JohnsonSAimlarge-Salesforecastprediction.hf.space/v1/salesbatch",
files={"file": uploaded_file}
)
if response.status_code == 200:
results = response.json()
st.success("✅ Batch predictions received!")
st.write(pd.DataFrame(results.items(), columns=["Product ID", "Predicted Sales (₹)"]))
else:
st.error(f"❌ Backend error: {response.text}")
except Exception as e:
st.error(f"⚠️ Request failed: {e}")