'''simple docstring'''

from typing import List

import PIL
import torch
from PIL import Image

from ...configuration_utils import ConfigMixin
from ...models.modeling_utils import ModelMixin
from ...utils import PIL_INTERPOLATION




class    lowerCamelCase__  (   SCREAMING_SNAKE_CASE_       ,				SCREAMING_SNAKE_CASE_     ):



   def __init__(    self     )				->     Tuple:
        """simple docstring"""





        super().__init__()

        self.register_buffer("""watermark_image"""					,      torch.zeros((62, 62, 4)     )     )
        _UpperCamelCase  :List[str]       =None




   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__=None     )				->     Optional[int]:
        """simple docstring"""





        _UpperCamelCase  :Union[str, Any]       =images[0].height
        _UpperCamelCase  :Optional[Any]       =images[0].width

        _UpperCamelCase  :Tuple       =sample_size or h

        _UpperCamelCase  :Dict       =min(h / sample_size					,      w / sample_size     )
        _UpperCamelCase       ,      _UpperCamelCase  :Optional[Any]       =(int(h / coef     ), int(w / coef     )) if coef < 1 else (h, w)

        _UpperCamelCase       ,      _UpperCamelCase  :Optional[int]       =1_024**2, img_w * img_h
        _UpperCamelCase  :Union[str, Any]       =(Sa / Sa) ** 0.5
        _UpperCamelCase       ,      _UpperCamelCase       ,      _UpperCamelCase  :str       =int(K * 62     ), img_w - int(14 * K     ), img_h - int(14 * K     )

        if self.watermark_image_as_pil is None:
             _UpperCamelCase  :Dict       =self.watermark_image.to(torch.uinta     ).cpu().numpy()
             _UpperCamelCase  :Tuple       =Image.fromarray(__UpperCAmelCase					,      mode="""RGBA"""     )
             _UpperCamelCase  :Any       =watermark_image

        _UpperCamelCase  :List[Any]       =self.watermark_image_as_pil.resize(
            (wm_size, wm_size)					,      PIL_INTERPOLATION["""bicubic"""]					,      reducing_gap=__UpperCAmelCase     )

        for pil_img in images:
             pil_img.paste(__UpperCAmelCase					,      box=(wm_x - wm_size, wm_y - wm_size, wm_x, wm_y)					,      mask=wm_img.split()[-1]     )

        return images

"""simple docstring"""






import copy

from transformers.configuration_utils import PretrainedConfig
from transformers.utils import logging


UpperCamelCase_						   =   logging.get_logger(__name__)





class 							snake_case       (     SCREAMING_SNAKE_CASE_		):
   a_					:		Tuple     					=     """hybrid-clip"""
   a_					:		Optional[Any]     					=     True







   def __init__( self       ,							__UpperCAmelCase=5_12       ,							**__UpperCAmelCase)   ->Dict:
      super().__init__(**__UpperCAmelCase)

      if "text_config" not in kwargs:
         raise ValueError("`text_config` can not be `None`.")

      if "vision_config" not in kwargs:
         raise ValueError("`vision_config` can not be `None`.")

      a_						   =     kwargs.pop("text_config")
      a_						   =     kwargs.pop("vision_config")

      a_						   =     text_config.pop("model_type")
      a_						   =     vision_config.pop("model_type")

      from transformers import AutoConfig

      a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase)

      if vision_model_type == "clip":
         a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase).vision_config
      elif vision_model_type == "clip_vision_model":
         from transformers import CLIPVisionConfig

         a_						   =     CLIPVisionConfig(**__UpperCAmelCase)
      else:
         a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase)

      a_						   =     projection_dim
      a_						   =     1.0







   @classmethod
   def    UpperCAmelCase__	( cls       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							**__UpperCAmelCase)   ->Optional[int]:
      return cls(text_config=text_config.to_dict()       ,							vision_config=vision_config.to_dict()       ,							**__UpperCAmelCase)







   def    UpperCAmelCase__	( self)   ->str:
      a_						   =     copy.deepcopy(self.__dict__)
      a_						   =     self.text_config.to_dict()
      a_						   =     self.vision_config.to_dict()
      a_						   =     self.__class__.model_type
      return output