Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| st.title("Super Kart Sales Predictor") | |
| # Input fields for product and store data | |
| Product_Weight = st.slider("Product Weight", min_value=0.0, value=12.0, max_value = 22.0) | |
| Product_MRP = st.slider("Product MRP", min_value=30.0, value=145.0, max_value=260.0) | |
| Product_Allocated_Area = st.slider("Product Allocated Area", min_value=0.0, value=0.05, max_value=0.3) | |
| Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) | |
| 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", ["Departmental Store ", "Supermarket Type1", "Supermarket Type2", "Food Mart"]) | |
| Store_Age_Years = st.slider("Store Age (Years)", min_value=0, value=15, max_value=40) | |
| Product_Id_prefix = st.selectbox("Product ID Prefix", ["FD", "DR", "NC"]) | |
| Product_FD_perishable = st.selectbox("Product FD Perishable flag", ["Perishables", "Non Perishables"]) | |
| product_data = { | |
| "Product_Weight": Product_Weight, | |
| "Product_MRP": Product_MRP, | |
| "Product_Allocated_Area": Product_Allocated_Area, | |
| "Product_Sugar_Content": Product_Sugar_Content, | |
| "Store_Size": Store_Size, | |
| "Store_Location_City_Type": Store_Location_City_Type, | |
| "Store_Type": Store_Type, | |
| "Store_Age_Years": Store_Age_Years, | |
| "Product_Id_prefix": Product_Id_prefix, | |
| "Product_FD_perishable": Product_FD_perishable, | |
| } | |
| # Make prediction when the "Predict" button is clicked | |
| if st.button("Predict", type='primary'): | |
| response = requests.post("https://AlbertoNuin-SuperKartBackend.hf.space/v1/predict", json=product_data) | |
| if response.status_code == 200: | |
| result = response.json() | |
| predicted_sales = result["Sales"] | |
| st.write(f"Predicted Product Store Sales Total: {predicted_sales:.2f}") | |
| else: | |
| st.error("Error in API request") | |
| # 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://AlbertoNuin-SuperKartBackend.hf.space/v1/batch", 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.") | |