SURESHBEEKHANI commited on
Commit
424bbc5
·
verified ·
1 Parent(s): a7924dc

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +29 -0
  2. app.py +56 -0
  3. requirements.txt +14 -0
Dockerfile ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12
2
+
3
+ ## set the working directory to /code
4
+ WORKDIR /code
5
+
6
+ ## Copy the current directory contents in the container at /code
7
+ COPY ./requirements.txt /code/requirements.txt
8
+
9
+ ## Install the requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ # Set up a new user named "user"
13
+ RUN useradd user
14
+ # Switch to the "user" user
15
+ USER user
16
+
17
+ # Set home to the user's home directory
18
+
19
+ ENV HOME=/home/user \
20
+ PATH=/home/user/.local/bin:$PATH
21
+
22
+ # Set the working directory to the user's home directory
23
+ WORKDIR $HOME/app
24
+
25
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
26
+ COPY --chown=user . $HOME/app
27
+
28
+ ## Start the FASTAPI App on port 7860
29
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from src.pipelines.prediction_pipeline import CustomData, PredictPipeline
3
+ from src.exception import CustomException
4
+
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/')
8
+ def index():
9
+ return render_template('index.html')
10
+
11
+ @app.route('/predict', methods=['POST'])
12
+ def predict_route():
13
+ try:
14
+ # Get the form data from the request
15
+ data = request.form
16
+
17
+ # Extract values safely from the incoming form data
18
+ custom_data = CustomData(
19
+ age=data.get("age"),
20
+ sex=data.get("sex"),
21
+ chest_pain_type=data.get("chestPainType"),
22
+ resting_bp=data.get("restingBP"),
23
+ cholesterol=data.get("cholesterol"),
24
+ fasting_bs=data.get("fastingBS"),
25
+ resting_ecg=data.get("restingECG"),
26
+ max_hr=data.get("maxHR"),
27
+ oldpeak=data.get("oldpeak"),
28
+ exercise_angina=data.get("exerciseAngina"),
29
+ st_slope=data.get("stSlope")
30
+ )
31
+
32
+ # Convert to DataFrame
33
+ input_df = custom_data.get_data_as_dataframe()
34
+
35
+ # Create a PredictPipeline instance and make a prediction
36
+ prediction_pipeline = PredictPipeline()
37
+ prediction = prediction_pipeline.predict(input_df)
38
+
39
+ # Condition to check if prediction equals 1
40
+ if prediction[0] == 1:
41
+ result_message = "You are at moderate risk of experiencing a heart attack"
42
+ else:
43
+ result_message = "There are no immediate risk factors for a heart attack"
44
+
45
+ # Pass the result message back to the template for display
46
+ return render_template('index.html', results=result_message)
47
+
48
+ except ValueError as ve:
49
+ return jsonify({"error": str(ve)}), 400
50
+ except CustomException as ce:
51
+ return jsonify({"error": str(ce)}), 500
52
+ except Exception as e:
53
+ return jsonify({"error": "An error occurred: " + str(e)}), 500
54
+
55
+ if __name__ == '__main__':
56
+ app.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ numpy
2
+ pandas
3
+ matplotlib
4
+ seaborn
5
+ scikit-learn
6
+ ipykernel
7
+ catboost
8
+ xgboost
9
+ dill
10
+ flask
11
+ flask_cors
12
+ lime
13
+ gunicorn
14
+ #-e .