




import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin






@skip_mps
class 			A			(		_lowerCAmelCase			,						_lowerCAmelCase			,						unittest.TestCase		):
     """simple docstring"""

     _snake_case:	str     =IFSuperResolutionPipeline
     _snake_case:	List[Any]     =TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
     _snake_case:	Optional[Any]     =TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     _snake_case:	int     =PipelineTesterMixin.required_optional_params - {"latents"}




     def  __snake_case   (    self  :   List[Any]			)				->       List[Any]:
           return self._get_superresolution_dummy_components()




     def  __snake_case   (    self  :   Dict	,  A__  :   Union[str, Any]	,  A__  :   Optional[int]=0			)				->       int:
           if str(A__			).startswith('mps'			):
                 lowerCamelCase__        =				torch.manual_seed(A__			)
           else:
                 lowerCamelCase__        =				torch.Generator(device=A__			).manual_seed(A__			)

           lowerCamelCase__        =				floats_tensor((1, 3, 3_2, 3_2)	,  rng=random.Random(A__			)			).to(A__			)

           lowerCamelCase__        =				{
               'prompt': 'A painting of a squirrel eating a burger',
               'image': image,
               'generator': generator,
               'num_inference_steps': 2,
               'output_type': 'numpy',
           }

           return inputs




     @unittest.skipIf(
         torch_device != 'cuda' or not is_xformers_available()	,  reason='XFormers attention is only available with CUDA and `xformers` installed'	,  )
     def  __snake_case   (    self  :   Dict			)				->       Optional[int]:
           self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3			)




     def  __snake_case   (    self  :   Optional[int]			)				->       Tuple:
           self._test_save_load_optional_components()




     @unittest.skipIf(torch_device != 'cuda'	,  reason='float16 requires CUDA'			)
     def  __snake_case   (    self  :   Optional[int]			)				->       Dict:
           # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
           super().test_save_load_floataa(expected_max_diff=1E-1			)




     def  __snake_case   (    self  :   List[str]			)				->       Tuple:
           self._test_attention_slicing_forward_pass(expected_max_diff=1E-2			)




     def  __snake_case   (    self  :   Tuple			)				->       Optional[Any]:
           self._test_save_load_local()




     def  __snake_case   (    self  :   List[Any]			)				->       str:
           self._test_inference_batch_single_identical(
               expected_max_diff=1E-2	,  )





import shutil

import requests

def 			lowerCAmelCase_			(  lowerCamelCase:       str     ,				lowerCamelCase:       bool = False     ,				lowerCamelCase:       str = "."						)					->			dict:


      '''simple docstring'''




      lowerCamelCase__        =				'https://api.nasa.gov/planetary/apod'
      return requests.get(lowerCamelCase     ,				params={'api_key': api_key}						).json()

def 			lowerCAmelCase_			(  lowerCamelCase:       str     ,				lowerCamelCase:       str = "."						)					->			dict:


      '''simple docstring'''




      lowerCamelCase__        =				get_apod_data(lowerCamelCase						)
      lowerCamelCase__        =				apod_data['url']
      lowerCamelCase__        =				img_url.split('/'						)[-1]
      lowerCamelCase__        =				requests.get(lowerCamelCase     ,				stream=lowerCamelCase						)

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

def 			lowerCAmelCase_			(  lowerCamelCase:       str						)					->			dict:


      '''simple docstring'''




      lowerCamelCase__        =				'https://images-api.nasa.gov/search'
      return requests.get(lowerCamelCase     ,				params={'q': query}						).json()


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