"""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, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import EfficientNetImageProcessor


class       _lowercase		( unittest.TestCase	):

				def __init__(  self							:     List[Any]							,     _lowercase							:     Optional[Any]							,     _lowercase							:     Any=1_3							,     _lowercase							:     List[str]=3							,     _lowercase							:     Dict=1_8							,     _lowercase							:     int=3_0							,     _lowercase							:     List[str]=4_0_0							,     _lowercase							:     List[Any]=True							,     _lowercase							:     str=None							,     _lowercase							:     Any=True							,     _lowercase							:     Optional[int]=[0.5, 0.5, 0.5]							,     _lowercase							:     List[Any]=[0.5, 0.5, 0.5]							,     ):


										'''simple docstring'''
										UpperCAmelCase__       						=		size if size is not None else {"""height""": 1_8, """width""": 1_8}
										UpperCAmelCase__       						=		parent
										UpperCAmelCase__       						=		batch_size
										UpperCAmelCase__       						=		num_channels
										UpperCAmelCase__       						=		image_size
										UpperCAmelCase__       						=		min_resolution
										UpperCAmelCase__       						=		max_resolution
										UpperCAmelCase__       						=		do_resize
										UpperCAmelCase__       						=		size
										UpperCAmelCase__       						=		do_normalize
										UpperCAmelCase__       						=		image_mean
										UpperCAmelCase__       						=		image_std

				def 							A			(  self							:     Optional[int]  ):


										'''simple docstring'''
										return {
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_normalize": self.do_normalize,
										    "do_resize": self.do_resize,
										    "size": self.size,
										}


@require_torch
@require_vision
class       _lowercase		( __lowerCamelCase   ,   unittest.TestCase	):
				lowerCamelCase__							=							EfficientNetImageProcessor if is_vision_available() else None

				def 							A			(  self							:     Optional[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		EfficientNetImageProcessorTester(self  )

				@property
				def 							A			(  self							:     List[str]  ):


										'''simple docstring'''
										return self.image_processor_tester.prepare_image_processor_dict()

				def 							A			(  self							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.image_processing_class(**self.image_processor_dict  )
										self.assertTrue(hasattr(_lowercase							,     """image_mean"""  )  )
										self.assertTrue(hasattr(_lowercase							,     """image_std"""  )  )
										self.assertTrue(hasattr(_lowercase							,     """do_normalize"""  )  )
										self.assertTrue(hasattr(_lowercase							,     """do_resize"""  )  )
										self.assertTrue(hasattr(_lowercase							,     """size"""  )  )

				def 							A			(  self							:     List[str]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.image_processing_class.from_dict(self.image_processor_dict  )
										self.assertEqual(image_processor.size							,     {"""height""": 1_8, """width""": 1_8}  )

										UpperCAmelCase__       						=		self.image_processing_class.from_dict(self.image_processor_dict							,     size=4_2  )
										self.assertEqual(image_processor.size							,     {"""height""": 4_2, """width""": 4_2}  )

				def 							A			(  self							:     int  ):


										'''simple docstring'''
										# Initialize image_processing
										UpperCAmelCase__       						=		self.image_processing_class(**self.image_processor_dict  )
										# create random PIL images
										UpperCAmelCase__       						=		prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_lowercase  )
										for image in image_inputs:
																self.assertIsInstance(_lowercase							,     Image.Image  )

										# Test not batched input
										UpperCAmelCase__       						=		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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )							,     )

										# Test batched
										UpperCAmelCase__       						=		image_processing(_lowercase							,     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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )							,     )

				def 							A			(  self							:     Optional[int]  ):


										'''simple docstring'''
										# Initialize image_processing
										UpperCAmelCase__       						=		self.image_processing_class(**self.image_processor_dict  )
										# create random numpy tensors
										UpperCAmelCase__       						=		prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_lowercase							,     numpify=_lowercase  )
										for image in image_inputs:
																self.assertIsInstance(_lowercase							,     np.ndarray  )

										# Test not batched input
										UpperCAmelCase__       						=		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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )							,     )

										# Test batched
										UpperCAmelCase__       						=		image_processing(_lowercase							,     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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )							,     )

				def 							A			(  self							:     Optional[Any]  ):


										'''simple docstring'''
										# Initialize image_processing
										UpperCAmelCase__       						=		self.image_processing_class(**self.image_processor_dict  )
										# create random PyTorch tensors
										UpperCAmelCase__       						=		prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_lowercase							,     torchify=_lowercase  )
										for image in image_inputs:
																self.assertIsInstance(_lowercase							,     torch.Tensor  )

										# Test not batched input
										UpperCAmelCase__       						=		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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )							,     )

										# Test batched
										UpperCAmelCase__       						=		image_processing(_lowercase							,     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.size["""height"""],
										        self.image_processor_tester.size["""width"""],
										    )							,     )


"""simple docstring"""







import shutil

import requests


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


def 	a__   (		UpperCAmelCase__							:      str		,      UpperCAmelCase__							:      str = "."      )->						dict:
						UpperCAmelCase__       						=		get_apod_data(UpperCAmelCase__      )
						UpperCAmelCase__       						=		apod_data["""url"""]
						UpperCAmelCase__       						=		img_url.split("""/"""      )[-1]
						UpperCAmelCase__       						=		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 	a__   (		UpperCAmelCase__							:      str      )->						dict:
						UpperCAmelCase__       						=		"""https://images-api.nasa.gov/search"""
						return requests.get(UpperCAmelCase__		,      params={"""q""": query}      ).json()


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

