





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 	_UpperCAmelCase						( __UpperCAmelCase			,							__UpperCAmelCase       ):




					def __init__(    self							)    ->	Dict:
							super().__init__()

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




					def 						snake_case_		(    self     ,   __lowerCAmelCase     ,   __lowerCAmelCase=None							)    ->	Optional[int]:
							# copied from https://github.com/deep-floyd/IF/blob/b77482e36ca2031cb94dbca1001fc1e6400bf4ab/deepfloyd_if/modules/base.py#L287

							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__								=						1_024**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(UpperCAmelCase_     ,   mode="""RGBA"""							)
									UpperCamelCase__								=						watermark_image

							UpperCamelCase__								=						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











from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


UpperCAmelCase_    ={"""configuration_vilt""": ["""VILT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ViltConfig"""]}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase_    =["""ViltFeatureExtractor"""]
		UpperCAmelCase_    =["""ViltImageProcessor"""]
		UpperCAmelCase_    =["""ViltProcessor"""]

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase_    =[
		    """VILT_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """ViltForImageAndTextRetrieval""",
		    """ViltForImagesAndTextClassification""",
		    """ViltForTokenClassification""",
		    """ViltForMaskedLM""",
		    """ViltForQuestionAnswering""",
		    """ViltLayer""",
		    """ViltModel""",
		    """ViltPreTrainedModel""",
		]


if TYPE_CHECKING:
		from .configuration_vilt import VILT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViltConfig

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_vilt import ViltFeatureExtractor
				from .image_processing_vilt import ViltImageProcessor
				from .processing_vilt import ViltProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_vilt import (
				    VILT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ViltForImageAndTextRetrieval,
				    ViltForImagesAndTextClassification,
				    ViltForMaskedLM,
				    ViltForQuestionAnswering,
				    ViltForTokenClassification,
				    ViltLayer,
				    ViltModel,
				    ViltPreTrainedModel,
				)


else:
		import sys

		UpperCAmelCase_    =_LazyModule(__name__, globals()["""__file__"""], _import_structure)



