简体   繁体   English

在 Heroku 上部署 Flask API 会出现“app crashed”错误

[英]Deploying Flask API on Heroku gives "app crashed" Error

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:我正在将 Flask API 部署到 Heroku。API 在本地主机上完美运行,但我正在尝试将其部署在 Heroku 上。这是我的 API 代码:

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.这是我的 Procfile,在看到这个问题的答案后,我已经更改了好几次都没有用。

web: gunicorn

This is my requirement.txt这是我的要求.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 后)将我的 flask API 推送到 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,但是当我 go 到 https://<app_name>.herokuapp.com 它显示了这个,

在此处输入图像描述

I checked heroku logs and this is the output,我检查了 heroku 日志,这是 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!我想要解决此问题的方法我已经检查了许多 StackOverflow 答案,但它不起作用,如果您需要任何额外信息,请告诉我,我会添加它!

You need to add gunicorn to your requirements.txt ( reference )您需要将gunicorn添加到您的requirements.txt参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM