How to run a python function in flask without changing the route/outside the route with html button?

Solution
@app.route("/engine", methods=["GET"])
def get_engine():
    use_script = request.args.get("use_script")
    if use_script:
        get_text_from_pdf(config.doc_path)  # Here I am calling python function

    return render_template("engine.html")
 Insight Engine