






'''simple docstring'''







import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class   __SCREAMING_SNAKE_CASE       (UpperCAmelCase__       ):


  """simple docstring"""


  _a  : str      			=     ['''image_processor''', '''tokenizer''']
  _a  : int      			=     '''AutoImageProcessor'''
  _a  : Dict      			=     '''AutoTokenizer'''







  def __init__(			self   ,	UpperCamelCase__=None   ,	UpperCamelCase__=None   ,	**UpperCamelCase__	):






         """simple docstring"""


         a_						     =			None
         if "feature_extractor" in kwargs:
                warnings.warn(
                    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
                    ' instead.'   ,	_UpperCAmelCase   ,	)
                a_						     =			kwargs.pop('feature_extractor'	)

         a_						     =			image_processor if image_processor is not None else feature_extractor
         if image_processor is None:
                raise ValueError('You need to specify an `image_processor`.'	)
         if tokenizer is None:
                raise ValueError('You need to specify a `tokenizer`.'	)

         super().__init__(_UpperCAmelCase   ,	_UpperCAmelCase	)
         a_						     =			self.image_processor
         a_						     =			False







  def __call__(			self   ,	*UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         if self._in_target_context_manager:
                return self.current_processor(*_UpperCAmelCase   ,	**_UpperCAmelCase	)

         a_						     =			kwargs.pop('images'   ,	_UpperCAmelCase	)
         a_						     =			kwargs.pop('text'   ,	_UpperCAmelCase	)
         if len(_UpperCAmelCase	) > 0:
                a_						     =			args[0]
                a_						     =			args[1:]

         if images is None and text is None:
                raise ValueError('You need to specify either an `images` or `text` input to process.'	)

         if images is not None:
                a_						     =			self.image_processor(_UpperCAmelCase   ,	*_UpperCAmelCase   ,	**_UpperCAmelCase	)
         if text is not None:
                a_						     =			self.tokenizer(_UpperCAmelCase   ,	**_UpperCAmelCase	)

         if text is None:
                return inputs
         elif images is None:
                return encodings
         else:
                a_						     =			encodings['input_ids']
                return inputs







  def    _a       (			self   ,	*UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         return self.tokenizer.batch_decode(*_UpperCAmelCase   ,	**_UpperCAmelCase	)







  def    _a       (			self   ,	*UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         return self.tokenizer.decode(*_UpperCAmelCase   ,	**_UpperCAmelCase	)







  @contextmanager
  def    _a       (			self	):






         """simple docstring"""


         warnings.warn(
             '`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '
             'labels by using the argument `text` of the regular `__call__` method (either in the same call as '
             'your images inputs, or in a separate call.'	)
         a_						     =			True
         a_						     =			self.tokenizer
         yield
         a_						     =			self.image_processor
         a_						     =			False







  def    _a       (			self   ,	UpperCamelCase__   ,	UpperCamelCase__=False   ,	UpperCamelCase__=None	):






         """simple docstring"""


         if added_vocab is None:
                a_						     =			self.tokenizer.get_added_vocab()

         a_						     =			{}

         while tokens:
                a_						     =			re.search(R'<s_(.*?)>'   ,	_UpperCAmelCase   ,	re.IGNORECASE	)
                if start_token is None:
                       break
                a_						     =			start_token.group(1	)
                a_						     =			re.search(Rf'</s_{key}>'   ,	_UpperCAmelCase   ,	re.IGNORECASE	)
                a_						     =			start_token.group()
                if end_token is None:
                       a_						     =			tokens.replace(_UpperCAmelCase   ,	''	)
                else:
                       a_						     =			end_token.group()
                       a_						     =			re.escape(_UpperCAmelCase	)
                       a_						     =			re.escape(_UpperCAmelCase	)
                       a_						     =			re.search(f'{start_token_escaped}(.*?){end_token_escaped}'   ,	_UpperCAmelCase   ,	re.IGNORECASE	)
                       if content is not None:
                              a_						     =			content.group(1	).strip()
                              if r"<s_" in content and r"</s_" in content:  # non-leaf node
                                     a_						     =			self.tokenajson(_UpperCAmelCase   ,	is_inner_value=_UpperCAmelCase   ,	added_vocab=_UpperCAmelCase	)
                                     if value:
                                            if len(_UpperCAmelCase	) == 1:
                                                   a_						     =			value[0]
                                            a_						     =			value
                              else:  # leaf nodes
                                     a_						     =			[]
                                     for leaf in content.split(R'<sep/>'	):
                                            a_						     =			leaf.strip()
                                            if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                                                   a_						     =			leaf[1:-2]  # for categorical special tokens
                                            output[key].append(_UpperCAmelCase	)
                                     if len(output[key]	) == 1:
                                            a_						     =			output[key][0]

                       a_						     =			tokens[tokens.find(_UpperCAmelCase	) + len(_UpperCAmelCase	) :].strip()
                       if tokens[:6] == r"<sep/>":  # non-leaf nodes
                              return [output] + self.tokenajson(tokens[6:]   ,	is_inner_value=_UpperCAmelCase   ,	added_vocab=_UpperCAmelCase	)

         if len(_UpperCAmelCase	):
                return [output] if is_inner_value else output
         else:
                return [] if is_inner_value else {"text_sequence": tokens}







  @property
  def    _a       (			self	):






         """simple docstring"""


         warnings.warn(
             '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'   ,	_UpperCAmelCase   ,	)
         return self.image_processor_class







  @property
  def    _a       (			self	):






         """simple docstring"""


         warnings.warn(
             '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'   ,	_UpperCAmelCase   ,	)
         return self.image_processor








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






					A__     =					MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

					def     lowerCamelCase__	(self       :		List[str] ,   _UpperCAmelCase       :		List[str] ,   _UpperCAmelCase       :		Dict ,   _UpperCAmelCase       :		Tuple						)		->  Tuple:




							"""simple docstring"""


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

					def     lowerCamelCase__	(self       :		List[str] ,   _UpperCAmelCase       :		Union[str, Any] ,   _UpperCAmelCase       :		Tuple						)		->  List[Any]:




							"""simple docstring"""


							for example in examples:
									lowercase__	     =						video_classifier(_UpperCAmelCase						)

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

					@require_torch
					def     lowerCamelCase__	(self       :		str						)		->  List[Any]:




							"""simple docstring"""


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

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

							lowercase__	     =						video_classifier(
							    [
							        video_file_path,
							        video_file_path,
							    ] ,   top_k=2 ,   )
							self.assertEqual(
							    nested_simplify(_UpperCAmelCase ,   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     lowerCamelCase__	(self       :		Any						)		->  Union[str, Any]:




							"""simple docstring"""


							pass

