1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Appropriate method to pass arguments in Flask without using the url

Discussão em 'Python' iniciado por Stack, Novembro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am using flask and a deep learning model in tensorflow to display some annotated video. The module works fine but the loading of the model is lazy due to the nature of the generator. Only after I launch the url in my browser the model is loaded, and thus, there is some delay before the actual detection start to occur. I wanted to load my module before-hand to avoid this behaviour.

    So, instead of using a structure like this:

    def main():
    app.run(host='0.0.0.0', debug=True)


    @app.route('/')
    def video_feed():
    return Response(apply_detections(), mimetype='multipart/x-mixed-replace; boundary=frame')


    if __name__ == '__main__':
    main()


    apply_detections() here of course is the generator which detects the objects and then yields the annotated frame. I was aiming for something like this:

    def main():
    loaded_model = load_model() # this should load the model before-hand
    loaded_tracker = load_tracker() # same here. This should load the model before-hand
    app.run(host='0.0.0.0', debug=True)


    @app.route('/')
    def video_feed():
    return Response(apply_detections(loaded_model, loaded_tracker), mimetype='multipart/x-mixed-replace; boundary=frame')


    if __name__ == '__main__':
    main()


    I know I can pass some arguments via the url -like @app.route('/<args1>')- but obviously this could not help here (I couldn't pass the whole model as text in the url) and a second option would be to define the arguments as global ones but this also has its drawbacks.

    So, my question is which is the right way to accomplish this argument passing?

    Continue reading...

Compartilhe esta Página