| | import streamlit as st
|
| | import pandas as pd
|
| | import requests
|
| | import os
|
| |
|
| |
|
| |
|
| |
|
| | st.title("Product Store Sales Revenue Predictor")
|
| |
|
| |
|
| | st.subheader("Online Prediction.! ")
|
| |
|
| |
|
| |
|
| | Id=st.number_input("Enter Id for the intended Product", min_value=1, step=1, format="%d")
|
| | ProductCategory = st.selectbox("Product_Category", ["Food(FD)","Non Consumables(NC)","Drinks(DR)"])
|
| | ProductWeight = st.number_input("Product_Weight", min_value=1.00, value=1.00)
|
| | ProductAllocatedArea = st.number_input("Product_Allocated_Area", min_value=0.0001, value=0.0001)
|
| | ProductMRP = st.number_input("Product_MRP", min_value=1.00,value=1.00)
|
| | StoreEstablishmentYear = st.number_input("Store_Establishment_Year", min_value=1980,value=1990)
|
| | ProductSugarContent = st.selectbox("Product_Sugar_Content", ["Low Sugar", "Regular", "No Sugar"])
|
| | ProductType = st.selectbox("Product_Type", ["Fruits and Vegetables","Snack Foods","Frozen Foods","Dairy","Household","Baking Goods","Canned","Health and Hygiene","Meat","Soft Drinks","Breads","Hard Drinks","Others","Starchy Foods","Breakfast",
|
| | "Seafood"])
|
| | StoreId = st.selectbox("Store_Id", ["OUT001", "OUT002", "OUT003","OUT004"])
|
| | StoreSize = st.selectbox("Store_Size", ["Small", "Medium", "High"])
|
| | StoreLocationCityType = st.selectbox("Store_Location_City_Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| | StoreType = st.selectbox("Store_Type", ["Departmental Store", "Food Mart", "Supermarket Type1","Supermarket Type2"])
|
| |
|
| |
|
| | input_data = pd.DataFrame([{
|
| | 'Product_Weight': ProductWeight,
|
| | 'Product_Allocated_Area': ProductAllocatedArea,
|
| | 'Product_MRP': ProductMRP,
|
| | 'Store_Establishment_Year': StoreEstablishmentYear,
|
| | 'Product_Category' : ProductCategory.split("(")[-1].strip(")"),
|
| | 'Product_Sugar_Content': ProductSugarContent,
|
| | 'Product_Type': ProductType,
|
| | 'Store_Id': StoreId,
|
| | 'Store_Size': StoreSize,
|
| | 'Store_Location_City_Type': StoreLocationCityType,
|
| | 'Store_Type': StoreType
|
| | }])
|
| |
|
| |
|
| | api_token = os.environ["API_TOKEN"]
|
| |
|
| |
|
| | headers = {
|
| | 'Authorization': f"Bearer {api_token}",
|
| | 'Content-Type': 'application/json'
|
| | }
|
| |
|
| | headers_batch = {
|
| | 'Authorization': f"Bearer {api_token}",
|
| | }
|
| |
|
| |
|
| | if st.button("Predict"):
|
| | product_Id = input_data["Product_Category"].iloc[0] + str(Id)
|
| | try:
|
| | response = requests.post(
|
| | "https://MainiSandeep1987-SuperKartBackEnd.hf.space/v1/salesTotal",headers=headers,
|
| | json=input_data.to_dict(orient='records')[0]
|
| | )
|
| |
|
| | if response.status_code == 200:
|
| |
|
| | prediction = response.json().get('Predicted Sales Revenue Price', "Prediction not found")
|
| | st.success(f"Predicted Sales Revenue for Product_Id {product_Id} :: {prediction}")
|
| | else:
|
| | st.error(f"Error {response.status_code}: {response.text}")
|
| |
|
| | except requests.exceptions.RequestException as e:
|
| | st.error(f"Request failed : {str(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"):
|
| | try:
|
| | response = requests.post("https://MainiSandeep1987-SuperKartBackEnd.hf.space/v1/salesTotalBatch",headers=headers_batch, files={"file": uploaded_file})
|
| | if response.status_code == 200:
|
| | response.raise_for_status()
|
| | predictions = response.json()
|
| | st.success("Batch predictions completed!")
|
| | st.write(predictions)
|
| | else:
|
| | st.error("Error making batch prediction.")
|
| | except requests.exceptions.RequestException as e:
|
| | st.error(f"Request failed: {str(e)}")
|
| | except Exception as e:
|
| | st.error(f"Unexpected error: {e}")
|
| |
|