Flask app build successful but failed to deploy

Hello I have a python flask application which I am currently trying to deploy when I deploy the app i get a build successful message but the deploy fails. The application is an API for my machine learning project i need to deploy the app to get a live URL using render

please I need help I have been stuck for over a week.

below is MY app on github
image_2023-04-28_104542372

below is the code in my python file

from flask import Flask, request, jsonify
import pickle
import numpy as np

model = pickle.load(open(‘model1.pkl’,‘rb’))

app = Flask(name)

@app.route(‘/’)
def home():
return “Stroke Disease Prediction App”

@app.route(‘/predict’,methods=[‘POST’])

#‘cp’,‘thalach’,‘slope’,‘restecg’,‘chol’,‘trestbps’,‘fbs’,‘oldpeak’
#[0,108,1,0,250,160,1,1.5] 0
#[3,150,0,0,233,145,1,2.3] 1

def predict():
cp = request.form.get(‘cp’)
thalach = request.form.get(‘thalach’)
slope = request.form.get(‘slope’)
restecg = request.form.get(‘restecg’)
chol = request.form.get(‘chol’)
trestbps = request.form.get(‘trestbps’)
fbs = request.form.get(‘fbs’)
oldpeak = request.form.get(‘oldpeak’)

#result = {'cp':cp,'thalach':thalach,'slope':slope,'restecg':restecg,'chol':chol,'trestbps':trestbps,'fbs':fbs,'oldpeak':oldpeak}

input_query = np.array([[cp,thalach,slope,restecg,chol,trestbps,fbs,oldpeak]])

result = model.predict(input_query)[0]

return jsonify({'hearth_disease': str(result)})

