





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_		(	_lowerCamelCase				,	_lowerCamelCase       ):




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

										self.register_buffer('watermark_image'					,    torch.zeros((62, 62, 4)	)	)
										_snake_case						=					None






					def 						lowerCAmelCase      (		self					,    lowerCAmelCase_					,    lowerCAmelCase_=None	)		->				List[Any]:
										# copied from https://github.com/deep-floyd/IF/blob/b77482e36ca2031cb94dbca1001fc1e6400bf4ab/deepfloyd_if/modules/base.py#L287

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

										_snake_case						=					sample_size or h

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

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

										if self.watermark_image_as_pil is None:
															_snake_case						=					self.watermark_image.to(torch.uinta	).cpu().numpy()
															_snake_case						=					Image.fromarray(lowerCAmelCase_					,    mode='RGBA'	)
															_snake_case						=					watermark_image

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










import unittest

from transformers import is_torch_available, load_tool

from .test_tools_common import ToolTesterMixin


if is_torch_available():
					import torch
class       UpperCamelCase_		(	unittest.TestCase				,	_lowerCamelCase       ):




					def 						lowerCAmelCase      (		self	)		->				str:
										_snake_case						=					load_tool('speech-to-text'	)
										self.tool.setup()




					def 						lowerCAmelCase      (		self	)		->				Optional[Any]:
										_snake_case						=					self.tool(torch.ones(3000	)	)
										self.assertEqual(lowerCAmelCase_					,    ' you'	)






					def 						lowerCAmelCase      (		self	)		->				Optional[int]:
										_snake_case						=					self.tool(audio=torch.ones(3000	)	)
										self.assertEqual(lowerCAmelCase_					,    ' you'	)



