




import numpy as np
import torch
from imwatermark import WatermarkEncoder


# Copied from https://github.com/Stability-AI/generative-models/blob/613af104c6b85184091d42d374fef420eddb356d/scripts/demo/streamlit_helpers.py#L66
snake_case_ : int    		=       0b101100111110110010010000011110111011000110011110
# bin(x)[2:] gives bits of x as str, use int to convert them to 0/1
snake_case_ : Optional[Any]    		=       [int(bit) for bit in bin(WATERMARK_MESSAGE)[2:]]







class __snake_case			:







   def __init__(      self		:						List[str]):

        """simple docstring"""


        UpperCAmelCase_          =							WATERMARK_BITS
        UpperCAmelCase_          =							WatermarkEncoder()

        self.encoder.set_watermark('''bits'''					,						self.watermark)







   def lowerCamelCase						(      self		:						Any					,						_snake_case		:						torch.FloatTensor):

        """simple docstring"""


        if images.shape[-1] < 256:
             return images

        UpperCAmelCase_          =							(255 * (images / 2 + 0.5)).cpu().permute(0					,						2					,						3					,						1).float().numpy()

        UpperCAmelCase_          =							[self.encoder.encode(_snake_case					,						'''dwtDct''') for image in images]

        UpperCAmelCase_          =							torch.from_numpy(np.array(_snake_case)).permute(0					,						3					,						1					,						2)

        UpperCAmelCase_          =							torch.clamp(2 * (images / 255 - 0.5)					,						min=-1.0					,						max=1.0)
        return images












from typing import TYPE_CHECKING

from ....utils import _LazyModule


_UpperCAmelCase		:  Dict	=   {"tokenization_tapex": ["TapexTokenizer"]}


if TYPE_CHECKING:
     from .tokenization_tapex import TapexTokenizer


else:
     import sys

     _UpperCAmelCase		:  Optional[Any]	=   _LazyModule(__name__, globals()["__file__"], _import_structure)



