RedRooster99 commited on
Commit
0997dbc
·
verified ·
1 Parent(s): 5fb9733

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -14
  2. app.py +58 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,20 +1,14 @@
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"]
 
 
 
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # Streamlit UI for Customer Churn Prediction
6
+ st.title("Telecom Customer Churn Prediction App")
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
+ CustomerID = st.number_input("Customer ID", min_value=10000000, max_value=99999999)
11
+ SeniorCitizen = st.selectbox("Senior citizen", ["Yes", "No"])
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
+ # Convert categorical inputs to match model training
23
+ customer_data = {
24
+ 'SeniorCitizen': 1 if SeniorCitizen == "Yes" else 0,
25
+ 'Partner':Partner,
26
+ 'Dependents': Dependents,
27
+ 'tenure': tenure,
28
+ 'PhoneService': PhoneService,
29
+ 'InternetService': InternetService,
30
+ 'Contract': Contract,
31
+ 'PaymentMethod': PaymentMethod,
32
+ 'MonthlyCharges': MonthlyCharges,
33
+ 'TotalCharges': TotalCharges
34
+ }
35
+
36
+
37
+ if st.button("Predict", type='primary'):
38
+ response = requests.post("https://RedRooster99-week2guidedhandsonbackendspace.hf.space/v1/customer", json=customer_data) # enter user name and space name before running the cell
39
+ if response.status_code == 200:
40
+ result = response.json()
41
+ churn_prediction = result["Prediction"] # Extract only the value
42
+ st.write(f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")
43
+ else:
44
+ st.error("Error in API request")
45
+
46
+ # Batch Prediction
47
+ st.subheader("Batch Prediction")
48
+
49
+ file = st.file_uploader("Upload CSV file", type=["csv"])
50
+ if file is not None:
51
+ if st.button("Predict for Batch", type='primary'):
52
+ response = requests.post("https://RedRooster99-week2guidedhandsonbackendspace.hf.space/v1/customerbatch", files={"file": file}) # enter user name and space name before running the cell
53
+ if response.status_code == 200:
54
+ result = response.json()
55
+ st.header("Batch Prediction Results")
56
+ st.write(result)
57
+ else:
58
+ st.error("Error in API request")
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