SudeendraMG's picture
Upload folder using huggingface_hub
1d122a0 verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("SuperKart Product Total Sales Prediction")
# Section for online prediction
st.subheader("Online Prediction")
# ---------------------------- User Input Section ----------------------------
# Get product weight from user
product_weight = st.number_input(
"Product Weight (in grams)",
min_value=0.0, value=100.0, step=0.1,
help="Weight of each product"
)
# Get sugar content category
product_sugar_content = st.selectbox(
"Product Sugar Content",
["Low Sugar", "Regular", "No Sugar"],
help="Sugar content of each product"
)
# Get allocated display area ratio
product_allocated_area = st.number_input(
"Product Allocated Area (0 to 1)",
min_value=0.0, max_value=1.0, value=0.2, step=0.01,
help="Ratio of the product's allocated display area to total display area in the store"
)
# Select product type
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"
],
help="Broad category for the product"
)
# Set maximum retail price
product_mrp = st.number_input(
"Product MRP (in ₹)",
min_value=1.0, value=100.0, step=1.0,
help="Maximum retail price of each product"
)
# Unique store identifier
store_id = st.text_input(
"Store ID",
value="S101",
help="Unique identifier of the store"
)
# Year of store establishment
store_establishment_year = st.number_input(
"Store Establishment Year",
min_value=1900, max_value=2025, value=2010, step=1,
help="Year the store was established"
)
# Select store size
store_size = st.selectbox(
"Store Size",
["High", "Medium", "Small"],
help="Size of the store in square feet"
)
# Choose city type for store location
store_location_city_type = st.selectbox(
"Store Location City Type",
["Tier 1", "Tier 2", "Tier 3"],
help="City type where store is located"
)
# Choose store type
store_type = st.selectbox(
"Store Type",
["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"],
help="Type of store based on products sold"
)
# ---------------------------- Create DataFrame ----------------------------
# Collect all the input features into a DataFrame for API call
input_data = pd.DataFrame([{
'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
}])
# ---------------------------- Online Prediction ----------------------------
# Call the backend model API when the user clicks the "Predict" button
if st.button("Predict"):
response = requests.post(
"https://SudeendraMG-SuperKartProductTotalSalesPredictionBackend.hf.space/v1/totalsales", # Updated endpoint
json=input_data.to_dict(orient='records')[0]
)
# Check the response and show the prediction
if response.status_code == 200:
prediction = response.json()['Predicted Product Store Sales Total']
st.success(f"Predicted Product Store Sales Total: {prediction}")
else:
st.error("Error making prediction.") # Show error if API call fails
# ---------------------------- Batch Prediction Section ----------------------------
# Subtitle for batch predictions
st.subheader("Batch Prediction")
# Let user upload CSV file for batch prediction
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
# If file is uploaded and user clicks the "Predict Batch" button
if uploaded_file is not None:
if st.button("Predict Batch"):
# Send file to the backend batch prediction endpoint
response = requests.post(
"https://SudeendraMG-SuperKartProductTotalSalesPredictionBackend.hf.space/v1/totalsalesbatch", # Updated endpoint
files={"file": uploaded_file}
)
# Display batch predictions or error
if response.status_code == 200:
predictions = response.json()
st.success("Batch predictions completed!")
st.write(predictions)
else:
st.error("Error making batch prediction.")