
"""simple docstring"""







from typing import TYPE_CHECKING

from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available


SCREAMING_SNAKE_CASE_  					= {
    'configuration_utils': ['GenerationConfig'],
    'streamers': ['TextIteratorStreamer', 'TextStreamer'],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  SCREAMING_SNAKE_CASE_  					= [
      'Constraint',
      'ConstraintListState',
      'DisjunctiveConstraint',
      'PhrasalConstraint',
  ]
  SCREAMING_SNAKE_CASE_  					= [
      'BeamHypotheses',
      'BeamScorer',
      'BeamSearchScorer',
      'ConstrainedBeamSearchScorer',
  ]
  SCREAMING_SNAKE_CASE_  					= [
      'EpsilonLogitsWarper',
      'EtaLogitsWarper',
      'ForcedBOSTokenLogitsProcessor',
      'ForcedEOSTokenLogitsProcessor',
      'HammingDiversityLogitsProcessor',
      'InfNanRemoveLogitsProcessor',
      'LogitsProcessor',
      'LogitsProcessorList',
      'LogitsWarper',
      'MinLengthLogitsProcessor',
      'MinNewTokensLengthLogitsProcessor',
      'NoBadWordsLogitsProcessor',
      'NoRepeatNGramLogitsProcessor',
      'PrefixConstrainedLogitsProcessor',
      'RepetitionPenaltyLogitsProcessor',
      'SequenceBiasLogitsProcessor',
      'EncoderRepetitionPenaltyLogitsProcessor',
      'TemperatureLogitsWarper',
      'TopKLogitsWarper',
      'TopPLogitsWarper',
      'TypicalLogitsWarper',
      'EncoderNoRepeatNGramLogitsProcessor',
      'ExponentialDecayLengthPenalty',
      'LogitNormalization',
  ]
  SCREAMING_SNAKE_CASE_  					= [
      'MaxNewTokensCriteria',
      'MaxLengthCriteria',
      'MaxTimeCriteria',
      'StoppingCriteria',
      'StoppingCriteriaList',
      'validate_stopping_criteria',
  ]
  SCREAMING_SNAKE_CASE_  					= [
      'GenerationMixin',
      'top_k_top_p_filtering',
      'GreedySearchEncoderDecoderOutput',
      'GreedySearchDecoderOnlyOutput',
      'SampleEncoderDecoderOutput',
      'SampleDecoderOnlyOutput',
      'BeamSearchEncoderDecoderOutput',
      'BeamSearchDecoderOnlyOutput',
      'BeamSampleEncoderDecoderOutput',
      'BeamSampleDecoderOnlyOutput',
      'ContrastiveSearchEncoderDecoderOutput',
      'ContrastiveSearchDecoderOnlyOutput',
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  SCREAMING_SNAKE_CASE_  					= [
      'TFForcedBOSTokenLogitsProcessor',
      'TFForcedEOSTokenLogitsProcessor',
      'TFLogitsProcessor',
      'TFLogitsProcessorList',
      'TFLogitsWarper',
      'TFMinLengthLogitsProcessor',
      'TFNoBadWordsLogitsProcessor',
      'TFNoRepeatNGramLogitsProcessor',
      'TFRepetitionPenaltyLogitsProcessor',
      'TFTemperatureLogitsWarper',
      'TFTopKLogitsWarper',
      'TFTopPLogitsWarper',
      'TFForceTokensLogitsProcessor',
      'TFSuppressTokensAtBeginLogitsProcessor',
      'TFSuppressTokensLogitsProcessor',
  ]
  SCREAMING_SNAKE_CASE_  					= [
      'TFGenerationMixin',
      'tf_top_k_top_p_filtering',
      'TFGreedySearchDecoderOnlyOutput',
      'TFGreedySearchEncoderDecoderOutput',
      'TFSampleEncoderDecoderOutput',
      'TFSampleDecoderOnlyOutput',
      'TFBeamSearchEncoderDecoderOutput',
      'TFBeamSearchDecoderOnlyOutput',
      'TFBeamSampleEncoderDecoderOutput',
      'TFBeamSampleDecoderOnlyOutput',
      'TFContrastiveSearchEncoderDecoderOutput',
      'TFContrastiveSearchDecoderOnlyOutput',
  ]

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  SCREAMING_SNAKE_CASE_  					= [
      'FlaxForcedBOSTokenLogitsProcessor',
      'FlaxForcedEOSTokenLogitsProcessor',
      'FlaxLogitsProcessor',
      'FlaxLogitsProcessorList',
      'FlaxLogitsWarper',
      'FlaxMinLengthLogitsProcessor',
      'FlaxTemperatureLogitsWarper',
      'FlaxTopKLogitsWarper',
      'FlaxTopPLogitsWarper',
  ]
  SCREAMING_SNAKE_CASE_  					= [
      'FlaxGenerationMixin',
      'FlaxGreedySearchOutput',
      'FlaxSampleOutput',
      'FlaxBeamSearchOutput',
  ]

if TYPE_CHECKING:
  from .configuration_utils import GenerationConfig
  from .streamers import TextIteratorStreamer, TextStreamer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
    from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
    from .logits_process import (
        EncoderNoRepeatNGramLogitsProcessor,
        EncoderRepetitionPenaltyLogitsProcessor,
        EpsilonLogitsWarper,
        EtaLogitsWarper,
        ExponentialDecayLengthPenalty,
        ForcedBOSTokenLogitsProcessor,
        ForcedEOSTokenLogitsProcessor,
        HammingDiversityLogitsProcessor,
        InfNanRemoveLogitsProcessor,
        LogitNormalization,
        LogitsProcessor,
        LogitsProcessorList,
        LogitsWarper,
        MinLengthLogitsProcessor,
        MinNewTokensLengthLogitsProcessor,
        NoBadWordsLogitsProcessor,
        NoRepeatNGramLogitsProcessor,
        PrefixConstrainedLogitsProcessor,
        RepetitionPenaltyLogitsProcessor,
        SequenceBiasLogitsProcessor,
        TemperatureLogitsWarper,
        TopKLogitsWarper,
        TopPLogitsWarper,
        TypicalLogitsWarper,
    )
    from .stopping_criteria import (
        MaxLengthCriteria,
        MaxNewTokensCriteria,
        MaxTimeCriteria,
        StoppingCriteria,
        StoppingCriteriaList,
        validate_stopping_criteria,
    )
    from .utils import (
        BeamSampleDecoderOnlyOutput,
        BeamSampleEncoderDecoderOutput,
        BeamSearchDecoderOnlyOutput,
        BeamSearchEncoderDecoderOutput,
        ContrastiveSearchDecoderOnlyOutput,
        ContrastiveSearchEncoderDecoderOutput,
        GenerationMixin,
        GreedySearchDecoderOnlyOutput,
        GreedySearchEncoderDecoderOutput,
        SampleDecoderOnlyOutput,
        SampleEncoderDecoderOutput,
        top_k_top_p_filtering,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tf_logits_process import (
        TFForcedBOSTokenLogitsProcessor,
        TFForcedEOSTokenLogitsProcessor,
        TFForceTokensLogitsProcessor,
        TFLogitsProcessor,
        TFLogitsProcessorList,
        TFLogitsWarper,
        TFMinLengthLogitsProcessor,
        TFNoBadWordsLogitsProcessor,
        TFNoRepeatNGramLogitsProcessor,
        TFRepetitionPenaltyLogitsProcessor,
        TFSuppressTokensAtBeginLogitsProcessor,
        TFSuppressTokensLogitsProcessor,
        TFTemperatureLogitsWarper,
        TFTopKLogitsWarper,
        TFTopPLogitsWarper,
    )
    from .tf_utils import (
        TFBeamSampleDecoderOnlyOutput,
        TFBeamSampleEncoderDecoderOutput,
        TFBeamSearchDecoderOnlyOutput,
        TFBeamSearchEncoderDecoderOutput,
        TFContrastiveSearchDecoderOnlyOutput,
        TFContrastiveSearchEncoderDecoderOutput,
        TFGenerationMixin,
        TFGreedySearchDecoderOnlyOutput,
        TFGreedySearchEncoderDecoderOutput,
        TFSampleDecoderOnlyOutput,
        TFSampleEncoderDecoderOutput,
        tf_top_k_top_p_filtering,
    )

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .flax_logits_process import (
        FlaxForcedBOSTokenLogitsProcessor,
        FlaxForcedEOSTokenLogitsProcessor,
        FlaxLogitsProcessor,
        FlaxLogitsProcessorList,
        FlaxLogitsWarper,
        FlaxMinLengthLogitsProcessor,
        FlaxTemperatureLogitsWarper,
        FlaxTopKLogitsWarper,
        FlaxTopPLogitsWarper,
    )
    from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
else:
  import sys

  SCREAMING_SNAKE_CASE_  					= _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



"""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      __a      (       lowerCAmelCase_					,						lowerCAmelCase_      ):







       def __init__(       self		):



          '''simple docstring'''

          super().__init__()

          self.register_buffer("watermark_image"				,torch.zeros((62, 62, 4)		)		)
          _UpperCAmelCase 						=       None







       def  _snake_case      (       self				,lowerCamelCase_				,lowerCamelCase_=None		):



          '''simple docstring'''

          _UpperCAmelCase 						=       images[0].height
          _UpperCAmelCase 						=       images[0].width

          _UpperCAmelCase 						=       sample_size or h

          _UpperCAmelCase 						=       min(h / sample_size				,w / sample_size		)
          _UpperCAmelCase						,				_UpperCAmelCase 						=       (int(h / coef		), int(w / coef		)) if coef < 1 else (h, w)

          _UpperCAmelCase						,				_UpperCAmelCase 						=       1024**2, img_w * img_h
          _UpperCAmelCase 						=       (Sa / Sa) ** 0.5
          _UpperCAmelCase						,				_UpperCAmelCase						,				_UpperCAmelCase 						=       int(K * 62		), img_w - int(14 * K		), img_h - int(14 * K		)

          if self.watermark_image_as_pil is None:
             _UpperCAmelCase 						=       self.watermark_image.to(torch.uinta		).cpu().numpy()
             _UpperCAmelCase 						=       Image.fromarray(lowerCamelCase_				,mode="RGBA"		)
             _UpperCAmelCase 						=       watermark_image

          _UpperCAmelCase 						=       self.watermark_image_as_pil.resize(
              (wm_size, wm_size)				,PIL_INTERPOLATION["bicubic"]				,reducing_gap=lowerCamelCase_		)

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

          return images

