Spaces:
No application file
No application file
| import streamlit as st | |
| import requests | |
| # Streamlit UI for Sales Prediction | |
| st.set_page_config(page_title="SuperKart Sales Prediction", page_icon="๐") | |
| st.title("๐ SuperKart Sales Prediction App") | |
| st.write("This tool predicts SuperKart Sales. Enter the required information below.") | |
| # Model Choice | |
| model_choice = st.selectbox( | |
| "Select Model", | |
| options=["dt", "xgb"], | |
| format_func=lambda x: "Decision Tree" if x == "dt" else "XGBoost" | |
| ) | |
| # Collect user input based on dataset columns | |
| product_weight = st.number_input("Product Weight", min_value=0.0, value=10.0) | |
| sugar = st.selectbox("Sugar Content Code", [0, 1, 2]) | |
| area = st.number_input("Allocated Area", min_value=0.0, value=0.05) | |
| product_type = st.number_input("Product Type Code", min_value=0, value=1) | |
| mrp = st.number_input("Product MRP", min_value=0.0, value=100.0) | |
| store_size = st.selectbox("Store Size Code", [0, 1, 2]) | |
| city = st.selectbox("City Type Code", [0, 1, 2]) | |
| store_type = st.number_input("Store Type Code", min_value=0, value=1) | |
| store_age = st.number_input("Store Age", min_value=0, value=10) | |
| # Payload to send to Flask API | |
| sample = { | |
| "model": model_choice, | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": sugar, | |
| "Product_Allocated_Area": area, | |
| "Product_Type": product_type, | |
| "Product_MRP": mrp, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": city, | |
| "Store_Type": store_type, | |
| "Store_Age": store_age | |
| } | |
| # API URL (Hugging Face backend) | |
| API_URL = "https://Lokiiparihar-SuperKart_API.hf.space/predict" | |
| if st.button("Predict", type="primary"): | |
| with st.spinner("๐ฎ Predicting sales..."): | |
| try: | |
| response = requests.post(API_URL, json=sample, timeout=20) | |
| if response.status_code == 200: | |
| result = response.json() | |
| sales_prediction = result["Prediction"] | |
| st.success(f"๐ฐ Predicted Sales: {sales_prediction:.2f}") | |
| else: | |
| st.error(f"โ API Error {response.status_code}") | |
| st.code(response.text) | |
| except Exception as e: | |
| st.error("โ Request failed") | |
| st.code(str(e)) |