Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| st.title("SuperKart Store Sales Prediction") | |
| st.subheader("Online Prediction") | |
| # Collect user input | |
| 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 Sugar", "Regular", "No Sugar"]) | |
| product_type = st.selectbox("Product Type", [ | |
| "Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "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", [ | |
| "Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart" | |
| ]) | |
| store_id = st.text_input("Store Id", "OUT001") | |
| # Prepare payload for backend | |
| input_data = { | |
| "Product_Weight": product_weight, | |
| "Product_Allocated_Area": product_allocated_area, | |
| "Product_MRP": product_mrp, | |
| "Store_Establishment_Year": store_establishment_year, # ✅ backend will convert to 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 | |
| } | |
| # Prediction button | |
| if st.button("Predict"): | |
| try: | |
| response = requests.post( | |
| "https://disha252001-sales-prediction-backend-final.hf.space/v1/sales", | |
| json=input_data | |
| ) | |
| if response.status_code == 200: | |
| prediction = response.json()["Predicted Store Sales"] | |
| st.success(f"Predicted Store Sales: {prediction}") | |
| else: | |
| st.error(f"Error {response.status_code}: Could not get prediction. Check backend logs.") | |
| except Exception as e: | |
| st.error(f"Request failed: {e}") | |
| # Batch prediction | |
| st.subheader("Batch Prediction") | |
| uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"]) | |
| if uploaded_file is not None: | |
| if st.button("Predict Batch"): | |
| try: | |
| response = requests.post( | |
| "https://disha252001-sales-prediction-backend-final.hf.space/v1/salesbatch", | |
| files={"file": uploaded_file} | |
| ) | |
| if response.status_code == 200: | |
| predictions = response.json() | |
| st.success("Batch predictions completed!") | |
| st.write(predictions) | |
| else: | |
| st.error(f"Error {response.status_code}: Could not get batch prediction.") | |
| except Exception as e: | |
| st.error(f"Batch request failed: {e}") | |