Can flask concurrently rendering a template while executing a function?

Greetings!

I am facing trouble in concurently rendering (“det_loader.html”) while executing the function (detect_img()). And, once the function execution is completed, it should be able to proceed to render (“custom.html”, value = data).

Screenshot_1

I hope someone can help with this! Thank you.