






"""simple docstring"""



import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY



@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class 					a						(       unittest.TestCase				):



    """simple docstring"""



    UpperCAmelCase						 =					MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

    def 				UpperCamelCase	(     self: Any    ,						UpperCamelCase: Dict    ,						UpperCamelCase: List[str]    ,						UpperCamelCase: Optional[int]       ):






         """simple docstring"""


         A__										=  hf_hub_download(
             repo_id="""nateraw/video-demo"""    ,						filename="""archery.mp4"""    ,						repo_type="""dataset"""       )
         A__										=  VideoClassificationPipeline(model=__lowerCamelCase    ,						image_processor=__lowerCamelCase    ,						top_k=2       )
         A__										=  [
             example_video_filepath,
             "https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4",
         ]
         return video_classifier, examples

    def 				UpperCamelCase	(     self: str    ,						UpperCamelCase: Union[str, Any]    ,						UpperCamelCase: Optional[Any]       ):






         """simple docstring"""


         for example in examples:
              A__										=  video_classifier(__lowerCamelCase       )

              self.assertEqual(
                  __lowerCamelCase    ,						[
                      {"""score""": ANY(__lowerCamelCase       ), """label""": ANY(__lowerCamelCase       )},
                      {"""score""": ANY(__lowerCamelCase       ), """label""": ANY(__lowerCamelCase       )},
                  ]    ,						)

    @require_torch
    def 				UpperCamelCase	(     self: Optional[Any]       ):






         """simple docstring"""


         A__										=  "hf-internal-testing/tiny-random-VideoMAEForVideoClassification"
         A__										=  VideoMAEFeatureExtractor(
             size={"""shortest_edge""": 10}    ,						crop_size={"""height""": 10, """width""": 10}       )
         A__										=  pipeline(
             """video-classification"""    ,						model=__lowerCamelCase    ,						feature_extractor=__lowerCamelCase    ,						frame_sampling_rate=4       )

         A__										=  hf_hub_download(repo_id="""nateraw/video-demo"""    ,						filename="""archery.mp4"""    ,						repo_type="""dataset"""       )
         A__										=  video_classifier(__lowerCamelCase    ,						top_k=2       )
         self.assertEqual(
             nested_simplify(__lowerCamelCase    ,						decimals=4       )    ,						[{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}]    ,						)

         A__										=  video_classifier(
             [
                 video_file_path,
                 video_file_path,
             ]    ,						top_k=2    ,						)
         self.assertEqual(
             nested_simplify(__lowerCamelCase    ,						decimals=4       )    ,						[
                 [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}],
                 [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}],
             ]    ,						)





    @require_tf
    def 				UpperCamelCase	(     self: Dict       ):






         """simple docstring"""


         pass









"""simple docstring"""



from collections.abc import Callable





def  _snake_case     (    UpperCAmelCase_  :					Callable[[float], float]					,   UpperCAmelCase_  :					float					,   UpperCAmelCase_  :					float			):
     A__										=  a
     A__										=  b
     if function(UpperCAmelCase_			) == 0:  # one of the a or b is a root for the function
          return a
     elif function(UpperCAmelCase_			) == 0:
          return b
     elif (
         function(UpperCAmelCase_			) * function(UpperCAmelCase_			) > 0
     ):  # if none of these are root and they are both positive or negative,
          # then this algorithm can't find the root
          raise ValueError("""could not find root in given interval."""			)
     else:
          A__										=  start + (end - start) / 2.0
          while abs(start - mid			) > 10**-7:  # until precisely equals to 10^-7
               if function(UpperCAmelCase_			) == 0:
                    return mid
               elif function(UpperCAmelCase_			) * function(UpperCAmelCase_			) < 0:
                    A__										=  mid
               else:
                    A__										=  mid
               A__										=  start + (end - start) / 2.0
          return mid





def  _snake_case     (    UpperCAmelCase_  :					float			):
     return x**3 - 2 * x - 5


if __name__ == "__main__":
 print(bisection(f, 1, 1_0_0_0))

 import doctest

 doctest.testmod()






