nbhoite9988's picture
Upload folder using huggingface_hub
742fdb5 verified
import streamlit as st
import pandas as pd
import requests
# Streamlit UI for Product sales revenue Prediction
st.title("Product Sales Revenue Prediction App")
st.write("This tool predicts the revenue generated by sale of a particular product in particular store.")
st.subheader("Enter the product details:")
# Collect user input based on dataset columns
Product_Id = st.text_input("Product_Id", placeholder="Enter product id")
Product_Weight = st.number_input("Product Weight", min_value=1.0, value=12.2)
Product_Sugar_Content = st.selectbox("Product Sugar Content", ['No Sugar', 'Low Sugar', 'Regular'])
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.001, max_value=1.0, value=0.056)
Product_Type = st.selectbox("Product Type", ['Household',
'Frozen Foods',
'Snack Foods',
'Canned',
'Baking Goods',
'Breads',
'Fruits and Vegetables',
'Dairy',
'Health and Hygiene',
'Meat',
'Hard Drinks',
'Soft Drinks',
'Starchy Foods',
'Others',
'Breakfast',
'Seafood'])
Product_MRP = st.number_input("Product_MRP", min_value=1, value=147)
Store_Id = st.selectbox("Store_Id", ['OUT004', 'OUT001', 'OUT003', 'OUT002'])
Store_Establishment_Year = st.selectbox("Store_Establishment_Year", [2009, 1987, 1999, 1998])
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', 'Supermarket Type1', 'Departmental Store', 'Food Mart'])
# Convert user inputs to match model training
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
}
# Make prediction when the "Predict" button is clicked
if st.button("Predict", type='primary'):
response = requests.post("https://nbhoite9988-ProductSalesRevenuePredictionBackend.hf.space/v1/sales", json=input_data) # enter user name and space name before running the cell
if response.status_code == 200:
result = response.json()
sales_revenue_prediction = result["Prediction"] # Extract only the value
st.write(f"Based on the information provided, the product with ID {Product_Id} is likely to generate sales revenue: {sales_revenue_prediction}.")
else:
st.error("Error in API request")
# Batch Prediction
st.subheader("Batch Prediction")
file = st.file_uploader("Upload CSV file", type=["csv"])
if file is not None:
if st.button("Predict for Batch", type='primary'):
response = requests.post("https://nbhoite9988-ProductSalesRevenuePredictionBackend.hf.space/v1/salesbatch", files={"file": file}) # enter user name and space name before running the cell
if response.status_code == 200:
result = response.json()
st.header("Batch Prediction Results")
st.write(result)
else:
st.error("Error in API request")