





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







							"""simple docstring"""




							def __init__(					self	:     List[str], _UpperCAmelCase	:     Union[str, Any], _UpperCAmelCase	:     Tuple=1_3, _UpperCAmelCase	:     List[str]=3, _UpperCAmelCase	:     Dict=1_8, _UpperCAmelCase	:     Optional[Any]=3_0, _UpperCAmelCase	:     Optional[Any]=4_0_0, _UpperCAmelCase	:     List[Any]=True, _UpperCAmelCase	:     Any=None, _UpperCAmelCase	:     str=True, _UpperCAmelCase	:     List[Any]=[0.5, 0.5, 0.5], _UpperCAmelCase	:     List[str]=[0.5, 0.5, 0.5], )      -> str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   :			Tuple      =						size if size is not None else {"height": 1_8, "width": 1_8}
														SCREAMING_SNAKE_CASE__   :			int      =						parent
														SCREAMING_SNAKE_CASE__   :			Optional[Any]      =						batch_size
														SCREAMING_SNAKE_CASE__   :			Optional[Any]      =						num_channels
														SCREAMING_SNAKE_CASE__   :			Union[str, Any]      =						image_size
														SCREAMING_SNAKE_CASE__   :			Any      =						min_resolution
														SCREAMING_SNAKE_CASE__   :			Union[str, Any]      =						max_resolution
														SCREAMING_SNAKE_CASE__   :			Dict      =						do_resize
														SCREAMING_SNAKE_CASE__   :			Dict      =						size
														SCREAMING_SNAKE_CASE__   :			int      =						do_normalize
														SCREAMING_SNAKE_CASE__   :			Union[str, Any]      =						image_mean
														SCREAMING_SNAKE_CASE__   :			Tuple      =						image_std






							def 					A_	(					self	:     Union[str, Any]						)      -> Tuple:





														"""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 						lowerCamelCase   (__lowerCamelCase							,	unittest.TestCase			):







							"""simple docstring"""




							UpperCAmelCase_									=    EfficientNetImageProcessor if is_vision_available() else None






							def 					A_	(					self	:     Optional[int]						)      -> Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   :			Any      =						EfficientNetImageProcessorTester(self						)






							@property
							def 					A_	(					self	:     Tuple						)      -> Optional[Any]:





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






							def 					A_	(					self	:     List[Any]						)      -> Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   :			Tuple      =						self.image_processing_class(**self.image_processor_dict						)
														self.assertTrue(hasattr(snake_case__, "image_mean"						)						)
														self.assertTrue(hasattr(snake_case__, "image_std"						)						)
														self.assertTrue(hasattr(snake_case__, "do_normalize"						)						)
														self.assertTrue(hasattr(snake_case__, "do_resize"						)						)
														self.assertTrue(hasattr(snake_case__, "size"						)						)






							def 					A_	(					self	:     str						)      -> Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   :			List[Any]      =						self.image_processing_class.from_dict(self.image_processor_dict						)
														self.assertEqual(image_processor.size, {"height": 1_8, "width": 1_8}						)

														SCREAMING_SNAKE_CASE__   :			Union[str, Any]      =						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	:     List[Any]						)      -> Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   :			Optional[int]      =						self.image_processing_class(**self.image_processor_dict						)
														# create random PIL images
														SCREAMING_SNAKE_CASE__   :			int      =						prepare_image_inputs(self.image_processor_tester, equal_resolution=snake_case__						)
														for image in image_inputs:
																					self.assertIsInstance(snake_case__, Image.Image						)

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

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






							def 					A_	(					self	:     Any						)      -> List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   :			Any      =						self.image_processing_class(**self.image_processor_dict						)
														# create random numpy tensors
														SCREAMING_SNAKE_CASE__   :			str      =						prepare_image_inputs(self.image_processor_tester, equal_resolution=snake_case__, numpify=snake_case__						)
														for image in image_inputs:
																					self.assertIsInstance(snake_case__, np.ndarray						)

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

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






							def 					A_	(					self	:     List[str]						)      -> Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   :			Optional[Any]      =						self.image_processing_class(**self.image_processor_dict						)
														# create random PyTorch tensors
														SCREAMING_SNAKE_CASE__   :			str      =						prepare_image_inputs(self.image_processor_tester, equal_resolution=snake_case__, torchify=snake_case__						)
														for image in image_inputs:
																					self.assertIsInstance(snake_case__, torch.Tensor						)

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

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














"""simple docstring"""



import shutil

import requests


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      str       , snake_case    :      bool = False       , snake_case    :      str = "."							)->						dict:






     '''simple docstring'''



     UpperCAmelCase__		:  Union[str, Any]				=				"https://api.nasa.gov/planetary/apod"
     return requests.get(snake_case       , params={"api_key": api_key}							).json()


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      str       , snake_case    :      str = "."							)->						dict:






     '''simple docstring'''



     UpperCAmelCase__		:  List[Any]				=				get_apod_data(snake_case							)
     UpperCAmelCase__		:  str				=				apod_data["url"]
     UpperCAmelCase__		:  Tuple				=				img_url.split("/"							)[-1]
     UpperCAmelCase__		:  Dict				=				requests.get(snake_case       , stream=snake_case							)

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


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      str							)->						dict:






     '''simple docstring'''



     UpperCAmelCase__		:  List[str]				=				"https://images-api.nasa.gov/search"
     return requests.get(snake_case       , params={"q": query}							).json()


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


