
"""simple docstring"""




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 						lowercase(unittest.TestCase					):



     def __init__(       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE=7    ,							__SCREAMING_SNAKE_CASE=3    ,							__SCREAMING_SNAKE_CASE=1_8    ,							__SCREAMING_SNAKE_CASE=3_0    ,							__SCREAMING_SNAKE_CASE=4_0_0    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=None    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=None    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]    ,							__SCREAMING_SNAKE_CASE=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]    ,							__SCREAMING_SNAKE_CASE=True    ,							)		->    str:







         """simple docstring"""



         a__    = size if size is not None else {'shortest_edge': 2_0}
         a__    = crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
         a__    = parent
         a__    = batch_size
         a__    = num_channels
         a__    = image_size
         a__    = min_resolution
         a__    = max_resolution
         a__    = do_resize
         a__    = size
         a__    = do_center_crop
         a__    = crop_size
         a__    = do_normalize
         a__    = image_mean
         a__    = image_std
         a__    = do_convert_rgb



     def  lowercase__     (       self      )		->    Tuple:







         """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  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE=False    ,							__SCREAMING_SNAKE_CASE=False    ,							__SCREAMING_SNAKE_CASE=False      )		->    Dict:







         """simple docstring"""



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

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

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

         if torchify:
             a__    = [torch.from_numpy(__SCREAMING_SNAKE_CASE      ) for x in image_inputs]

         return image_inputs







@require_torch
@require_vision
class 						lowercase(_lowercase						,	unittest.TestCase					):
     __snake_case:  Optional[Any]  				=    CLIPImageProcessor if is_vision_available() else None



     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         a__    = CLIPImageProcessingTester(self      )



     @property
     def  lowercase__     (       self      )		->    int:







         """simple docstring"""



         return self.image_processor_tester.prepare_image_processor_dict()



     def  lowercase__     (       self      )		->    Tuple:







         """simple docstring"""



         a__    = self.image_processing_class(**self.image_processor_dict      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_resize'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'size'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_center_crop'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'center_crop'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_normalize'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'image_mean'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'image_std'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_convert_rgb'      )      )



     def  lowercase__     (       self      )		->    int:







         """simple docstring"""



         a__    = self.image_processing_class.from_dict(self.image_processor_dict      )
         self.assertEqual(image_processor.size    ,							{'shortest_edge': 2_0}      )
         self.assertEqual(image_processor.crop_size    ,							{'height': 1_8, 'width': 1_8}      )

         a__    = self.image_processing_class.from_dict(self.image_processor_dict    ,							size=4_2    ,							crop_size=8_4      )
         self.assertEqual(image_processor.size    ,							{'shortest_edge': 4_2}      )
         self.assertEqual(image_processor.crop_size    ,							{'height': 8_4, 'width': 8_4}      )



     def  lowercase__     (       self      )		->    Tuple:







         """simple docstring"""



         pass



     def  lowercase__     (       self      )		->    List[str]:







         """simple docstring"""



         a__    = self.image_processing_class(**self.image_processor_dict      )
         # create random PIL images
         a__    = self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE      )
         for image in image_inputs:
             self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							Image.Image      )

         # Test not batched input
         a__    = 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
         a__    = image_processing(__SCREAMING_SNAKE_CASE    ,							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  lowercase__     (       self      )		->    Dict:







         """simple docstring"""



         a__    = self.image_processing_class(**self.image_processor_dict      )
         # create random numpy tensors
         a__    = self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE    ,							numpify=__SCREAMING_SNAKE_CASE      )
         for image in image_inputs:
             self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							np.ndarray      )

         # Test not batched input
         a__    = 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
         a__    = image_processing(__SCREAMING_SNAKE_CASE    ,							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  lowercase__     (       self      )		->    Any:







         """simple docstring"""



         a__    = self.image_processing_class(**self.image_processor_dict      )
         # create random PyTorch tensors
         a__    = self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE    ,							torchify=__SCREAMING_SNAKE_CASE      )
         for image in image_inputs:
             self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							torch.Tensor      )

         # Test not batched input
         a__    = 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
         a__    = image_processing(__SCREAMING_SNAKE_CASE    ,							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 						lowercase(_lowercase						,	unittest.TestCase					):
     __snake_case:  Dict  				=    CLIPImageProcessor if is_vision_available() else None



     def  lowercase__     (       self      )		->    Optional[int]:







         """simple docstring"""



         a__    = CLIPImageProcessingTester(self    ,							num_channels=4      )
         a__    = 3



     @property
     def  lowercase__     (       self      )		->    Any:







         """simple docstring"""



         return self.image_processor_tester.prepare_image_processor_dict()



     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         a__    = self.image_processing_class(**self.image_processor_dict      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_resize'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'size'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_center_crop'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'center_crop'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_normalize'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'image_mean'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'image_std'      )      )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,							'do_convert_rgb'      )      )



     def  lowercase__     (       self      )		->    Any:







         """simple docstring"""



         pass




     def  lowercase__     (       self      )		->    Optional[int]:







         """simple docstring"""



         a__    = self.image_processing_class(**self.image_processor_dict      )
         # create random PIL images
         a__    = self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE      )
         for image in image_inputs:
             self.assertIsInstance(__SCREAMING_SNAKE_CASE    ,							Image.Image      )

         # Test not batched input
         a__    = 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
         a__    = image_processing(__SCREAMING_SNAKE_CASE    ,							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'],
             )    ,							)




"""simple docstring"""




import shutil

import requests



def 						__magic_name__		(				UpperCamelCase    :		str       ,		UpperCamelCase    :		bool = False       ,		UpperCamelCase    :		str = "."    )    ->	dict:
    a__    = 'https://api.nasa.gov/planetary/apod'
    return requests.get(UpperCamelCase       ,		params={'api_key': api_key}    ).json()



def 						__magic_name__		(				UpperCamelCase    :		str       ,		UpperCamelCase    :		str = "."    )    ->	dict:
    a__    = get_apod_data(UpperCamelCase    )
    a__    = apod_data['url']
    a__    = img_url.split('/'    )[-1]
    a__    = requests.get(UpperCamelCase       ,		stream=UpperCamelCase    )

    with open(f'{path}/{img_name}'       ,		'wb+'    ) as img_file:
        shutil.copyfileobj(response.raw       ,		UpperCamelCase    )
    del response
    return apod_data



def 						__magic_name__		(				UpperCamelCase    :		str    )    ->	dict:
    a__    = 'https://images-api.nasa.gov/search'
    return requests.get(UpperCamelCase       ,		params={'q': query}    ).json()


if __name__ == "__main__":
    print(save_apod('YOUR API KEY'))
    a		:					List[Any]    	=					get_archive_data('apollo 2011')['collection']['items']
    print(apollo_aaaa_items[0]['data'][0]['description'])


