





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_video_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import VivitImageProcessor







class      lowerCamelCase(						unittest.TestCase	):
     '''simple docstring'''


     def __init__(    self				,     snake_case_				,     snake_case_=7				,     snake_case_=3				,     snake_case_=10				,     snake_case_=18				,     snake_case_=30				,     snake_case_=400				,     snake_case_=True				,     snake_case_=None				,     snake_case_=True				,     snake_case_=[0.5, 0.5, 0.5]				,     snake_case_=[0.5, 0.5, 0.5]				,     snake_case_=None				,     ):
         _A     =							size if size is not None else {"""shortest_edge""": 18}
         _A     =							crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

         _A     =							parent
         _A     =							batch_size
         _A     =							num_channels
         _A     =							num_frames
         _A     =							image_size
         _A     =							min_resolution
         _A     =							max_resolution
         _A     =							do_resize
         _A     =							size
         _A     =							do_normalize
         _A     =							image_mean
         _A     =							image_std
         _A     =							crop_size




     def        lowerCAmelCase__		(    self							):
         return {
             "image_mean": self.image_mean,
             "image_std": self.image_std,
             "do_normalize": self.do_normalize,
             "do_resize": self.do_resize,
             "size": self.size,
             "crop_size": self.crop_size,
         }







@require_torch
@require_vision
class      lowerCamelCase(						lowerCAmelCase__			, unittest.TestCase	):
     '''simple docstring'''


     __magic_name__   =			VivitImageProcessor if is_vision_available() else None




     def        lowerCAmelCase__		(    self							):
         _A     =							VivitImageProcessingTester(self							)




     @property
     def        lowerCAmelCase__		(    self							):
         return self.image_processor_tester.prepare_image_processor_dict()




     def        lowerCAmelCase__		(    self							):
         _A     =							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        lowerCAmelCase__		(    self							):
         _A     =							self.image_processing_class.from_dict(self.image_processor_dict							)
         self.assertEqual(image_processor.size				,     {'shortest_edge': 18}							)
         self.assertEqual(image_processor.crop_size				,     {'height': 18, 'width': 18}							)

         _A     =							self.image_processing_class.from_dict(self.image_processor_dict				,     size=42				,     crop_size=84							)
         self.assertEqual(image_processor.size				,     {'shortest_edge': 42}							)
         self.assertEqual(image_processor.crop_size				,     {'height': 84, 'width': 84}							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.image_processing_class(**self.image_processor_dict							)
         # create random PIL videos
         _A     =							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     =							image_processing(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     =							image_processing(_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        lowerCAmelCase__		(    self							):
         _A     =							self.image_processing_class(**self.image_processor_dict							)
         # create random numpy tensors
         _A     =							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     =							image_processing(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     =							image_processing(_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        lowerCAmelCase__		(    self							):
         _A     =							self.image_processing_class(**self.image_processor_dict							)
         # create random PyTorch tensors
         _A     =							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     =							image_processing(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     =							image_processing(_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 requests




def 					a__						(						lowerCAmelCase			,	lowerCAmelCase    )	-> None:
      UpperCAmelCase__			:							List[str]							=    {"""Content-Type""": """application/json"""}
      UpperCAmelCase__			:							List[str]							=    requests.post(lowerCAmelCase			,	json={"""text""": message_body}			,	headers=lowerCAmelCase    )
      if response.status_code != 2_00:
            UpperCAmelCase__			:							str							=    (
                """Request to slack returned an error """
                F"""{response.status_code}, the response is:\n{response.text}"""
            )
            raise ValueError(lowerCAmelCase    )


if __name__ == "__main__":
    # Set the slack url to the one provided by Slack when you create the webhook at
    # https://my.slack.com/services/new/incoming-webhook/
    send_slack_message("""<YOUR MESSAGE BODY>""", """<SLACK CHANNEL URL>""")

