Spaces:
Build error
Build error
import streamlit as st | |
import pandas as pd | |
import requests | |
# Set the title of the Streamlit app | |
st.title("SuperKart Store Sales Prediction") | |
# Section for online prediction | |
st.subheader("Online Prediction") | |
# Collect user input for store/product features | |
product_weight = st.number_input("Product Weight", min_value=0.0, value=1.0) | |
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=10.0) | |
product_mrp = st.number_input("Product MRP", min_value=0.0, value=50.0) | |
store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2015) | |
product_sugar_content = st.selectbox("Product Sugar Content", ["Low", "Medium", "High"]) | |
product_type = st.selectbox("Product Type", ["Dairy", "Beverages", "Snacks", "Others"]) | |
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", ["Type 1", "Type 2", "Type 3", "Type 4"]) | |
store_id = st.text_input("Store Id", "S001") | |
# Feature engineering for Store_Age | |
store_age = 2025 - store_establishment_year | |
# Convert user input into a DataFrame | |
input_data = pd.DataFrame([{ | |
'Product_Weight': product_weight, | |
'Product_Allocated_Area': product_allocated_area, | |
'Product_MRP': product_mrp, | |
'Store_Age': store_age, | |
'Product_Sugar_Content': product_sugar_content, | |
'Product_Type': product_type, | |
'Store_Size': store_size, | |
'Store_Location_City_Type': store_location_city_type, | |
'Store_Type': store_type, | |
'Store_Id': store_id | |
}]) | |
# Make prediction when the "Predict" button is clicked | |
if st.button("Predict"): | |
response = requests.post( | |
"https://Disha252001-SuperKart-Frontend.hf.space/v1/sale", | |
json=input_data.to_dict(orient='records')[0] | |
) | |
if response.status_code == 200: | |
prediction = response.json()['Predicted Store Sales'] | |
st.success(f"Predicted Store Sales: {prediction}") | |
else: | |
st.error("Error making prediction.") | |
# 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"): | |
response = requests.post( | |
"https://Disha252001-SuperKart-Frontend.hf.space/v1/salebatch", | |
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.") | |