簡體   English   中英

在 Heroku 上部署 Flask API 會出現“app crashed”錯誤

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

我正在將 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()

這是我的 Procfile,在看到這個問題的答案后,我已經更改了好幾次都沒有用。

web: gunicorn

這是我的要求.txt

numpy==1.22.3
tensorflow-hub==0.12.0
flask

因此,我運行了以下命令(登錄並設置 git 后)將我的 flask API 推送到 Heroku

$ git add -A
$ git commit -m "commit message"
$ git push heroku master

它顯示了這一點,

...
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

但是當我 go 到 https://<app_name>.herokuapp.com 它顯示了這個,

在此處輸入圖像描述

我檢查了 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

我想要解決此問題的方法我已經檢查了許多 StackOverflow 答案,但它不起作用,如果您需要任何額外信息,請告訴我,我會添加它!

您需要將gunicorn添加到您的requirements.txt參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM