I am deploying a Flask API to Heroku. That API perfectly works on localhost but I am trying to deploy it on Heroku. This is my API code:
from flask import Flask, request, jsonify
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, World!"
@app.route('/embed', methods=['GET'])
def embed():
text = request.args.get('text')
try:
embedding = model([text]).numpy().tolist()
return jsonify({'text': text, 'embedding': embedding, 'status': 'ok'})
except Exception as e:
print(e)
return jsonify({'text': text, 'status': 'error'})
if __name__ == '__main__':
app.run()
This is my Procfile, I have changed it several times after seeing the answer from this question none works.
web: gunicorn
This is my requirement.txt
numpy==1.22.3
tensorflow-hub==0.12.0
flask
So, I ran the following commands (after logging in and setting git) to push my flask API to Heroku
$ git add -A
$ git commit -m "commit message"
$ git push heroku master
It shows this,
...
remote: -----> Installing requirements with pip
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 80M
remote: -----> Launching...
remote: Released v7
remote: https://<app_name>.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/<app_name>.git
7b4ea0b..0fe40fe master -> master
But when I go to https://<app_name>.herokuapp.com it shows this,
I checked heroku logs and this is the output,
2022-05-01T07:35:00.333123+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=<app_name>.herokuapp.com request_id=992baf8b-cae3-4c7a-9949-653bfdac3c65 fwd="103.88.83.161" dyno= connect= service= status=503 bytes= protocol=https
I want solution for this I have checked many StackOverflow answers but it doesn't works, If you need any extra information let me know I will add it!