






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import CLIPImageProcessor
class        __snake_case(					unittest.TestCase      ):



 def __init__(	self   :   Union[str, Any] ,		UpperCAmelCase__   :   Dict ,		UpperCAmelCase__   :   Optional[Any]=7 ,		UpperCAmelCase__   :   int=3 ,		UpperCAmelCase__   :   List[str]=18 ,		UpperCAmelCase__   :   List[Any]=30 ,		UpperCAmelCase__   :   Any=400 ,		UpperCAmelCase__   :   Optional[int]=True ,		UpperCAmelCase__   :   Dict=None ,		UpperCAmelCase__   :   Tuple=True ,		UpperCAmelCase__   :   str=None ,		UpperCAmelCase__   :   Tuple=True ,		UpperCAmelCase__   :   Optional[Any]=[0.48_145_466, 0.4_578_275, 0.40_821_073] ,		UpperCAmelCase__   :   Optional[int]=[0.26_862_954, 0.26_130_258, 0.27_577_711] ,		UpperCAmelCase__   :   str=True ,		):

    """simple docstring"""






    lowercase__						:	Any         = size if size is not None else {"""shortest_edge""": 20}
    lowercase__						:	Dict         = crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
    lowercase__						:	int         = parent
    lowercase__						:	Any         = batch_size
    lowercase__						:	List[str]         = num_channels
    lowercase__						:	Dict         = image_size
    lowercase__						:	Tuple         = min_resolution
    lowercase__						:	Tuple         = max_resolution
    lowercase__						:	Any         = do_resize
    lowercase__						:	Dict         = size
    lowercase__						:	Optional[Any]         = do_center_crop
    lowercase__						:	Tuple         = crop_size
    lowercase__						:	Optional[Any]         = do_normalize
    lowercase__						:	Dict         = image_mean
    lowercase__						:	Dict         = image_std
    lowercase__						:	int         = do_convert_rgb



 def 						UpperCAmelCase    (	self   :   Dict	):

    """simple docstring"""






    return {
        "do_resize": self.do_resize,
        "size": self.size,
        "do_center_crop": self.do_center_crop,
        "crop_size": self.crop_size,
        "do_normalize": self.do_normalize,
        "image_mean": self.image_mean,
        "image_std": self.image_std,
        "do_convert_rgb": self.do_convert_rgb,
    }







 def 						UpperCAmelCase    (	self   :   Tuple ,		UpperCAmelCase__   :   Optional[int]=False ,		UpperCAmelCase__   :   Any=False ,		UpperCAmelCase__   :   List[str]=False	):

    """simple docstring"""






    assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

    if equal_resolution:
       lowercase__						:	str         = []
       for i in range(self.batch_size	):
          image_inputs.append(
              np.random.randint(
                  255 ,		size=(self.num_channels, self.max_resolution, self.max_resolution) ,		dtype=np.uinta	)	)
    else:
       lowercase__						:	Any         = []
       for i in range(self.batch_size	):
          lowercase__						:	Union[str, Any]         = np.random.choice(np.arange(self.min_resolution ,		self.max_resolution	) ,		2	)
          image_inputs.append(np.random.randint(255 ,		size=(self.num_channels, width, height) ,		dtype=np.uinta	)	)

    if not numpify and not torchify:
       # PIL expects the channel dimension as last dimension
       lowercase__						:	List[str]         = [Image.fromarray(np.moveaxis(UpperCAmelCase__ ,		0 ,		-1	)	) for x in image_inputs]

    if torchify:
       lowercase__						:	Any         = [torch.from_numpy(UpperCAmelCase__	) for x in image_inputs]

    return image_inputs
