deepacsr's picture
Upload folder using huggingface_hub
29a4399 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 details
product_type = st.selectbox("Product Type",["Frozen Foods","Dairy","Canned","Baking Goods","Snack Foods","Meat","Fruits and Vegetables","Breads","Breakfast","Starchy Foods","Seafood"])
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar","Regular","No Sugar"])
# Min, Max value taken from the statistics details captured in the EDA
# Mean value is taken as the default value
# Step is defined based on the range of numbers
# Keeping all the arguments in same type as expected by streamlit
product_mrp = st.number_input("MRP (in $)", min_value=31.0, max_value=267.0, step=1.0, value=147.0)
product_weight = st.number_input("Product Weight (in Ounce)", min_value=4.0, max_value=22.0, step=0.2, value=12.0)
product_allocated_area=st.number_input("Product Allocated area in %", min_value=0.4, max_value=30.0, step=0.1, value=0.7)
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", ["Food Mart","Supermarket Type1","Supermarket Type2","Departmental Store"])
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'Product_MRP': product_mrp,
'Product_Type': product_type,
'Product_Sugar_Content': product_sugar_content,
'Product_Weight': product_weight,
'Product_Allocated_Area': product_allocated_area/100,
'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"):
response = requests.post("https://deepacsr-ProductPricePredictionBackend.hf.space/v1/ProductSale", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()
st.success("Product sales predictions completed!")
st.success(f"Predicted Sales Price (in dollars): {prediction}")
else:
st.error("Error making prediction.")
st.error(f"Error code: {response.status_code}")
# Section for batch prediction
st.subheader("Batch Prediction")
# Allow users to upload a CSV file for batch prediction
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
# Make batch prediction when the "Predict Batch" button is clicked
if uploaded_file is not None:
if st.button("Predict Batch"):
st.write(uploaded_file.name)
st.write(uploaded_file.getvalue())
response = requests.post("https://deepacsr-ProductPricePredictionBackend.hf.space//v1/batchsales",files={"file": uploaded_file})
if response.status_code == 200:
predictions = response.json()
st.success("Batch predictions completed!")
st.write(predictions) # Display the predictions
else:
st.error("Error making batch prediction.")
st.error(f"Error code: {response.status_code}")
st.error(response.text)