| | import streamlit as st |
| | import pandas as pd |
| | import requests |
| |
|
| | |
| | st.title("SuperKart Product Store Sales Prediction") |
| |
|
| | |
| | st.subheader("Predict Single Product Sales") |
| |
|
| | |
| | product_id = st.text_input("Product ID") |
| | product_weight = st.number_input("Product Weight", min_value=0.0, value=10.0) |
| | product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "low sugar"]) |
| | product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.05) |
| | product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Meat', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood', 'Fruits and Vegetables', 'Household']) |
| | product_mrp = st.number_input("Product MRP", min_value=0.0, value=100.0) |
| | store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002']) |
| | store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, value=2000) |
| | store_size = st.selectbox("Store Size", ["Medium", "High", "Small"]) |
| | store_location_city_type = st.selectbox("Store Location City Type", ["Tier 2", "Tier 1", "Tier 3"]) |
| | store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart']) |
| |
|
| | |
| | current_year = pd.to_datetime('now').year |
| | store_age = current_year - store_establishment_year |
| |
|
| | perishables = ['Fruits and Vegetables', 'Dairy', 'Meat', 'Seafood', 'Breads', 'Breakfast'] |
| | product_category_type = 'Perishables' if product_type in perishables else 'Non Perishables' |
| |
|
| | |
| | input_data = { |
| | 'Product_Id': product_id, |
| | 'Product_Weight': product_weight, |
| | 'Product_Sugar_Content': product_sugar_content, |
| | 'Product_Allocated_Area': product_allocated_area, |
| | 'Product_Type': product_type, |
| | 'Product_MRP': product_mrp, |
| | 'Store_Id': store_id, |
| | 'Store_Establishment_Year': store_establishment_year, |
| | 'Store_Size': store_size, |
| | 'Store_Location_City_Type': store_location_city_type, |
| | 'Store_Type': store_type, |
| | 'Product_Category_from_ID': product_id[:2] if product_id else '', |
| | 'Store_Age': store_age, |
| | 'Product_Category_Type': product_category_type |
| | } |
| |
|
| |
|
| | |
| | if st.button("Predict"): |
| | |
| | backend_url = "https://Garg06-superkart.hf.space" |
| | predict_url = f"{backend_url}/v1/product" |
| |
|
| | try: |
| | response = requests.post(predict_url, json=input_data) |
| | if response.status_code == 200: |
| | prediction = response.json()['Predicted_Product_Store_Sales_Total'] |
| | st.success(f"Predicted Product Store Sales Total: {prediction:.2f}") |
| | else: |
| | st.error(f"Error making prediction. Status code: {response.status_code}") |
| | st.error(f"Response: {response.text}") |
| | except requests.exceptions.RequestException as e: |
| | st.error(f"Error connecting to the backend: {e}") |
| |
|
| |
|
| | |
| | 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"): |
| | |
| | backend_url = "https://Garg06-superkart.hf.space" |
| | predict_batch_url = f"{backend_url}/v1/productbatch" |
| |
|
| | try: |
| | response = requests.post(predict_batch_url, 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 making batch prediction. Status code: {response.status_code}") |
| | st.error(f"Response: {response.text}") |
| | except requests.exceptions.RequestException as e: |
| | st.error(f"Error connecting to the backend: {e}") |
| |
|