cchele/Predict-Total-Revenue
0
1import streamlit as st2import pandas as pd3import requests4 5# Set the title of the Streamlit app6st.title("SuperKart Sales Revenue Prediction")7st.write("This tool predicts total sales revenue based on the values entered. Type or select values for each variable and click 'Predict'.")8 9# Section for online prediction10st.subheader("Online Prediction for One Product")11 12# Collect user input for property features13Product_Weight = st.number_input("Weight of the Product", min_value=0., value=13.) # value is the default, if min_value and value have to both be int or both be float14Product_Allocated_Area = st.number_input("Ratio of the Display Area of the Product to the Total Display Area in the Store", min_value = .001, value=.06)15Product_MRP = st.number_input("Maximum Retail Price for the Product", min_value = .05, value=147.0)16Product_Sugar_Content = st.selectbox("Sugar Content of the Product", ['Regular','Low Sugar','No Sugar'])17Product_TypeCombos = st.selectbox("Type of Product", ['NonFood','Fruits and Vegetables','Dairy','Baking Goods','Drinks','MeatSeafood','LongDuration','StarchBread'])18Store_Establishment_Year = st.selectbox("Year Store was Established", ['1987','1998','1999','2009'])19Store_Size = st.selectbox("Size of the Store", ['Small','Medium','High'])20Store_Location_City_Type = st.selectbox("Type of City Where the Store is Located", ['Tier 1', "Tier 2", "Tier 3"])21Store_Type = st.selectbox("Type of Store",['Supermarket Type1', 'Supermarket Type2', 'Departmental Store','Food Mart'])22 23# Convert user input into a DataFrame24input_data = pd.DataFrame([{25 'Product_Weight': Product_Weight,26 'Product_Sugar_Content': Product_Sugar_Content,27 'Product_Allocated_Area': Product_Allocated_Area,28 'Product_TypeCombos': Product_TypeCombos,29 'Product_MRP': Product_MRP,30 'Store_Establishment_Year': Store_Establishment_Year,31 'Store_Size': Store_Size,32 'Store_Location_City_Type': Store_Location_City_Type,33 'Store_Type': Store_Type34}])35 36# Make prediction when the "Predict" button is clicked37if st.button("Predict"):38 # Send data to backend Flask API39 response = requests.post("https://cchele-SuperKartPredictionBackend.hf.space/v1/superkart", json=input_data.to_dict(orient='records')[0])40 41 if response.status_code == 200:42 prediction = response.json()['Predicted Total Revenue (in dollars)'] # has to match where it says return jsonify in the Flask app43 st.success(f"Predicted Total Revenue (in dollars): {prediction}")44 else:45 st.error("Error making prediction.")46 