Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +79 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
+
RUN pip3 install -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
| 15 |
+
|
| 16 |
+
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("Superkart product sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for product features
|
| 12 |
+
Product_Id = st.text_input("Product ID", value="PROD001")
|
| 13 |
+
Product_Weight = st.number_input("Product Weight",min_value=1, step=1, value=0)
|
| 14 |
+
Product_Sugar_Content = st.selectbox("Sugar content", ['Low Sugar', 'Regular', 'No Sugar'])
|
| 15 |
+
Product_Allocated_Area = st.number_input("Product_Allocated_Area", min_value=1, step=1, value=0)
|
| 16 |
+
Product_Type = st.selectbox("Product Type", [
|
| 17 |
+
'Meat', 'Snack Foods', 'Hard Drinks', 'Dairy', 'Canned', 'Soft Drinks',
|
| 18 |
+
'Health and Hygiene', 'Baking Goods', 'Bread', 'Breakfast', 'Frozen Foods',
|
| 19 |
+
'Fruits and Vegetables', 'Household', 'Seafood', 'Starchy Foods', 'Others'
|
| 20 |
+
] )
|
| 21 |
+
Product_MRP = st.number_input("Product_MRP", min_value=1, step=0.1, value=0)
|
| 22 |
+
Store_Id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
|
| 23 |
+
Store_Establishment_Year = st.number_input("Store Established Year", min_value=1900, max_value=2050, step=1, value=2025)
|
| 24 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High" ])
|
| 25 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type",["Tier 1", "Tier 2", "Tier 3"])
|
| 26 |
+
Store_Type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Convert user input into a DataFrame
|
| 30 |
+
input_data = pd.DataFrame([{
|
| 31 |
+
"Product_Id": Product_Id,
|
| 32 |
+
'Product_Weight': Product_Weight,
|
| 33 |
+
'Product_Sugar_Content': Product_Sugar_Content,
|
| 34 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 35 |
+
'Product_Type': Product_Type,
|
| 36 |
+
'Product_MRP': Product_MRP,
|
| 37 |
+
'Store_Id': Store_Id,
|
| 38 |
+
'Store_Establishment_Year': Store_Establishment_Year,
|
| 39 |
+
'Store_Size': Store_Size,
|
| 40 |
+
'Store_Location_City_Type': Store_Location_City_Type,
|
| 41 |
+
'Store_Type': Store_Type
|
| 42 |
+
}])
|
| 43 |
+
|
| 44 |
+
# Make prediction when the "Predict" button is clicked
|
| 45 |
+
if st.button("Predict Sales"):
|
| 46 |
+
try:
|
| 47 |
+
response = requests.post(
|
| 48 |
+
"https://JohnsonSAimlarge-Salesforecastprediction.hf.space/v1/sales",
|
| 49 |
+
json=input_data.to_dict(orient='records')[0]
|
| 50 |
+
)
|
| 51 |
+
if response.status_code == 200:
|
| 52 |
+
predicted = response.json()['Sales']
|
| 53 |
+
st.success(f"💰 Predicted Sales: ₹{predicted}")
|
| 54 |
+
else:
|
| 55 |
+
st.error(f"❌ Backend error: {response.text}")
|
| 56 |
+
except Exception as e:
|
| 57 |
+
st.error(f"⚠️ Request failed: {e}")
|
| 58 |
+
|
| 59 |
+
# Section: Batch prediction
|
| 60 |
+
st.subheader("📄 Batch Prediction (CSV Upload)")
|
| 61 |
+
|
| 62 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 63 |
+
|
| 64 |
+
if uploaded_file is not None:
|
| 65 |
+
if st.button("Predict Batch Sales"):
|
| 66 |
+
try:
|
| 67 |
+
response = requests.post(
|
| 68 |
+
"https://JohnsonSAimlarge-Salesforecastprediction.hf.space/v1/salesbatch",
|
| 69 |
+
files={"file": uploaded_file}
|
| 70 |
+
)
|
| 71 |
+
if response.status_code == 200:
|
| 72 |
+
results = response.json()
|
| 73 |
+
st.success("✅ Batch predictions received!")
|
| 74 |
+
st.write(pd.DataFrame(results.items(), columns=["Product ID", "Predicted Sales (₹)"]))
|
| 75 |
+
else:
|
| 76 |
+
st.error(f"❌ Backend error: {response.text}")
|
| 77 |
+
except Exception as e:
|
| 78 |
+
st.error(f"⚠️ Request failed: {e}")
|
| 79 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|