flask remove file after send_file

from flask import Flask, send_file, after_this_request
import os

app = Flask(__name__)

def download_file():
    # Specify the file path
    file_path = 'path/to/your/file.txt'

    # Define a function to be executed after the file is sent
    def remove_file(response):
            # Remove the file after it has been sent
        except Exception as error:
            app.logger.error("Error removing file: %s", error)
        return response

    # Send the file to the client
    return send_file(file_path, as_attachment=True)

if __name__ == '__main__':