




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 						lowercase							(   unittest.TestCase		):
     _a							 =						MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

     def 					a__	(  self		,     _a		,     _a		,     _a				)						->							Any:
           _A							:     List[Any]			=						hf_hub_download(
               repo_id="""nateraw/video-demo"""		,     filename="""archery.mp4"""		,     repo_type="""dataset"""				)
           _A							:     Tuple			=						VideoClassificationPipeline(model=_a		,     image_processor=_a		,     top_k=2				)
           _A							:     Optional[Any]			=						[
               example_video_filepath,
               """https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4""",
           ]
           return video_classifier, examples

     def 					a__	(  self		,     _a		,     _a				)						->							Any:
           for example in examples:
                 _A							:     Optional[int]			=						video_classifier(_a				)

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

     @require_torch
     def 					a__	(  self				)						->							str:
           _A							:     Tuple			=						"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
           _A							:     Tuple			=						VideoMAEFeatureExtractor(
               size={"""shortest_edge""": 10}		,     crop_size={"""height""": 10, """width""": 10}				)
           _A							:     Any			=						pipeline(
               """video-classification"""		,     model=_a		,     feature_extractor=_a		,     frame_sampling_rate=4				)

           _A							:     Optional[int]			=						hf_hub_download(repo_id="""nateraw/video-demo"""		,     filename="""archery.mp4"""		,     repo_type="""dataset"""				)
           _A							:     Any			=						video_classifier(_a		,     top_k=2				)
           self.assertEqual(
               nested_simplify(_a		,     decimals=4				)		,     [{"""score""": 0.5199, """label""": """LABEL_0"""}, {"""score""": 0.4801, """label""": """LABEL_1"""}]		,     )

           _A							:     Optional[int]			=						video_classifier(
               [
                   video_file_path,
                   video_file_path,
               ]		,     top_k=2		,     )
           self.assertEqual(
               nested_simplify(_a		,     decimals=4				)		,     [
                   [{"""score""": 0.5199, """label""": """LABEL_0"""}, {"""score""": 0.4801, """label""": """LABEL_1"""}],
                   [{"""score""": 0.5199, """label""": """LABEL_0"""}, {"""score""": 0.4801, """label""": """LABEL_1"""}],
               ]		,     )



     @require_tf
     def 					a__	(  self				)						->							str:
           pass








'''simple docstring'''


lowerCAmelCase					:     str												='''
# Installazione di Transformers
! pip install transformers datasets
# Per installare dalla fonte invece dell\'ultima versione rilasciata, commenta il comando sopra e
# rimuovi la modalità commento al comando seguente.
# ! pip install git+https://github.com/huggingface/transformers.git
'''

lowerCAmelCase					:     int												=[{'''type''': '''code''', '''content''': INSTALL_CONTENT}]
lowerCAmelCase					:     List[str]												={
    '''{processor_class}''': '''FakeProcessorClass''',
    '''{model_class}''': '''FakeModelClass''',
    '''{object_class}''': '''FakeObjectClass''',
}


