1

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,

enter image description here

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!

  • Try restarting the dynos while in the logs screen and monitor the logs – fourjr May 01 '22 at 07:39
  • Did you miss out `flask` in your requirements? – fourjr May 01 '22 at 07:39
  • @fourjr how can I add flask? I don't the version! –  May 01 '22 at 07:40
  • Add `flask` onto a new line in your `requirements.txt` – fourjr May 01 '22 at 07:40
  • @fourjr I added flask it installed it too but still the situation is same it is showing same error `2022-05-01T07:45:30.305054+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=.herokuapp.com request_id=28f2ae1c-1350-4161-a3c3-3af2d338e23b fwd="103.88.83.161" dyno= connect= service= status=503 bytes= protocol=https` –  May 01 '22 at 07:46
  • Try restarting the dynos while in the logs screen and monitor the logs [image](https://i.imgur.com/3FcrlKz.png) – fourjr May 01 '22 at 07:49
  • I restarted dynos, this is how the logs changed image: https://i.imgur.com/QWVhOrj.png –  May 01 '22 at 07:52
  • @fourjr it is showing something gunicorn not found, what's that? –  May 01 '22 at 07:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244369/discussion-between-fourjr-and-pritish-mishra). – fourjr May 01 '22 at 07:55

1 Answers1

0

You need to add gunicorn to your requirements.txt (reference)

fourjr
  • 329
  • 2
  • 9