u2jyothibhat commited on
Commit
fcfaea1
·
verified ·
1 Parent(s): 85967e9

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -13
  2. app.py +70 -0
  3. requirements.txt +11 -3
Dockerfile CHANGED
@@ -1,20 +1,16 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
 
14
  RUN pip3 install -r requirements.txt
15
 
16
- EXPOSE 8501
17
-
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
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,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import datetime
4
+ import joblib # For loading the serialized model
5
+ import pandas as pd # For data manipulation
6
+ from flask import Flask, request, jsonify # For creating the Flask API
7
+ import numpy as np
8
+ from sklearn.base import BaseEstimator, TransformerMixin
9
+ from sklearn.preprocessing import PowerTransformer, OrdinalEncoder
10
+ from sklearn.pipeline import Pipeline
11
+ from sklearn.compose import ColumnTransformer
12
+
13
+
14
+ # Set the title of the Streamlit app
15
+ st.title("SuperKart sales Prediction")
16
+
17
+ # Section for online prediction
18
+ st.subheader("Online Prediction")
19
+
20
+ # cyear = datetime.now().year
21
+ cyear=2025
22
+
23
+ #--------------------------------------------TESTING (Model without REST)-----------------------------------------------
24
+
25
+ print( " Trying to load XGBoost model using joblib")
26
+ model = joblib.load("XGBoost_best_model.joblib")
27
+
28
+ print("Model loaded successfully!")
29
+
30
+ #--------------------------------------------TESTING (Model without REST)-----------------------------------------------------
31
+
32
+ # Collect user input for property features
33
+ pwt = st.number_input("Product Weight", min_value=0.1, value=100.0)
34
+ paa = st.number_input("Product_Allocated_Area (Ratio of product area to Total Area)", min_value=0.001, max_value=0.999, value=0.2)
35
+ psc = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
36
+ ptyp = st.selectbox("Product Type", ['Fruits and Vegetables', 'Snack Foods', 'Frozen Foods', 'Dairy',
37
+ 'Household', 'Baking Goods', 'Canned', 'Health and Hygiene',
38
+ 'Meat', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others',
39
+ 'Starchy Foods', 'Breakfast', 'Seafood'])
40
+ ssize = st.selectbox("Store Size", ['Small', 'Medium', 'High'])
41
+ sloctype = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 2', 'Tier 3'])
42
+ styp = st.selectbox("Store Type", ['Supermarket Type2', 'Supermarket Type1', 'Departmental Store', 'Food Mart'])
43
+ # pid_c2 = st.selectbox("pid_c2", ['FD', 'DR', 'NC'])
44
+ pmrp = st.number_input("Product MRP", min_value=0.1, value=100.0)
45
+ seyr_i = st.number_input("Store Establishment Year", min_value=1987, step=1, max_value=cyear, value=2025)
46
+ seyr = str(seyr_i)
47
+
48
+ # Convert user input into a DataFrame
49
+ input_data = pd.DataFrame([{
50
+ 'Product_Weight': pwt,
51
+ 'Product_Allocated_Area': paa,
52
+ 'Product_MRP': pmrp,
53
+ 'Product_Sugar_Content': psc,
54
+ 'Product_Type': ptyp,
55
+ 'Store_Establishment_Year': seyr,
56
+ 'Store_Size': ssize,
57
+ # 'pid_c2':pid_c2,
58
+ 'Store_Location_City_Type': sloctype,
59
+ 'Store_Type': styp
60
+ }])
61
+
62
+ # Make prediction when the "Predict" button is clicked
63
+ if st.button("Predict"):
64
+ print("payload = ", input_data.to_dict(orient='records')[0])
65
+ response = requests.post("https://u2jyothibhat-SuperKart-Backend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0])
66
+ if response.status_code == 200:
67
+ prediction = response.json()['Predicted Sales']
68
+ st.success(f"Predicted Sales: {prediction}")
69
+ else:
70
+ st.error("Error making prediction.")
requirements.txt CHANGED
@@ -1,3 +1,11 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.4.2
6
+ Werkzeug==2.2.2
7
+ flask==2.2.2
8
+ gunicorn==20.1.0
9
+ requests==2.28.1
10
+ uvicorn[standard]
11
+ streamlit==1.43.2