Lokiiparihar commited on
Commit
4cd2f8b
·
verified ·
1 Parent(s): 569626e

Update Streamlit app

Browse files
Files changed (2) hide show
  1. Dockerfile +9 -13
  2. app.py +54 -0
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.11.7-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,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # Streamlit UI for Customer Churn Prediction
6
+ st.title("Sales Prediction App")
7
+ st.write("This tool predicts SupeKaet Sales. Enter the required information below.")
8
+
9
+ # Model Choice
10
+ model_choice = st.selectbox(
11
+ "Select Model",
12
+ options=["dt", "xgb"],
13
+ format_func=lambda x: "Decision Tree" if x == "dt" else "XGBoost"
14
+ )
15
+
16
+ # Collect user input based on dataset columns
17
+
18
+ product_weight = st.number_input("Product Weight", min_value=0.0)
19
+ sugar = st.selectbox("Sugar Content", [0, 1, 2])
20
+ area = st.number_input("Allocated Area", min_value=0.0)
21
+ product_type = st.number_input("Product Type Code", min_value=0)
22
+ mrp = st.number_input("Product MRP", min_value=0.0)
23
+ store_size = st.selectbox("Store Size Code", [0, 1, 2])
24
+ city = st.selectbox("City Type Code", [0, 1, 2])
25
+ store_type = st.number_input("Store Type Code", min_value=0)
26
+ store_age = st.number_input("Store Age", min_value=0)
27
+
28
+ # Convert categorical inputs to match model training
29
+ sample = {
30
+ "model": model_choice,
31
+ "Product_Weight": product_weight,
32
+ "Product_Sugar_Content": sugar,
33
+ "Product_Allocated_Area": area,
34
+ "Product_Type": product_type,
35
+ "Product_MRP": mrp,
36
+ "Store_Size": store_size,
37
+ "Store_Location_City_Type": city,
38
+ "Store_Type": store_type,
39
+ "Store_Age": store_age
40
+
41
+ }
42
+
43
+ if st.button("Predict", type='primary'):
44
+ response = requests.post("https://Lokiiparihar-Sample.hf.space/predict", json=sample) # enter user name and space name before running the cell
45
+ if response.status_code == 200:
46
+ result = response.json()
47
+ sales_prediction = result["Prediction"] # Extract only the value
48
+ st.write(f"Based on the information provided, the sale is likely to {sales_prediction}.")
49
+ else:
50
+ st.error("Error in API request")
51
+
52
+ # Run the Flask app in debug mode
53
+ if __name__ == '__main__':
54
+ app.run(debug=True)