pkulkar's picture
Upload folder using huggingface_hub
df995f9 verified
Raw History Blame Contribute Delete
3.11 kB
import streamlit as st
import requests
import json
st.title("SuperKart Sales Forecaster")
st.write("Enter the details of the product and store to get a sales forecast.")
# Create input fields for the user
product_weight = st.number_input("Product Weight", min_value=0.0, format="%f")
product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, format="%f")
product_type = st.selectbox("Product Type", ['Dairy', 'Soft Drinks', 'Meat', 'Fruits and Vegetables', 'Household', 'Baking Goods', 'Snack Foods', 'Frozen Foods', 'Breakfast', 'Health and Hygiene', 'Hard Drinks', 'Canned', 'Bread', 'Starchy Foods', 'Others', 'Seafood'])
product_mrp = st.number_input("Product MRP", min_value=0.0, format="%f")
store_id = st.selectbox("Store ID", [f"Store_{i}" for i in range(1, 11)])
store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2024, step=1)
store_size = st.selectbox("Store Size", ['Medium', 'High', 'Low'])
store_location_city_type = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 3', 'Tier 2'])
store_type = st.selectbox("Store Type", ['Supermarket Type 1', 'Supermarket Type 2', 'Departmental Store', 'Food Mart'])
# Prepare the data to be sent to the API
input_data = {
'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,
}
if st.button("Predict Sales"):
# Send the data to the Flask API
try:
response = requests.post("https://pkulkar-SalesForcasterFrontend.hf.space/v1/sales", json=input_data)
if response.status_code == 200:
prediction = response.json()
st.success(f"Predicted Sales: {prediction['Predicted Price (in dollars)']:.2f}")
else:
st.error(f"Error predicting sales: {response.status_code} - {response.text}")
except requests.exceptions.RequestException as e:
st.error(f"Error connecting to the API: {e}")
# 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 Sales Batch"):
response = requests.post("https://pkulkar-SalesForcasterFrontend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
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.")