Quantum9999's picture
Upload folder using huggingface_hub
e475cbe verified
import streamlit as st
import pandas as pd
import requests
# Title
st.title("Retail Sales Prediction")
# ---------------------------
# Section: Online Prediction
# ---------------------------
st.subheader("Online Prediction")
# Collect user input
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2100, value=2000)
Product_MRP = st.number_input("Product MRP", min_value=0.0, value=100.0, step=1.0)
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=10.0, step=0.1)
Store_Id = st.selectbox("Store ID", ["OUT004", "OUT001", "OUT003", "OUT002"])
Product_Type = 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"
])
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 2", "Tier 1", "Tier 3"])
Store_Size = st.selectbox("Store Size", ["Medium", "High", "Small"])
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, value=50.0, step=1.0)
Product_Id = st.text_input("Product ID (Unique Code)", "FD6114")
Store_Type = st.selectbox("Store Type", ["Supermarket Type2", "Supermarket Type1", "Departmental Store", "Food Mart"])
# Convert user input into DataFrame
input_data = pd.DataFrame([{
'Store_Establishment_Year': Store_Establishment_Year,
'Product_MRP': Product_MRP,
'Product_Weight': Product_Weight,
'Store_Id': Store_Id,
'Product_Type': Product_Type,
'Product_Sugar_Content': Product_Sugar_Content,
'Store_Location_City_Type': Store_Location_City_Type,
'Store_Size': Store_Size,
'Product_Allocated_Area': Product_Allocated_Area,
'Product_Id': Product_Id,
'Store_Type': Store_Type
}])
# Call backend for prediction
if st.button("Predict Sales"):
response = requests.post(
"https://Quantum9999-RetailSlesPredictionBackend.hf.space/v1/sales",
json=input_data.to_dict(orient='records')[0]
)
if response.status_code == 200:
prediction = response.json()['Predicted_Sales']
st.success(f"Predicted Sales: {prediction}")
else:
st.error("Error making prediction.")
# ---------------------------
# Section: Batch Prediction
# ---------------------------
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 Sales"):
response = requests.post(
"https://Quantum9999-RetailSlesPredictionBackend.hf.space/v1/salesbatch",
files={"file": uploaded_file}
)
if response.status_code == 200:
predictions = response.json() # This is a dict of {id: prediction}
st.success("Batch predictions completed!")
st.write(predictions) # Display all predictions
else:
st.error(f"Error making prediction: {response.text}")