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


if is_torch_available():
       import torch

if is_vision_available():
       from PIL import Image

       from transformers import TvltImageProcessor







def 	__lowercase  (     snake_case_						:						str       ,snake_case_						:						str=10       ,snake_case_						:						Optional[Any]=10       ,snake_case_						:						Tuple=False       ,snake_case_						:						Dict=False		)     ->Union[str, Any]:



    '''simple docstring'''







    __A					:		Optional[int]						=  []
    for i in range(image_processor_tester.num_frames		):
        video.append(np.random.randint(255       ,size=(image_processor_tester.num_channels, width, height)       ,dtype=np.uinta		)		)

    if not numpify and not torchify:
        # PIL expects the channel dimension as last dimension
        __A					:		Union[str, Any]						=  [Image.fromarray(np.moveaxis(__lowerCamelCase       ,0       ,-1		)		) for frame in video]

    if torchify:
        __A					:		Optional[int]						=  [torch.from_numpy(__lowerCamelCase		) for frame in video]

    return video







def 	__lowercase  (     snake_case_						:						int       ,snake_case_						:						List[Any]=False       ,snake_case_						:						Tuple=False       ,snake_case_						:						str=False		)     ->List[Any]:



    '''simple docstring'''







    assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

    __A					:		List[Any]						=  []
    for i in range(image_processor_tester.batch_size		):
        if equal_resolution:
            __A					:		Dict						=  image_processor_tester.max_resolution
        else:
            __A				, __A					:		Optional[Any]						=  np.random.choice(
                np.arange(image_processor_tester.min_resolution       ,image_processor_tester.max_resolution		)       ,2		)
            __A					:		Optional[Any]						=  prepare_video(
                image_processor_tester=__lowerCamelCase       ,width=__lowerCamelCase       ,height=__lowerCamelCase       ,numpify=__lowerCamelCase       ,torchify=__lowerCamelCase       ,)
        video_inputs.append(__lowerCamelCase		)

    return video_inputs






class 	__snake_case      (	unittest.TestCase  ):





 """simple docstring"""


 def __init__(					self      ,		__lowerCamelCase      ,		__lowerCamelCase=7      ,		__lowerCamelCase=3      ,		__lowerCamelCase=4      ,		__lowerCamelCase=18      ,		__lowerCamelCase=30      ,		__lowerCamelCase=400      ,		__lowerCamelCase=True      ,		__lowerCamelCase=None      ,		__lowerCamelCase=True      ,		__lowerCamelCase=[0.5, 0.5, 0.5]      ,		__lowerCamelCase=[0.5, 0.5, 0.5]      ,		__lowerCamelCase=True      ,		__lowerCamelCase=None      ,		):



     '''simple docstring'''




     __A					:		str						=  size if size is not None else {'''shortest_edge''': 18}
     __A					:		List[Any]						=  crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

     __A					:		Any						=  parent
     __A					:		Optional[int]						=  batch_size
     __A					:		List[str]						=  num_channels
     __A					:		Tuple						=  num_frames
     __A					:		Optional[Any]						=  image_size
     __A					:		Optional[int]						=  min_resolution
     __A					:		List[str]						=  max_resolution
     __A					:		int						=  do_resize
     __A					:		Optional[Any]						=  size
     __A					:		Optional[Any]						=  do_normalize
     __A					:		Union[str, Any]						=  image_mean
     __A					:		Union[str, Any]						=  image_std
     __A					:		List[str]						=  do_center_crop
     __A					:		Union[str, Any]						=  crop_size







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






@require_torch
@require_vision
class 	__snake_case      (	snake_case_							,							unittest.TestCase  ):





 """simple docstring"""


 _lowerCamelCase				 =  TvltImageProcessor if is_vision_available() else None

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[int]						=  TvltImageProcessorTester(self						)

 @property
 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     return self.image_processor_tester.prepare_image_processor_dict()

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[int]						=  self.image_processing_class(**self.image_processor_dict						)
     self.assertTrue(hasattr(__lowerCamelCase      ,		'''image_mean'''						)						)
     self.assertTrue(hasattr(__lowerCamelCase      ,		'''image_std'''						)						)
     self.assertTrue(hasattr(__lowerCamelCase      ,		'''do_normalize'''						)						)
     self.assertTrue(hasattr(__lowerCamelCase      ,		'''do_resize'''						)						)
     self.assertTrue(hasattr(__lowerCamelCase      ,		'''do_center_crop'''						)						)
     self.assertTrue(hasattr(__lowerCamelCase      ,		'''size'''						)						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		str						=  self.image_processing_class(**self.image_processor_dict						)
     # create random PIL videos
     __A					:		str						=  prepare_video_inputs(self.image_processor_tester      ,		equal_resolution=__lowerCamelCase						)
     for video in video_inputs:
         self.assertIsInstance(__lowerCamelCase      ,		__lowerCamelCase						)
         self.assertIsInstance(video[0]      ,		Image.Image						)

     # Test not batched input
     __A					:		int						=  image_processor(video_inputs[0]      ,		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_videos.shape      ,		(
             1,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         )      ,		)

     # Test batched
     __A					:		Optional[Any]						=  image_processor(__lowerCamelCase      ,		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_videos.shape      ,		(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         )      ,		)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[str]						=  self.image_processing_class(**self.image_processor_dict						)
     # create random numpy tensors
     __A					:		Tuple						=  prepare_video_inputs(self.image_processor_tester      ,		equal_resolution=__lowerCamelCase      ,		numpify=__lowerCamelCase						)
     for video in video_inputs:
         self.assertIsInstance(__lowerCamelCase      ,		__lowerCamelCase						)
         self.assertIsInstance(video[0]      ,		np.ndarray						)

     # Test not batched input
     __A					:		Union[str, Any]						=  image_processor(video_inputs[0]      ,		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_videos.shape      ,		(
             1,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         )      ,		)

     # Test batched
     __A					:		List[str]						=  image_processor(__lowerCamelCase      ,		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_videos.shape      ,		(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         )      ,		)







 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		int						=  self.image_processing_class(**self.image_processor_dict						)
     # create random PyTorch tensors
     __A					:		int						=  prepare_video_inputs(self.image_processor_tester      ,		equal_resolution=__lowerCamelCase      ,		torchify=__lowerCamelCase						)
     for video in video_inputs:
         self.assertIsInstance(__lowerCamelCase      ,		__lowerCamelCase						)
         self.assertIsInstance(video[0]      ,		torch.Tensor						)

     # Test not batched input
     __A					:		int						=  image_processor(video_inputs[0]      ,		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_videos.shape      ,		(
             1,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         )      ,		)

     # Test batched
     __A					:		Optional[int]						=  image_processor(__lowerCamelCase      ,		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_videos.shape      ,		(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         )      ,		)











"""simple docstring"""



import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


a_				=    """
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
"""






class 	__snake_case      (	unittest.TestCase							,							SCREAMING_SNAKE_CASE__  ):





 """simple docstring"""


 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[Any]						=  load_tool('''summarization'''						)
     self.tool.setup()
     __A					:		Tuple						=  load_tool('''summarization'''      ,		remote=__lowerCamelCase						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[str]						=  self.tool(__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		int						=  self.remote_tool(__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[Any]						=  self.tool(text=__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)







 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[int]						=  self.remote_tool(text=__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)




