front_end_files / app.py
Enoch1359's picture
Upload folder using huggingface_hub
e9d2050 verified
raw
history blame
2.85 kB
import pandas as pd
import requests
import streamlit as st
st.title('SuperKart Sale Prediction')
# Inputs for prediction
Product_Weight = st.number_input('Product_Weight', value=15.46)
Product_Sugar_Content = st.selectbox('Product_Sugar_Content', ['No Sugar', 'Low Sugar', 'Regular', 'reg'], index=0)
Product_Allocated_Area = st.number_input('Product_Allocated_Area', value=0.026)
Product_Type = st.selectbox('Product_Type', ['Household', 'Soft Drinks', 'Fruits and Vegetables',
'Baking Goods', 'Meat', 'Dairy', 'Canned', 'Snack Foods',
'Frozen Foods', 'Health and Hygiene', 'Breads', 'Hard Drinks',
'Others', 'Starchy Foods', 'Breakfast', 'Seafood'], index=0)
Product_MRP = st.number_input('Product_MRP', value=171.83)
Store_Id = st.selectbox('Store_Id', ['OUT001', 'OUT003', 'OUT004', 'OUT002'], index=0)
Store_Establishment_Year = st.selectbox('Store_Establishment_Year',[1987,1998,1999,2009], index=0)
Store_Size = st.selectbox('Store_Size', ['Small', 'Medium', 'High'], index=0)
Store_Location_City_Type = st.selectbox('Store_Location_City_Type', ['Tier 1', 'Tier 2', 'Tier 3'], index=1)
Store_Type = st.selectbox('Store_Type', ['Supermarket Type1', 'Departmental Store', 'Supermarket Type2', 'Food Mart'], index=0)
# Create input data as DataFrame
input_data = pd.DataFrame([{
'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,
}])
# Single prediction
if st.button('Predict'):
response = requests.post(
'https://enoch1359-back-end-files.hf.space/v1/spkart_single',
json=input_data.to_dict(orient='records')[0]
)
if response.status_code == 200:
prediction = response.json()
st.success(f"Predicted Sale: {prediction['Sale']}")
else:
st.error(f"Error making prediction: {response.text}")
# Batch prediction
st.subheader('Batch Prediction')
uploaded_file = st.file_uploader('Upload a CSV file', type=['csv'])
if uploaded_file is not None:
if st.button('Predict Batch'):
response = requests.post(
'https://enoch1359-back-end-files.hf.space/v1/spkart_batch',
files={'file': uploaded_file}
)
if response.status_code == 200:
predictions = response.json()
st.success("Batch predictions completed!")
st.json(predictions)
else:
st.error(f"Error making batch prediction: {response.text}")