krishpvg commited on
Commit
1506aa3
·
verified ·
1 Parent(s): e6c6c43

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -15
  2. app.py +56 -0
  3. requirements.txt +10 -3
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
+ FROM python:3.9-slim
2
 
3
+ # Set the working directory inside the container
4
  WORKDIR /app
5
 
6
+ # Copy all files from the current directory to the container's working directory
7
+ COPY . .
 
 
 
8
 
9
+ # Install dependencies from the requirements file without using cache to reduce image size
10
+ RUN pip install --no-cache-dir -r requirements.txt
11
 
12
+ # Define the command to start the application using Gunicorn with 4 worker processes
13
+ # - `-w 4`: Uses 4 worker processes for handling requests
14
+ # - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
15
+ # - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
16
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
 
 
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ from flask import Flask, request, jsonify
4
+
5
+ app = Flask("Telecom Customer Churn Predictor")
6
+ model = joblib.load("churn_prediction_model_v1_0.joblib")
7
+
8
+ @app.get('/')
9
+ def home():
10
+ return "Welcome to the Telecom Customer Churn Prediction API"
11
+
12
+ @app.post('/customer/v1')
13
+ def predict_churn():
14
+ cutomer_data = request.get_json()
15
+
16
+ sample = {
17
+ 'SeniorCitizen': customer_data['SeniorCitizen'],
18
+ 'Partner': customer_data['Partner'],
19
+ 'Dependents': customer_data['Dependents'],
20
+ 'tenure': customer_data['tenure'],
21
+ 'PhoneService': customer_data['PhoneService'],
22
+ 'InternetService': customer_data['InternetService'],
23
+ 'Contract': customer_data['Contract'],
24
+ 'PaymentMethod': customer_data['PaymentMethod'],
25
+ 'MonthlyCharges': customer_data['MonthlyCharges'],
26
+ 'TotalCharges': customer_data['TotalCharges']
27
+
28
+ }
29
+ input_data = pd.DataFrame([sample])
30
+
31
+ prediction = model.predict(input_data).tolist()[0]
32
+ prediction_label = "churn" if prediction == 1 else "not churn"
33
+ return jsonify({'prediction': predxition_label})
34
+
35
+ @app.post('/v1/customerbatch')
36
+ def predict_churn_batch():
37
+ # Get the uploaded CSV file from the request
38
+ file = request.files['file']
39
+
40
+ # Read the file into a DataFrame
41
+ input_data = pd.read_csv(file)
42
+
43
+ # Make predictions for the batch data and convert raw predictions into a readable format
44
+ predictions = [
45
+ 'Churn' if x == 1
46
+ else "Not Churn"
47
+ for x in model.predict(input_data.drop("customerID",axis=1)).tolist()
48
+ ]
49
+
50
+ cust_id_list = input_data.customerID.values.tolist()
51
+ output_dict = dict(zip(cust_id_list, predictions))
52
+
53
+ return output_dict
54
+
55
+ if __name__ == '__main__':
56
+ app.run(debug=True)
requirements.txt CHANGED
@@ -1,3 +1,10 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
 
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
+ Werkzeug==2.2.2
7
+ flask==2.2.2
8
+ gunicorn==20.1.0
9
+ requests==2.28.1
10
+ uvicorn[standard]