@require_torch
@require_vision
class        __snake_case(					__UpperCamelCase     ,       unittest.TestCase      ):
 lowercase :       Dict		      =		CLIPImageProcessor if is_vision_available() else None



 def 						UpperCAmelCase    (	self   :   Dict	):

    """simple docstring"""






    lowercase__						:	str         = CLIPImageProcessingTester(self	)



 @property
 def 						UpperCAmelCase    (	self   :   str	):

    """simple docstring"""






    return self.image_processor_tester.prepare_image_processor_dict()



 def 						UpperCAmelCase    (	self   :   List[str]	):

    """simple docstring"""






    lowercase__						:	Dict         = self.image_processing_class(**self.image_processor_dict	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_resize"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""size"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_center_crop"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""center_crop"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_normalize"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""image_mean"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""image_std"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_convert_rgb"""	)	)



 def 						UpperCAmelCase    (	self   :   List[Any]	):

    """simple docstring"""






    lowercase__						:	int         = self.image_processing_class.from_dict(self.image_processor_dict	)
    self.assertEqual(image_processor.size ,		{"""shortest_edge""": 20}	)
    self.assertEqual(image_processor.crop_size ,		{"""height""": 18, """width""": 18}	)

    lowercase__						:	str         = self.image_processing_class.from_dict(self.image_processor_dict ,		size=42 ,		crop_size=84	)
    self.assertEqual(image_processor.size ,		{"""shortest_edge""": 42}	)
    self.assertEqual(image_processor.crop_size ,		{"""height""": 84, """width""": 84}	)



 def 						UpperCAmelCase    (	self   :   Dict	):

    """simple docstring"""






    pass



 def 						UpperCAmelCase    (	self   :   Tuple	):

    """simple docstring"""






    lowercase__						:	Tuple         = self.image_processing_class(**self.image_processor_dict	)
    # create random PIL images
    lowercase__						:	Optional[int]         = self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase__	)
    for image in image_inputs:
       self.assertIsInstance(UpperCAmelCase__ ,		Image.Image	)

    # Test not batched input
    lowercase__						:	str         = image_processing(image_inputs[0] ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)

    # Test batched
    lowercase__						:	List[str]         = image_processing(UpperCAmelCase__ ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)



 def 						UpperCAmelCase    (	self   :   Union[str, Any]	):

    """simple docstring"""






    lowercase__						:	str         = self.image_processing_class(**self.image_processor_dict	)
    # create random numpy tensors
    lowercase__						:	List[Any]         = self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase__ ,		numpify=UpperCAmelCase__	)
    for image in image_inputs:
       self.assertIsInstance(UpperCAmelCase__ ,		np.ndarray	)

    # Test not batched input
    lowercase__						:	Optional[Any]         = image_processing(image_inputs[0] ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)

    # Test batched
    lowercase__						:	List[str]         = image_processing(UpperCAmelCase__ ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)







 def 						UpperCAmelCase    (	self   :   Union[str, Any]	):

    """simple docstring"""






    lowercase__						:	Optional[Any]         = self.image_processing_class(**self.image_processor_dict	)
    # create random PyTorch tensors
    lowercase__						:	List[str]         = self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase__ ,		torchify=UpperCAmelCase__	)
    for image in image_inputs:
       self.assertIsInstance(UpperCAmelCase__ ,		torch.Tensor	)

    # Test not batched input
    lowercase__						:	Optional[int]         = image_processing(image_inputs[0] ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)

    # Test batched
    lowercase__						:	Optional[int]         = image_processing(UpperCAmelCase__ ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)
@require_torch
@require_vision
class        __snake_case(					__UpperCamelCase     ,       unittest.TestCase      ):
 lowercase :       int		      =		CLIPImageProcessor if is_vision_available() else None



 def 						UpperCAmelCase    (	self   :   Union[str, Any]	):

    """simple docstring"""






    lowercase__						:	str         = CLIPImageProcessingTester(self ,		num_channels=4	)
    lowercase__						:	List[Any]         = 3



 @property
 def 						UpperCAmelCase    (	self   :   Union[str, Any]	):

    """simple docstring"""






    return self.image_processor_tester.prepare_image_processor_dict()



 def 						UpperCAmelCase    (	self   :   List[Any]	):

    """simple docstring"""






    lowercase__						:	int         = self.image_processing_class(**self.image_processor_dict	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_resize"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""size"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_center_crop"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""center_crop"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_normalize"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""image_mean"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""image_std"""	)	)
    self.assertTrue(hasattr(UpperCAmelCase__ ,		"""do_convert_rgb"""	)	)



 def 						UpperCAmelCase    (	self   :   str	):

    """simple docstring"""






    pass







 def 						UpperCAmelCase    (	self   :   List[str]	):

    """simple docstring"""






    lowercase__						:	List[Any]         = self.image_processing_class(**self.image_processor_dict	)
    # create random PIL images
    lowercase__						:	Any         = self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase__	)
    for image in image_inputs:
       self.assertIsInstance(UpperCAmelCase__ ,		Image.Image	)

    # Test not batched input
    lowercase__						:	Tuple         = image_processing(image_inputs[0] ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            1,
            self.expected_encoded_image_num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)

    # Test batched
    lowercase__						:	List[Any]         = image_processing(UpperCAmelCase__ ,		return_tensors="""pt"""	).pixel_values
    self.assertEqual(
        encoded_images.shape ,		(
            self.image_processor_tester.batch_size,
            self.expected_encoded_image_num_channels,
            self.image_processor_tester.crop_size["""height"""],
            self.image_processor_tester.crop_size["""width"""],
        ) ,		)










import os
import sys
import time

from . import transposition_cipher as trans_cipher
def       a__						(  ):
   lowercase__						:	Union[str, Any]         = """Prehistoric Men.txt"""
   lowercase__						:	Optional[Any]         = """Output.txt"""
   lowercase__						:	List[str]         = int(input("""Enter key: """					)					)
   lowercase__						:	Tuple         = input("""Encrypt/Decrypt [e/d]: """					)

   if not os.path.exists(A					):
      print(F'''File {input_file} does not exist. Quitting...'''					)
      sys.exit()
   if os.path.exists(A					):
      print(F'''Overwrite {output_file}? [y/n]'''					)
      lowercase__						:	List[Any]         = input("""> """					)
      if not response.lower().startswith("""y"""					):
         sys.exit()

   lowercase__						:	str         = time.time()
   if mode.lower().startswith("""e"""					):
      with open(A					) as f:
         lowercase__						:	Optional[int]         = f.read()
      lowercase__						:	List[str]         = trans_cipher.encrypt_message(A		,				A					)
   elif mode.lower().startswith("""d"""					):
      with open(A					) as f:
         lowercase__						:	int         = f.read()
      lowercase__						:	int         = trans_cipher.decrypt_message(A		,				A					)

   with open(A		,				"""w"""					) as output_obj:
      output_obj.write(A					)

   lowercase__						:	Optional[Any]         = round(time.time() - start_time		,				2					)
   print(("""Done (""", total_time, """seconds )""")					)


if __name__ == "__main__":
 main()


