我正在尝试使用 Flask 的蓝图通过 API 提供机器学习模型,这是我的烧瓶__init__.py文件
from flask import Flask
def create_app(test_config=None):
app = Flask(__name__)
@app.route("/healthcheck")
def healthcheck() -> str:
return "OK"
# Registers the machine learning blueprint
from . import ml
app.register_blueprint(ml.bp)
return app
Run Code Online (Sandbox Code Playgroud)
ml.py包含/ml端点蓝图的文件
import numpy as np
from . import configuration as cfg
import tensorflow as tf
from flask import (
Blueprint, flash, request, url_for
)
bp = Blueprint("ml", __name__, url_prefix="/ml")
keras_model = None
graph = None
@bp.before_app_first_request
def load_model():
print("Loading keras model") …Run Code Online (Sandbox Code Playgroud)