




import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
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:	Tuple     =IFImgaImgPipeline
     _snake_case:	Union[str, Any]     =TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
     _snake_case:	Optional[Any]     =TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     _snake_case:	Optional[int]     =PipelineTesterMixin.required_optional_params - {"latents"}




     def  __snake_case   (    self  :   Optional[Any]			)				->       int:
           return self._get_dummy_components()




     def  __snake_case   (    self  :   str	,  A__  :   Any	,  A__  :   Optional[int]=0			)				->       Optional[Any]:
           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




     def  __snake_case   (    self  :   Dict			)				->       Union[str, Any]:
           self._test_save_load_optional_components()




     @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  :   Tuple			)				->       Union[str, Any]:
           self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3			)




     @unittest.skipIf(torch_device != 'cuda'	,  reason='float16 requires CUDA'			)
     def  __snake_case   (    self  :   Tuple			)				->       List[Any]:
           # 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			)




     @unittest.skipIf(torch_device != 'cuda'	,  reason='float16 requires CUDA'			)
     def  __snake_case   (    self  :   List[str]			)				->       Tuple:
           super().test_floataa_inference(expected_max_diff=1E-1			)




     def  __snake_case   (    self  :   Dict			)				->       str:
           self._test_attention_slicing_forward_pass(expected_max_diff=1E-2			)




     def  __snake_case   (    self  :   Union[str, Any]			)				->       Union[str, Any]:
           self._test_save_load_local()




     def  __snake_case   (    self  :   Union[str, Any]			)				->       Dict:
           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"""])