Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +65 -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,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.header("SuperKart Product Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Product Sales Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for product and store features
|
| 12 |
+
Product_Weight=st.number_input("Product Weight")
|
| 13 |
+
Product_Sugar_Content=st.selectbox("Product Sugar Content",["Low Sugar","Medium Sugar","High Sugar"])
|
| 14 |
+
Product_Allocated_Area=st.number_input("Product Allocated Area")
|
| 15 |
+
Product_Type=st.selectbox("Product Type",['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods',
|
| 16 |
+
'Health and Hygiene', 'Snack Foods', 'Meat', 'Household',
|
| 17 |
+
'Hard Drinks', 'Fruits and Vegetables', 'Breads', 'Soft Drinks',
|
| 18 |
+
'Breakfast', 'Others', 'Starchy Foods', 'Seafood'])
|
| 19 |
+
Product_MRP=st.number_input("Product MRP")
|
| 20 |
+
Store_Id=st.selectbox("Store Id",['OUT001', 'OUT002', 'OUT003', 'OUT004'])
|
| 21 |
+
Store_Size=st.selectbox("Store Size",['Small', 'Medium', 'High'])
|
| 22 |
+
Store_Location_City_Type=st.selectbox("Store Location City Type",['Tier 1', 'Tier 2', 'Tier 3'])
|
| 23 |
+
Store_Type=st.selectbox("Store Type",['Supermarket Type2', 'Departmental Store', 'Supermarket Type1',
|
| 24 |
+
'Food Mart'])
|
| 25 |
+
Store_Establishment_Year=st.number_input("Store Establishment Year",min_value=1980, max_value=2025, value=1987)
|
| 26 |
+
|
| 27 |
+
# Convert user input into a DataFrame
|
| 28 |
+
input_data=pd.DataFrame([{
|
| 29 |
+
'Product_Weight':Product_Weight,
|
| 30 |
+
'Product_Sugar_Content':Product_Sugar_Content,
|
| 31 |
+
'Product_Allocated_Area':Product_Allocated_Area,
|
| 32 |
+
'Product_Type':Product_Type,
|
| 33 |
+
'Product_MRP':Product_MRP,
|
| 34 |
+
'Store_Id':Store_Id,
|
| 35 |
+
'Store_Size':Store_Size,
|
| 36 |
+
'Store_Location_City_Type':Store_Location_City_Type,
|
| 37 |
+
'Store_Type':Store_Type,
|
| 38 |
+
'Store_Age':2025-Store_Establishment_Year
|
| 39 |
+
}])
|
| 40 |
+
# Make prediction when the "Predict" button is clicked
|
| 41 |
+
if st.button("Predict"):
|
| 42 |
+
response = requests.post("https://Parthi07-SuperKartProductPricePrediction.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0])
|
| 43 |
+
if response.status_code == 200:
|
| 44 |
+
prediction = response.json()['Predicted Product Sales Price']
|
| 45 |
+
st.success(f"Predicted Product Sales Price: {prediction}")
|
| 46 |
+
else:
|
| 47 |
+
st.error(f"Error making prediction: {response.status_code}")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# Section for batch prediction
|
| 51 |
+
st.subheader("Batch Product Sales Prediction")
|
| 52 |
+
|
| 53 |
+
# Allow users to upload a CSV file for batch prediction
|
| 54 |
+
uploaded_file = st.file_uploader("Upload a CSV file for Batch Product Sales Prediction", type=["csv"])
|
| 55 |
+
|
| 56 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 57 |
+
if uploaded_file is not None:
|
| 58 |
+
if st.button("Predict Batch"):
|
| 59 |
+
response = requests.post("https://Parthi07-SuperKartProductPricePrediction.hf.space/v1/salesbatch", files={'file': uploaded_file})
|
| 60 |
+
if response.status_code == 200:
|
| 61 |
+
prediction = response.json()
|
| 62 |
+
st.success("Batch Product Sales Prediction Successful!")
|
| 63 |
+
st.write(prediction)
|
| 64 |
+
else:
|
| 65 |
+
st.error(f"Error making batch prediction: {response.status_code}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.32.3
|
| 3 |
+
streamlit==1.43.2
|