RomMat's picture
Upload folder using huggingface_hub
601a7e4 verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title('SuperKart Product Store Sales Total Prediction')
st.write("This tool predicts store sales based on their products details")
# Section for online prediction
st.subheader('Online Prediction')
# Collect user input for store features
store_id = st.text_input('Store ID')
store_establishment_year = st.number_input('Store Establishment Year')
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', 'Supermarket Type3'])
product_sugar_content = st.selectbox('Product Sugar Content', ['Low Sugar', 'Regular', 'No Sugar']) # Corrected options
product_type = st.selectbox('Product Type', ['Perishables', 'Non Perishables'])
product_weight = st.number_input('Product Weight')
product_allocated_area = st.number_input('Product Allocated Area')
product_mrp = st.number_input('Product MRP')
# Convert user input into a DataFrame
# The input data structure needs to match the training data features (X_train)
# Store_Age needs to be calculated dynamically
# Product_Id is a categorical feature and needs a placeholder for single predictions
# Handle potential single-value input for `st.number_input` which returns float, not tuple.
# Corrected variable names in the input_data dictionary.
input_data = pd.DataFrame([{
"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,
"Product_Sugar_Content": product_sugar_content,
"Product_Type": product_type,
"Product_Weight": product_weight,
"Product_Allocated_Area": product_allocated_area,
"Product_MRP": product_mrp,
"Product_Id": "FD6114" # Placeholder for Product_Id as it's not user input in this UI
}])
# Make prediction when the "predict" button is clicked
if st.button('Predict'):
# Send the input data to the backend API for prediction
# Make sure the URL is correct for your Hugging Face Space backend
response = requests.post("https://rommat/storesalestotalpredictionbackend.hf.space/v1/productstoresalestotal", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()['Predicted Product Store Sales Total (in dollars)']
st.success(f'Predicted Product Store Sales Total Price (in dollars): {prediction}')
else:
st.error(f'Error making prediction. Status code: {response.status_code}')