Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +64 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.title("Super Kart Store Total Sale Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for property features
|
| 12 |
+
Product_Weight = st.number_input("Product Weight", min_value=4.0, max_value=22.0, step=0.1, value=10.0)
|
| 13 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.004, max_value=0.298, step=0.01, value=0.22)
|
| 14 |
+
Product_MRP = st.number_input("Product MRP", min_value=31.0, max_value=266.0, step=0.5, value=10.0)
|
| 15 |
+
Store_Establishment_Year = st.selectbox("Store Establishment Year", [1987, 1998, 1999, 2009])
|
| 16 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
|
| 17 |
+
Product_Type = st.selectbox("Product Type", [
|
| 18 |
+
"Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household", "Baking Goods", "Canned",
|
| 19 |
+
"Health and Hygiene", "Meat", "Soft Drinks", "Breads", "Hard Drinks", "Starchy Foods", "Breakfast", "Seafood", "Others"
|
| 20 |
+
])
|
| 21 |
+
Store_Size = st.selectbox("Store Size", ["Medium", "High", "Small"])
|
| 22 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 23 |
+
Store_Type = st.selectbox("Store Type", [
|
| 24 |
+
"Departmental Store", "Food Mart", "Supermarket Type1", "Supermarket Type2"
|
| 25 |
+
])
|
| 26 |
+
|
| 27 |
+
# Convert user input into a DataFrame
|
| 28 |
+
input_data = pd.DataFrame([{
|
| 29 |
+
'Product_Weight': Product_Weight,
|
| 30 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 31 |
+
'Product_MRP': Product_MRP,
|
| 32 |
+
'Store_Establishment_Year': Store_Establishment_Year,
|
| 33 |
+
'Product_Sugar_Content': Product_Sugar_Content,
|
| 34 |
+
'Product_Type': Product_Type
|
| 35 |
+
'Store_Size': Store_Size,
|
| 36 |
+
'Store_Location_City_Type': Store_Location_City_Type,
|
| 37 |
+
'Store_Type': Store_Type
|
| 38 |
+
}])
|
| 39 |
+
|
| 40 |
+
# Make prediction when the "Predict" button is clicked
|
| 41 |
+
if st.button("Predict"):
|
| 42 |
+
response = requests.post("https://hkbindhu-superkart.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 43 |
+
if response.status_code == 200:
|
| 44 |
+
prediction = response.json()['Predicted Sales Total (in dollars)']
|
| 45 |
+
st.success(f"Predicted Sales Total (in dollars): {prediction}")
|
| 46 |
+
else:
|
| 47 |
+
st.error("Error making prediction.")
|
| 48 |
+
|
| 49 |
+
# Section for batch prediction
|
| 50 |
+
st.subheader("Batch Prediction")
|
| 51 |
+
|
| 52 |
+
# Allow users to upload a CSV file for batch prediction
|
| 53 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 54 |
+
|
| 55 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 56 |
+
if uploaded_file is not None:
|
| 57 |
+
if st.button("Predict Batch"):
|
| 58 |
+
response = requests.post("https://hkbindhu-superkart.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
|
| 59 |
+
if response.status_code == 200:
|
| 60 |
+
predictions = response.json()
|
| 61 |
+
st.success("Batch predictions completed!")
|
| 62 |
+
st.write(predictions) # Display the predictions
|
| 63 |
+
else:
|
| 64 |
+
st.error("Error making batch prediction.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit
|
| 4 |
+
numpy
|
| 5 |
+
flask
|