R-autowired commited on
Commit
cdc7950
·
verified ·
1 Parent(s): 3600ebd

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +53 -0
  3. requirements.txt +6 -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,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import joblib
5
+ import numpy as np
6
+
7
+ # Load the trained model
8
+ @st.cache_resource
9
+ def load_model():
10
+ return joblib.load("deployment_files/backend_files/product_sales_prediction_model_rf_tuned_v2_0.joblib")
11
+
12
+ model = load_model()
13
+
14
+ # Streamlit UI for Price Prediction
15
+ st.title("Product Sales Prediction App")
16
+ st.write("This tool predicts the price of an products listing based on the given details.")
17
+
18
+ st.subheader("Enter the listing details:")
19
+
20
+ # Collect user input
21
+ Product_Sugar_Content = st.selectbox("Sugar Content", ["Regular", "Low Sugar", "No Sugar"])
22
+ Product_Weight = st.number_input("Product Weights (grams)", min_value=0, max_value=25, format="%.2f", value=15.0, step=0.01)
23
+ Product_Allocated_Area = st.number_input("Product Allocated Area (Sq.Ft)", min_value=0,max_value=0.3, step=0.01, value=0.20, format="%.2f")
24
+ Product_MRP = st.number_input("Product Price ($) ", min_value=0, max_value=300, step=1, value=100, format="%.2f")
25
+ Store_Size = st.selectbox("Store Size", ["High", "Medium", "Small"])
26
+ Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
27
+ Store_Type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", "Departmental Store"])
28
+ Product_Id_Code = st.selectbox("Product ID Code ", ["FD", "DR", "NC"])
29
+ Product_Type_Category = st.selectbox("Product Type Category ", ["Non Perishables", "Perishables"])
30
+ Store_Age_Years = st.number_input("Age of the store ? ", min_value=0, max_value=50, value=15, step=1)
31
+
32
+ # Convert user input into a DataFrame
33
+ input_data = pd.DataFrame([{
34
+ 'Product_Sugar_Content': Product_Sugar_Content,
35
+ 'Product_Weight': Product_Weight,
36
+ 'Product_Allocated_Area': Product_Allocated_Area,
37
+ 'Product_MRP': Product_MRP,
38
+ 'Store_Size': Store_Size,
39
+ 'Store_Location_City_Type': Store_Location_City_Type,
40
+ 'Store_Type': Store_Type,
41
+ 'Product_Id_Code': Product_Id_Code,
42
+ 'Product_Type_Category': Product_Type_Category,
43
+ 'Store_Age_Years': Store_Age_Years
44
+ }])
45
+
46
+ # Make prediction when the "Predict" button is clicked
47
+ if st.button("Predict"):
48
+ response = requests.post("https://R-autowired-ProductSalesPredictionBackend.hf.space/v1/salespredict", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
49
+ if response.status_code == 200:
50
+ prediction = response.json()['Predicted Price (in dollars)']
51
+ st.success(f"Predicted Rental Price (in dollars): {prediction}")
52
+ else:
53
+ st.error("Error making prediction.")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
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
+ streamlit==1.43.2