MainiSandeep1987 commited on
Commit
fcbe7bd
·
verified ·
1 Parent(s): c964819

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -0
  2. app.py +58 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FROM python:3.9-slim
2
+ # WORKDIR /app
3
+ # COPY . .
4
+ # COPY requirements.txt .
5
+ # COPY app.py .
6
+ # RUN pip install --no-cache-dir --upgrade -r requirements.txt
7
+ # CMD ["streamlit", "run", "app.py", "server.address=0.0.0.0", "server.port=8501"]
8
+ FROM python:3.9-slim
9
+ WORKDIR /app
10
+ COPY requirements.txt .
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+ COPY app.py .
13
+ CMD ["streamlit", "run", "app.py", "--server.port=7861", "--server.address=0.0.0.0"]
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://MainiSandeep1987-FlaskAPITelecomChurnPrediction.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://MainiSandeep1987-FlaskAPITelecomChurnPrediction.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 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2