




from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType





class     lowerCamelCase__(					__lowerCamelCase):
      UpperCAmelCase__      :	List[Any]    		=   ['image_processor', 'tokenizer']
      UpperCAmelCase__      :	int    		=   'BlipImageProcessor'
      UpperCAmelCase__      :	Tuple    		=   ('BertTokenizer', 'BertTokenizerFast')
      def __init__(				self: Optional[Any]    ,       UpperCamelCase_: List[str]    ,       UpperCamelCase_: List[Any]   ):
             __lowerCamelCase   =						False
             super().__init__(UpperCamelCase_    ,       UpperCamelCase_   )
             __lowerCamelCase   =						self.image_processor
      def __call__(				self: str    ,       UpperCamelCase_: ImageInput = None    ,       UpperCamelCase_: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None    ,       UpperCamelCase_: bool = True    ,       UpperCamelCase_: Union[bool, str, PaddingStrategy] = False    ,       UpperCamelCase_: Union[bool, str, TruncationStrategy] = None    ,       UpperCamelCase_: Optional[int] = None    ,       UpperCamelCase_: int = 0    ,       UpperCamelCase_: Optional[int] = None    ,       UpperCamelCase_: Optional[bool] = None    ,       UpperCamelCase_: bool = False    ,       UpperCamelCase_: bool = False    ,       UpperCamelCase_: bool = False    ,       UpperCamelCase_: bool = False    ,       UpperCamelCase_: bool = False    ,       UpperCamelCase_: bool = True    ,       UpperCamelCase_: Optional[Union[str, TensorType]] = None    ,       **UpperCamelCase_: List[str]    ,       ):
             if images is None and text is None:
                    raise ValueError("""You have to specify either images or text."""   )

             # Get only text
             if images is None:
                    __lowerCamelCase   =						self.tokenizer
                    __lowerCamelCase   =						self.tokenizer(
                        text=UpperCamelCase_    ,       add_special_tokens=UpperCamelCase_    ,       padding=UpperCamelCase_    ,       truncation=UpperCamelCase_    ,       max_length=UpperCamelCase_    ,       stride=UpperCamelCase_    ,       pad_to_multiple_of=UpperCamelCase_    ,       return_attention_mask=UpperCamelCase_    ,       return_overflowing_tokens=UpperCamelCase_    ,       return_special_tokens_mask=UpperCamelCase_    ,       return_offsets_mapping=UpperCamelCase_    ,       return_token_type_ids=UpperCamelCase_    ,       return_length=UpperCamelCase_    ,       verbose=UpperCamelCase_    ,       return_tensors=UpperCamelCase_    ,       **UpperCamelCase_    ,       )
                    return text_encoding

             # add pixel_values
             __lowerCamelCase   =						self.image_processor(UpperCamelCase_    ,       return_tensors=UpperCamelCase_   )

             if text is not None:
                    __lowerCamelCase   =						self.tokenizer(
                        text=UpperCamelCase_    ,       add_special_tokens=UpperCamelCase_    ,       padding=UpperCamelCase_    ,       truncation=UpperCamelCase_    ,       max_length=UpperCamelCase_    ,       stride=UpperCamelCase_    ,       pad_to_multiple_of=UpperCamelCase_    ,       return_attention_mask=UpperCamelCase_    ,       return_overflowing_tokens=UpperCamelCase_    ,       return_special_tokens_mask=UpperCamelCase_    ,       return_offsets_mapping=UpperCamelCase_    ,       return_token_type_ids=UpperCamelCase_    ,       return_length=UpperCamelCase_    ,       verbose=UpperCamelCase_    ,       return_tensors=UpperCamelCase_    ,       **UpperCamelCase_    ,       )
             else:
                    __lowerCamelCase   =						None

             if text_encoding is not None:
                    encoding_image_processor.update(UpperCamelCase_   )

             return encoding_image_processor
      def 			lowerCAmelCase__						(				self: Optional[int]    ,       *UpperCamelCase_: Union[str, Any]    ,       **UpperCamelCase_: Tuple   ):
             return self.tokenizer.batch_decode(*UpperCamelCase_    ,       **UpperCamelCase_   )
      def 			lowerCAmelCase__						(				self: List[str]    ,       *UpperCamelCase_: List[str]    ,       **UpperCamelCase_: str   ):
             return self.tokenizer.decode(*UpperCamelCase_    ,       **UpperCamelCase_   )




      @property
      def 			lowerCAmelCase__						(				self: str   ):
             __lowerCamelCase   =						self.tokenizer.model_input_names
             __lowerCamelCase   =						self.image_processor.model_input_names
             return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names   )   )








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 					__lowerCAmelCase       (			unittest.TestCase     ):
			lowerCamelCase_     :     Any       			=      MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__    )     ->   Dict:


							'''simple docstring'''



							snake_case_						:    Any				=  hf_hub_download(
							    repo_id='''nateraw/video-demo'''					,							filename='''archery.mp4'''					,							repo_type='''dataset'''    )
							snake_case_						:    List[Any]				=  VideoClassificationPipeline(model=__magic_name__					,							image_processor=__magic_name__					,							top_k=2    )
							snake_case_						:    str				=  [
							    example_video_filepath,
							    '''https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4''',
							]
							return video_classifier, examples






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__    )     ->   Any:


							'''simple docstring'''



							for example in examples:
											snake_case_						:    Union[str, Any]				=  video_classifier(__magic_name__    )

											self.assertEqual(
											    __magic_name__					,							[
											        {'''score''': ANY(__magic_name__    ), '''label''': ANY(__magic_name__    )},
											        {'''score''': ANY(__magic_name__    ), '''label''': ANY(__magic_name__    )},
											    ]					,							)






			@require_torch
			def 			lowerCamelCase  (self    )     ->   str:


							'''simple docstring'''



							snake_case_						:    Any				=  '''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
							snake_case_						:    str				=  VideoMAEFeatureExtractor(
							    size={'''shortest_edge''': 10}					,							crop_size={'''height''': 10, '''width''': 10}    )
							snake_case_						:    int				=  pipeline(
							    '''video-classification'''					,							model=__magic_name__					,							feature_extractor=__magic_name__					,							frame_sampling_rate=4    )

							snake_case_						:    List[str]				=  hf_hub_download(repo_id='''nateraw/video-demo'''					,							filename='''archery.mp4'''					,							repo_type='''dataset'''    )
							snake_case_						:    Union[str, Any]				=  video_classifier(__magic_name__					,							top_k=2    )
							self.assertEqual(
							    nested_simplify(__magic_name__					,							decimals=4    )					,							[{'''score''': 0.5_199, '''label''': '''LABEL_0'''}, {'''score''': 0.4_801, '''label''': '''LABEL_1'''}]					,							)

							snake_case_						:    int				=  video_classifier(
							    [
							        video_file_path,
							        video_file_path,
							    ]					,							top_k=2					,							)
							self.assertEqual(
							    nested_simplify(__magic_name__					,							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    )     ->   Optional[int]:


							'''simple docstring'''



							pass
