def initialize_requirements_txt() -> bool:
    """Initialize the requirements.txt file.
    If absent and no pyproject.toml file exists, generate one for the user.
    If the requirements.txt does not have reflex as dependency,
    generate a requirement pinning current version and append to
    the requirements.txt file.

    Returns:
        True if the user has to update the requirements.txt file.

    Raises:
        Exit: If the requirements.txt file cannot be read or written to.
    """
    requirements_file_path = Path(constants.RequirementsTxt.FILE)
    if (
        not requirements_file_path.exists()
        and Path(constants.PyprojectToml.FILE).exists()
    ):
        return True

    requirements_file_path.touch(exist_ok=True)

    for encoding in [None, "utf-8"]:
        try:
            content = requirements_file_path.read_text(encoding)
            break
        except UnicodeDecodeError:
            continue
        except Exception as e:
            console.error(f"Failed to read {requirements_file_path}.")
            raise click.exceptions.Exit(1) from e
    else:
        return True

    for line in content.splitlines():
        if re.match(r"^reflex[^a-zA-Z0-9]", line):
            console.debug(f"{requirements_file_path} already has reflex as dependency.")
            return False

    console.debug(
        f"Appending {constants.RequirementsTxt.DEFAULTS_STUB} to {requirements_file_path}"
    )
    with requirements_file_path.open("a", encoding=encoding) as f:
        f.write(
            "\n" + constants.RequirementsTxt.DEFAULTS_STUB + constants.Reflex.VERSION
        )

    return False
Initialize the requirements.txt file.
    If absent and no pyproject.toml file exists, generate one for the user.
    If the requirements.txt does not have reflex as dependency,
    generate a requirement pinning current version and append to
    the requirements.txt file.

    Returns:
        True if the user has to update the requirements.txt file.

    Raises:
        Exit: If the requirements.txt file cannot be read or written to.
    
reflex/utils/prerequisites.py