Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +45 -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,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for property features
|
| 12 |
+
|
| 13 |
+
Product_Weight = st.number_input("Enter Product Weight", min_value=0.0, value=1.0)
|
| 14 |
+
Product_Allocated_Area = st.number_input("Enter Product Allocated Area", min_value=0.0, value=1.0)
|
| 15 |
+
Product_MRP = st.number_input("Enter Product MRP", min_value=0.0, value=1.0)
|
| 16 |
+
Store_Established_Year = st.number_input("Enter Store Established Year", min_value=1980, value=1987, max_value=2025)# [2009 1999 1987 1998]
|
| 17 |
+
Product_Sugar_Content = st.selectbox("Select Product Sugar Content", ["No Sugar", "Low Sugar", "Regular"])
|
| 18 |
+
Store_Size = st.selectbox("Select Product Sugar Content", ["Small", "Medium", "High"])
|
| 19 |
+
Store_Location_City_Type = st.selectbox("Select Store Location City Type ", ["Tier 3", "Tier 2", "Tier 1"])
|
| 20 |
+
Product_Type = st.selectbox("Select Product Type ", ["Product_Type","Fruits and Vegetables","Snack Foods","Frozen Foods","Dairy","Household","Baking Goods","Canned","Health and Hygiene","Meat","Soft Drinks","Breads","Hard Drinks ","Others","Starchy Foods","Breakfast","Seafood" ])
|
| 21 |
+
Store_Type = st.selectbox("Select Store Type ", ["Supermarket Type2", "Supermarket Type1", "Departmental Store","Food Mart"])
|
| 22 |
+
Store_Id = st.selectbox("Select Store Id ", ["OUT001", "OUT002", "OUT003","OUT004"])
|
| 23 |
+
|
| 24 |
+
# Convert user input into a DataFrame
|
| 25 |
+
input_data = pd.DataFrame([{
|
| 26 |
+
"Product_Weight": Product_Weight,
|
| 27 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 28 |
+
"Product_MRP": Product_MRP,
|
| 29 |
+
"Store_Established_Year": Store_Established_Year,
|
| 30 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 31 |
+
"Store_Size": Store_Size,
|
| 32 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 33 |
+
"Product_Type": Product_Type,
|
| 34 |
+
"Store_Type": Store_Type,
|
| 35 |
+
"Store_Id" :Store_Id
|
| 36 |
+
}])
|
| 37 |
+
|
| 38 |
+
# Make prediction when the "Predict" button is clicked setuagrawal/salespredictorbackend
|
| 39 |
+
if st.button("Predict"):
|
| 40 |
+
response = requests.post("https://setuagrawal-salespredictorbackend.hf.space/v1/productsales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 41 |
+
if response.status_code == 200:
|
| 42 |
+
prediction = response.json()['prediction']
|
| 43 |
+
st.success(f"Predicted Sales Value: {prediction}")
|
| 44 |
+
else:
|
| 45 |
+
st.error("Error making prediction.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|