harishsohani commited on
Commit
3fcc5b1
·
verified ·
1 Parent(s): 4fab6d0

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -13
  2. app.py +58 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,21 +1,16 @@
 
1
  FROM python:3.9-slim
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- software-properties-common \
9
- git \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
14
 
 
15
  RUN pip3 install -r requirements.txt
16
 
17
- EXPOSE 8501
18
-
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
 
21
- 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,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+ st.title ("Customer Churn Prediction - Week1")
6
+
7
+ st.write ("This tool predicts customer churn risk based on their details. Enter the required information below.")
8
+
9
+ # Collect user input based on dataset columns
10
+ CustId = st.text_input ("Customer ID", value="12345")
11
+ Age = st.number_input ("Age", min_value=0, max_value=200, value=23)
12
+ Partner = st.selectbox ("Does the customer have a partner?", ["Yes", "No"])
13
+ Dependents = st.selectbox ("Does the customer have dependents?", ["Yes", "No"])
14
+ PhoneService = st.selectbox ("Does the customer have phone service?", ["Yes", "No"])
15
+ InternetService = st.selectbox ("Type of Internet Service", ["DSL", "Fiber optic", "No"])
16
+ Contract = st.selectbox ("Type of Contract", ["Month-to-month", "One year", "Two year"])
17
+ PaymentMethod = st.selectbox ("Payment Method", ["Electronic check", "Mailed check", "Bank transfer", "Credit card"])
18
+ Tenure = st.number_input ("Tenure (Months with the company)", min_value=0, value=12)
19
+ MonthlyCharges = st.number_input ("Monthly Charges", min_value=0.0, value=50.0)
20
+ TotalCharges = st.number_input ("Total Charges", min_value=0.0, value=600.0)
21
+
22
+ input_data = pd.DataFrame ([{
23
+ 'customerID': CustId,
24
+ 'SeniorCitizen': 1 if Age > 60 else 0,
25
+ 'tenure': Tenure,
26
+ 'MonthlyCharges': MonthlyCharges,
27
+ 'TotalCharges': TotalCharges,
28
+ 'Partner': Partner,
29
+ 'Dependents': "Yes",
30
+ 'PhoneService': PhoneService,
31
+ 'InternetService': InternetService,
32
+ 'Contract': Contract,
33
+ 'PaymentMethod': PaymentMethod
34
+ }])
35
+
36
+ if st.button("Predict", type='primary'):
37
+ response = requests.post ("https://harishsohani-CustChurnWeek1BackEnd.hf.space/v1/customer", json=customer_data) # enter user name and space name before running the cell
38
+ if response.status_code == 200:
39
+ result = response.json ()
40
+ churn_prediction = result ["Prediction"] # Extract only the value
41
+ st.write (f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")
42
+ else:
43
+ st.error ("Error in API request")
44
+
45
+ # Batch Prediction
46
+ st.subheader ("Batch Prediction - Week1")
47
+
48
+ file = st.file_uploader ("Upload CSV file", type=["csv"])
49
+ if file is not None:
50
+ if st.button("Predict for Batch", type='primary'):
51
+ response = requests.post("https://harishsohani-CustChurnWeek1BackEnd.hf.space/v1/customerbatch", files={"file": file}) # enter user name and space name before running the cell
52
+ if response.status_code == 200:
53
+ result = response.json()
54
+ st.header("Batch Prediction Results")
55
+ st.write(result)
56
+ else:
57
+ st.error("Error in API request")
58
+
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2