cnaditoka's picture
Upload folder using huggingface_hub
e9d321c verified
Raw
History Blame Contribute Delete
2.92 kB
import requests
import streamlit as st
import pandas as pd
st.title("SuperKart Sales Revenue Prediction")
# Single Prediction
st.subheader("Single Prediction")
# Input fields for product data
Product_Weight = st.number_input("weight of each product", min_value=0.0, value=0.0)
Product_Sugar_Content = st.selectbox("sugar content of each product", ["Low Sugar", "Regular", "No Sugar"])
Product_Allocated_Area = st.number_input("allocated display area of each product", min_value=0.0, value=0.0)
Product_Type = st.text_input("broad category for each product")
Product_MRP = st.number_input("maximum retail price of each product", min_value=0.0, value=0.0)
Store_Id = st.text_input("unique identifier of each store")
Store_Establishment_Year = st.number_input("year in which the store was established", min_value=1900, max_value=2030, value=1990)
Store_Size = st.selectbox("size of the store depending on sq. feet", ["High", "Medium", "Small"])
Store_Location_City_Type = st.selectbox("type of city in which the store is located", ["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.selectbox("type of store depending on the products that are being sold there", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
# Convert user input into a DataFrame
input_data = {
'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://cnaditoka-SuperKartModelBackend.hf.space/v1/sales_revenue", json=input_data)
if response.status_code == 200:
result = response.json()
predicted_sales_revenue = result["predicted_sales_revenue"] # Extract only the value
st.success(f"Predicted Sales Revenue (in dollars): {predicted_sales_revenue}")
else:
st.error("Error making prediction.")
# Batch Prediction
st.subheader("Batch Prediction")
# Allow users to upload a CSV file for batch prediction
file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
# Make batch prediction when the "Predict for Batch" button is clicked
if file is not None:
if st.button("Predict for Batch", type='primary'):
response = requests.post("https://cnaditoka-SuperKartModelBackend.hf.space/v1/sales_revenue_batch", files={"file": file})
if response.status_code == 200:
result = response.json()
st.success("Batch predictions completed!")
st.write(result)
else:
st.error("Error making batch prediction.")