
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					):
							lowercase_		:						Dict   							=  MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING







							def       UpperCAmelCase__					(						self  :  Dict      ,				snake_case__  :  Any      ,				snake_case__  :  Union[str, Any]      ,				snake_case__  :  Union[str, Any] ):
								"""simple docstring"""







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







							def       UpperCAmelCase__					(						self  :  List[str]      ,				snake_case__  :  Any      ,				snake_case__  :  int ):
								"""simple docstring"""







								for example in examples:
									__lowerCAmelCase         =							video_classifier(__a )

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







							@require_torch
							def       UpperCAmelCase__					(						self  :  int ):
								"""simple docstring"""







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

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

								__lowerCAmelCase         =							video_classifier(
								    [
								        video_file_path,
								        video_file_path,
								    ]      ,				top_k=2      ,				)
								self.assertEqual(
								    nested_simplify(__a      ,				decimals=4 )      ,				[
								        [{"score": 0.5_1_9_9, "label": "LABEL_0"}, {"score": 0.4_8_0_1, "label": "LABEL_1"}],
								        [{"score": 0.5_1_9_9, "label": "LABEL_0"}, {"score": 0.4_8_0_1, "label": "LABEL_1"}],
								    ]      ,				)







							@require_tf
							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								pass








import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
					import torch

					from transformers.generation import DisjunctiveConstraint

@require_torch
class       a		(   unittest.TestCase					):







							def       UpperCAmelCase__					(						self  :  Optional[int] ):
								"""simple docstring"""







								__lowerCAmelCase         =							[[1, 2, 4], [1, 2, 3, 4]]
								__lowerCAmelCase         =							DisjunctiveConstraint(snake_case__ )
								self.assertTrue(isinstance(dc.token_ids      ,				snake_case__ ) )

								with self.assertRaises(snake_case__ ):
									DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]] ) )

								with self.assertRaises(snake_case__ ):
									DisjunctiveConstraint([torch.LongTensor([1, 2, 4] ), torch.LongTensor([1, 2, 3, 4, 5] )] )







							def       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							[[1, 2], [1, 2, 3, 4]]

								with self.assertRaises(snake_case__ ):
									DisjunctiveConstraint(snake_case__ )  # fails here







							def       UpperCAmelCase__					(						self  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							[[1, 2, 3], [1, 2, 4]]

								__lowerCAmelCase         =							DisjunctiveConstraint(snake_case__ )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(1 )
								__lowerCAmelCase         =							stepped is True and completed is False and reset is False
								self.assertTrue(snake_case__ )
								self.assertTrue(not dc.completed )
								self.assertTrue(dc.current_seq == [1] )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(2 )
								__lowerCAmelCase         =							stepped is True and completed is False and reset is False
								self.assertTrue(snake_case__ )
								self.assertTrue(not dc.completed )
								self.assertTrue(dc.current_seq == [1, 2] )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(3 )
								__lowerCAmelCase         =							stepped is True and completed is True and reset is False
								self.assertTrue(snake_case__ )
								self.assertTrue(dc.completed )  # Completed!
								self.assertTrue(dc.current_seq == [1, 2, 3] )







							def       UpperCAmelCase__					(						self  :  Optional[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

								__lowerCAmelCase         =							DisjunctiveConstraint(snake_case__ )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(1 )
								self.assertTrue(not dc.completed )
								self.assertTrue(dc.current_seq == [1] )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(2 )
								self.assertTrue(not dc.completed )
								self.assertTrue(dc.current_seq == [1, 2] )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(4 )
								self.assertTrue(not dc.completed )
								self.assertTrue(dc.current_seq == [1, 2, 4] )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(5 )
								self.assertTrue(dc.completed )  # Completed!
								self.assertTrue(dc.current_seq == [1, 2, 4, 5] )

								dc.reset()

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(1 )
								self.assertTrue(not dc.completed )
								self.assertTrue(dc.remaining() == 3 )
								self.assertTrue(dc.current_seq == [1] )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(2 )
								self.assertTrue(not dc.completed )
								self.assertTrue(dc.remaining() == 2 )
								self.assertTrue(dc.current_seq == [1, 2] )

								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							dc.update(5 )
								self.assertTrue(dc.completed )  # Completed!
								self.assertTrue(dc.remaining() == 0 )
								self.assertTrue(dc.current_seq == [1, 2, 5] )






