Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Streamlit UI | |
| st.set_page_config(page_title="SuperKart Sales Predictor", layout="centered") | |
| st.title("SuperKart Product Sales Prediction") | |
| # Input form | |
| with st.form("prediction_form"): | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| product_weight = st.slider("Product Weight (kg)", 0.0, 25.0, 10.0) | |
| allocated_area = st.slider("Allocated Area (sq ft)", 50.0, 1000.0, 200.0) | |
| product_mrp = st.number_input("Product MRP (₹)", min_value=10.0, max_value=500.0, value=250.0) | |
| with col2: | |
| sugar_content = st.selectbox("Sugar Content", ["Low", "Medium", "High"]) | |
| product_type = st.selectbox("Product Type", ["Snack Foods", "Baking Goods", "Canned", "Soft Drinks", "Dairy"]) | |
| store_year = st.selectbox("Store Establishment Year", list(range(1985, 2024))) | |
| store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) | |
| city_type = st.selectbox("Store Location City Type", ["Urban", "Semi-Urban", "Rural"]) | |
| store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Grocery Store", "Supermarket Type3"]) | |
| submitted = st.form_submit_button("Predict") | |
| # On submit: call API | |
| if submitted: | |
| input_payload = [{ | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": sugar_content, | |
| "Product_Allocated_Area": allocated_area, | |
| "Product_Type": product_type, | |
| "Product_MRP": product_mrp, | |
| "Store_Establishment_Year": store_year, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": city_type, | |
| "Store_Type": store_type | |
| }] | |
| try: | |
| response = requests.post( | |
| "https://Mahendra87-IP-SuperMart.hf.space/predict", | |
| json=input_payload, | |
| timeout=10 | |
| ) | |
| if response.status_code == 200: | |
| result = response.json() | |
| st.write("API response:", result) # Helpful for debugging | |
| if "prediction" in result: | |
| prediction = result["prediction"][0] | |
| st.success(f"Predicted Product Sales: ₹{round(prediction, 2)}") | |
| else: | |
| st.error("'prediction' key not found in API response.") | |
| else: | |
| st.error(f"Prediction failed. Status code: {response.status_code}") | |
| st.text(response.text) | |
| except Exception as e: | |
| st.error(f"API request failed: {e}") | |