





import unittest
from typing import Dict, List, Optional, Union

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 BridgeTowerImageProcessor





class UpperCAmelCase_				( unittest.TestCase ):


  def __init__(							self ,__snake_case ,__snake_case = True ,__snake_case = None ,__snake_case = 3_2 ,__snake_case = True ,__snake_case = 1 / 2_5_5 ,__snake_case = True ,__snake_case = True ,__snake_case = [0.4814_5466, 0.457_8275, 0.4082_1073] ,__snake_case = [0.2686_2954, 0.2613_0258, 0.2757_7711] ,__snake_case = True ,__snake_case=7 ,__snake_case=3_0 ,__snake_case=4_0_0 ,__snake_case=3 ,):



       """simple docstring"""





       A_          =       parent
       A_          =       do_resize
       A_          =       size if size is not None else {'''shortest_edge''': 2_8_8}
       A_          =       size_divisor
       A_          =       do_rescale
       A_          =       rescale_factor
       A_          =       do_normalize
       A_          =       do_center_crop
       A_          =       image_mean
       A_          =       image_std
       A_          =       do_pad
       A_          =       batch_size
       A_          =       num_channels
       A_          =       min_resolution
       A_          =       max_resolution


  def 						__UpperCAmelCase     (							self ):



       """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,
           "size_divisor": self.size_divisor,
       }




  def 						__UpperCAmelCase     (							self ,__snake_case ,__snake_case=False ):



       """simple docstring"""





       if not batched:
            A_          =       self.size['''shortest_edge''']
            A_          =       image_inputs[0]
            if isinstance(__snake_case ,Image.Image ):
                 A_   ,    A_          =       image.size
            else:
                 A_   ,    A_          =       image.shape[1], image.shape[2]
            A_          =       size / min(__snake_case ,__snake_case )
            if h < w:
                 A_   ,    A_          =       size, scale * w
            else:
                 A_   ,    A_          =       scale * h, size

            A_          =       int((1_3_3_3 / 8_0_0) * size )
            if max(__snake_case ,__snake_case ) > max_size:
                 A_          =       max_size / max(__snake_case ,__snake_case )
                 A_          =       newh * scale
                 A_          =       neww * scale

            A_   ,    A_          =       int(newh + 0.5 ), int(neww + 0.5 )
            A_   ,    A_          =       (
                newh // self.size_divisor * self.size_divisor,
                neww // self.size_divisor * self.size_divisor,
            )

       else:
            A_          =       []
            for image in image_inputs:
                 A_   ,    A_          =       self.get_expected_values([image] )
                 expected_values.append((expected_height, expected_width) )
            A_          =       max(__snake_case ,key=lambda __snake_case : item[0] )[0]
            A_          =       max(__snake_case ,key=lambda __snake_case : item[1] )[1]

       return expected_height, expected_width





@require_torch
@require_vision
class UpperCAmelCase_				( _SCREAMING_SNAKE_CASE     ,		unittest.TestCase ):
  __lowerCAmelCase   :						Optional[Any]							=   BridgeTowerImageProcessor if is_vision_available() else None


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       A_          =       BridgeTowerImageProcessingTester(self )


  @property
  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       return self.image_processor_tester.prepare_image_processor_dict()


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       A_          =       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''' ) )
       self.assertTrue(hasattr(__snake_case ,'''size_divisor''' ) )


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       pass


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       A_          =       self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       A_          =       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
       A_          =       image_processing(image_inputs[0] ,return_tensors='''pt''' ).pixel_values

       A_   ,    A_          =       self.image_processor_tester.get_expected_values(__snake_case )
       self.assertEqual(
           encoded_images.shape ,(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,)

       # Test batched
       A_          =       image_processing(__snake_case ,return_tensors='''pt''' ).pixel_values

       A_   ,    A_          =       self.image_processor_tester.get_expected_values(__snake_case ,batched=__snake_case )
       self.assertEqual(
           encoded_images.shape ,(
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ) ,)


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       A_          =       self.image_processing_class(**self.image_processor_dict )
       # create random numpy tensors
       A_          =       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
       A_          =       image_processing(image_inputs[0] ,return_tensors='''pt''' ).pixel_values

       A_   ,    A_          =       self.image_processor_tester.get_expected_values(__snake_case )
       self.assertEqual(
           encoded_images.shape ,(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,)

       # Test batched
       A_          =       image_processing(__snake_case ,return_tensors='''pt''' ).pixel_values

       A_   ,    A_          =       self.image_processor_tester.get_expected_values(__snake_case ,batched=__snake_case )
       self.assertEqual(
           encoded_images.shape ,(
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ) ,)




  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       A_          =       self.image_processing_class(**self.image_processor_dict )
       # create random PyTorch tensors
       A_          =       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
       A_          =       image_processing(image_inputs[0] ,return_tensors='''pt''' ).pixel_values

       A_   ,    A_          =       self.image_processor_tester.get_expected_values(__snake_case )
       self.assertEqual(
           encoded_images.shape ,(1, self.image_processor_tester.num_channels, expected_height, expected_width) ,)

       # Test batched
       A_          =       image_processing(__snake_case ,return_tensors='''pt''' ).pixel_values

       A_   ,    A_          =       self.image_processor_tester.get_expected_values(__snake_case ,batched=__snake_case )
       self.assertEqual(
           encoded_images.shape ,(
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ) ,)










import requests

a__      :     Any         =		'YOUR API KEY'

def      UpperCAmelCase_    (    _UpperCAmelCase							:str  ,						_UpperCAmelCase							:str = giphy_api_key				)	->				list:
     '''simple docstring'''


     A_          =       '''+'''.join(query.split()				)
     A_          =       f'https://api.giphy.com/v1/gifs/search?q={formatted_query}&api_key={api_key}'
     A_          =       requests.get(_UpperCAmelCase				).json()['''data''']
     return [gif["url"] for gif in gifs]


if __name__ == "__main__":
      print('\n'.join(get_gifs('space ship')))