if name==‘main’:
app.run(debug=True

Below is my requirements.txt

flask
numpy
scikit-learn
gunicorn

below is the error after deploying

Apr 28 10:38:16 AM ==> Cloning from GitHub - HezGee/API
Apr 28 10:38:17 AM ==> Checking out commit 2d507f17923ef6017b08cd6202fdc04dba6b9cc0 in branch main
Apr 28 10:38:21 AM ==> Using Python version: 3.7.10
Apr 28 10:38:24 AM ==> Running build command ‘pip install -r API/requirements.txt’…
Apr 28 10:38:24 AM Collecting flask
Apr 28 10:38:24 AM Downloading Flask-2.2.4-py3-none-any.whl (101 kB)
Apr 28 10:38:25 AM Collecting numpy
Apr 28 10:38:25 AM Downloading numpy-1.21.6-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB)
Apr 28 10:38:27 AM Collecting scikit-learn
Apr 28 10:38:27 AM Downloading scikit_learn-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.8 MB)
Apr 28 10:38:28 AM Collecting gunicorn
Apr 28 10:38:28 AM Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
Apr 28 10:38:28 AM Collecting itsdangerous>=2.0
Apr 28 10:38:28 AM Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Apr 28 10:38:28 AM Collecting Jinja2>=3.0
Apr 28 10:38:28 AM Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
Apr 28 10:38:29 AM Collecting importlib-metadata>=3.6.0; python_version < “3.10”
Apr 28 10:38:29 AM Downloading importlib_metadata-6.6.0-py3-none-any.whl (22 kB)
Apr 28 10:38:29 AM Collecting click>=8.0
Apr 28 10:38:29 AM Downloading click-8.1.3-py3-none-any.whl (96 kB)
Apr 28 10:38:29 AM Collecting Werkzeug>=2.2.2
Apr 28 10:38:29 AM Downloading Werkzeug-2.2.3-py3-none-any.whl (233 kB)
Apr 28 10:38:29 AM Collecting threadpoolctl>=2.0.0
Apr 28 10:38:29 AM Downloading threadpoolctl-3.1.0-py3-none-any.whl (14 kB)
Apr 28 10:38:30 AM Collecting scipy>=1.1.0
Apr 28 10:38:30 AM Downloading scipy-1.7.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (38.1 MB)
Apr 28 10:38:30 AM Collecting scipy>=1.1.0
Apr 28 10:38:30 AM Downloading scipy-1.7.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (38.1 MB)
Apr 28 10:38:32 AM Collecting joblib>=0.11
Apr 28 10:38:32 AM Downloading joblib-1.2.0-py3-none-any.whl (297 kB)
Apr 28 10:38:32 AM Requirement already satisfied: setuptools>=3.0 in ./.venv/lib/python3.7/site-packages (from gunicorn->-r API/requirements.txt (line 4)) (47.1.0)
Apr 28 10:38:32 AM Collecting MarkupSafe>=2.0
Apr 28 10:38:32 AM Downloading MarkupSafe-2.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Apr 28 10:38:32 AM Collecting typing-extensions>=3.6.4; python_version < “3.8”
Apr 28 10:38:32 AM Downloading typing_extensions-4.5.0-py3-none-any.whl (27 kB)
Apr 28 10:38:32 AM Collecting zipp>=0.5
Apr 28 10:38:32 AM Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
Apr 28 10:38:33 AM Installing collected packages: itsdangerous, MarkupSafe, Jinja2, typing-extensions, zipp, importlib-metadata, click, Werkzeug, flask, numpy, threadpoolctl, scipy, joblib, scikit-learn, gunicorn
Apr 28 10:38:44 AM Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.2 Werkzeug-2.2.3 click-8.1.3 flask-2.2.4 gunicorn-20.1.0 importlib-metadata-6.6.0 itsdangerous-2.1.2 joblib-1.2.0 numpy-1.21.6 scikit-learn-1.0.2 scipy-1.7.3 threadpoolctl-3.1.0 typing-extensions-4.5.0 zipp-3.15.0
Apr 28 10:38:44 AM WARNING: You are using pip version 20.1.1; however, version 23.1.2 is available.
Apr 28 10:38:44 AM You should consider upgrading via the ‘/opt/render/project/src/.venv/bin/python -m pip install --upgrade pip’ command.
Apr 28 10:38:44 AM ==> Generating container image from build. This may take a few minutes…
Apr 28 10:38:16 AM ==> Cloning from GitHub - HezGee/API
Apr 28 10:38:17 AM ==> Checking out commit 2d507f17923ef6017b08cd6202fdc04dba6b9cc0 in branch main
Apr 28 10:38:21 AM ==> Using Python version: 3.7.10
Apr 28 10:38:24 AM ==> Running build command ‘pip install -r API/requirements.txt’…
Apr 28 10:38:24 AM Collecting flask
Apr 28 10:38:24 AM Downloading Flask-2.2.4-py3-none-any.whl (101 kB)
Apr 28 10:38:25 AM Collecting numpy
Apr 28 10:38:25 AM Downloading numpy-1.21.6-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB)
Apr 28 10:38:27 AM Collecting scikit-learn
Apr 28 10:38:27 AM Downloading scikit_learn-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.8 MB)
Apr 28 10:38:28 AM Collecting gunicorn
Apr 28 10:38:28 AM Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
Apr 28 10:38:28 AM Collecting itsdangerous>=2.0
Apr 28 10:38:28 AM Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Apr 28 10:38:28 AM Collecting Jinja2>=3.0
Apr 28 10:38:28 AM Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
Apr 28 10:38:29 AM Collecting importlib-metadata>=3.6.0; python_version < “3.10”
Apr 28 10:38:29 AM Downloading importlib_metadata-6.6.0-py3-none-any.whl (22 kB)
Apr 28 10:38:29 AM Collecting click>=8.0
Apr 28 10:38:29 AM Downloading click-8.1.3-py3-none-any.whl (96 kB)
Apr 28 10:38:29 AM Collecting Werkzeug>=2.2.2
Apr 28 10:38:29 AM Downloading Werkzeug-2.2.3-py3-none-any.whl (233 kB)
Apr 28 10:38:29 AM Collecting threadpoolctl>=2.0.0
Apr 28 10:38:29 AM Downloading threadpoolctl-3.1.0-py3-none-any.whl (14 kB)
Apr 28 10:38:30 AM Collecting scipy>=1.1.0
Apr 28 10:38:30 AM Downloading scipy-1.7.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (38.1 MB)
Apr 28 10:38:32 AM Collecting joblib>=0.11
Apr 28 10:38:32 AM Downloading joblib-1.2.0-py3-none-any.whl (297 kB)
Apr 28 10:38:32 AM Requirement already satisfied: setuptools>=3.0 in ./.venv/lib/python3.7/site-packages (from gunicorn->-r API/requirements.txt (line 4)) (47.1.0)
Apr 28 10:38:32 AM Collecting MarkupSafe>=2.0
Apr 28 10:38:32 AM Downloading MarkupSafe-2.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Apr 28 10:38:32 AM Collecting typing-extensions>=3.6.4; python_version < “3.8”
Apr 28 10:38:32 AM Downloading typing_extensions-4.5.0-py3-none-any.whl (27 kB)
Apr 28 10:38:32 AM Collecting zipp>=0.5
Apr 28 10:38:32 AM Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
Apr 28 10:38:33 AM Installing collected packages: itsdangerous, MarkupSafe, Jinja2, typing-extensions, zipp, importlib-metadata, click, Werkzeug, flask, numpy, threadpoolctl, scipy, joblib, scikit-learn, gunicorn
Apr 28 10:38:44 AM Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.2 Werkzeug-2.2.3 click-8.1.3 flask-2.2.4 gunicorn-20.1.0 importlib-metadata-6.6.0 itsdangerous-2.1.2 joblib-1.2.0 numpy-1.21.6 scikit-learn-1.0.2 scipy-1.7.3 threadpoolctl-3.1.0 typing-extensions-4.5.0 zipp-3.15.0
Apr 28 10:38:44 AM WARNING: You are using pip version 20.1.1; however, version 23.1.2 is available.
Apr 28 10:38:44 AM You should consider upgrading via the ‘/opt/render/project/src/.venv/bin/python -m pip install --upgrade pip’ command.
Apr 28 10:38:44 AM ==> Generating container image from build. This may take a few minutes…
Apr 28 10:40:45 AM ==> Uploading build…
Apr 28 10:41:32 AM ==> Build uploaded in 33s
Apr 28 10:41:32 AM ==> Build successful :tada:
Apr 28 10:41:32 AM ==> Deploying…
Apr 28 10:41:52 AM ==> Starting service with ‘gunicorn Heart_Disease_Prediction_App:app’
Apr 28 10:41:54 AM Traceback (most recent call last):
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/bin/gunicorn”, line 8, in
Apr 28 10:41:54 AM sys.exit(run())
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py”, line 67, in run
Apr 28 10:41:54 AM WSGIApplication(“%(prog)s [OPTIONS] [APP_MODULE]”).run()
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py”, line 231, in run
Apr 28 10:41:54 AM super().run()
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py”, line 72, in run
Apr 28 10:41:54 AM Arbiter(self).run()
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/arbiter.py”, line 58, in init
Apr 28 10:41:54 AM self.setup(app)
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/arbiter.py”, line 118, in setup
Apr 28 10:41:54 AM self.app.wsgi()
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py”, line 67, in wsgi
Apr 28 10:41:54 AM self.callable = self.load()
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py”, line 58, in load
Apr 28 10:41:54 AM return self.load_wsgiapp()
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py”, line 48, in load_wsgiapp
Apr 28 10:41:54 AM return util.import_app(self.app_uri)
Apr 28 10:41:54 AM File “/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/util.py”, line 359, in import_app
Apr 28 10:41:54 AM mod = importlib.import_module(module)
Apr 28 10:41:54 AM File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module
Apr 28 10:41:54 AM return _bootstrap._gcd_import(name[level:], package, level)
Apr 28 10:41:54 AM File “”, line 1006, in _gcd_import
Apr 28 10:41:54 AM File “”, line 983, in _find_and_load
Apr 28 10:41:54 AM File “”, line 965, in _find_and_load_unlocked
Apr 28 10:41:54 AM ModuleNotFoundError: No module named ‘Heart_Disease_Prediction_App’

i think its a gunicorn problem but i don’t know how to address it
your help will be highly appreciated

Hi Hez,

I see a .. at the very top of your GitHub screenshot. Is your application in the root directory of your repo?

If not, you’ll need to provide a dotted path to the module or specify a Root Directory in your services settings.

Give that a go and let me know if it helps.

Regards,

Matt

I moved everything to the root directory and it worked just fine.

thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.