
from io import BytesIO
from typing import List, Union

import requests

from ..utils import add_end_docstrings, is_decord_available, is_torch_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_decord_available():
					import numpy as np
					from decord import VideoReader


if is_torch_available():
					from ..models.auto.modeling_auto import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

UpperCamelCase_   	=	logging.get_logger(__name__)

@add_end_docstrings(__UpperCAmelCase					)
class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Optional[int]      ,				*snake_case__  :  List[Any]      ,				**snake_case__  :  int ):
								"""simple docstring"""







								super().__init__(*snake_case__      ,				**snake_case__ )
								requires_backends(self      ,				"decord" )
								self.check_model_type(snake_case__ )







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







								__lowerCAmelCase         =							{}
								if frame_sampling_rate is not None:
									__lowerCAmelCase         =							frame_sampling_rate
								if num_frames is not None:
									__lowerCAmelCase         =							num_frames

								__lowerCAmelCase         =							{}
								if top_k is not None:
									__lowerCAmelCase         =							top_k
								return preprocess_params, {}, postprocess_params







							def __call__(						self  :  Dict      ,				snake_case__  :  Union[str, List[str]]      ,				**snake_case__  :  Dict ):
								"""simple docstring"""







								return super().__call__(snake_case__      ,				**snake_case__ )







							def       UpperCAmelCase__					(						self  :  List[Any]      ,				snake_case__  :  Optional[Any]      ,				snake_case__  :  List[Any]=None      ,				snake_case__  :  Any=1 ):
								"""simple docstring"""







								if num_frames is None:
									__lowerCAmelCase         =							self.model.config.num_frames

								if video.startswith("http://" ) or video.startswith("https://" ):
									__lowerCAmelCase         =							BytesIO(requests.get(snake_case__ ).content )

								__lowerCAmelCase         =							VideoReader(snake_case__ )
								videoreader.seek(0 )

								__lowerCAmelCase         =							0
								__lowerCAmelCase         =							num_frames * frame_sampling_rate - 1
								__lowerCAmelCase         =							np.linspace(snake_case__      ,				snake_case__      ,				num=snake_case__      ,				dtype=np.intaa )

								__lowerCAmelCase         =							videoreader.get_batch(snake_case__ ).asnumpy()
								__lowerCAmelCase         =							list(snake_case__ )

								__lowerCAmelCase         =							self.image_processor(snake_case__      ,				return_tensors=self.framework )
								return model_inputs







							def       UpperCAmelCase__					(						self  :  Any      ,				snake_case__  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model(**snake_case__ )
								return model_outputs







							def       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  Tuple      ,				snake_case__  :  str=5 ):
								"""simple docstring"""







								if top_k > self.model.config.num_labels:
									__lowerCAmelCase         =							self.model.config.num_labels

								if self.framework == "pt":
									__lowerCAmelCase         =							model_outputs.logits.softmax(-1 )[0]
									__lowerCAmelCase   ,						__lowerCAmelCase         =							probs.topk(snake_case__ )
								else:
									raise ValueError(F"Unsupported framework: {self.framework}" )

								__lowerCAmelCase         =							scores.tolist()
								__lowerCAmelCase         =							ids.tolist()
								return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(snake_case__      ,				snake_case__ )]








from __future__ import annotations

UpperCamelCase_   	=	[True] * 1_0_0_0_0_0_1
UpperCamelCase_   	=	2
while i * i <= 1_0_0_0_0_0_0:
					if seive[i]:
										for j in range(i * i, 1_0_0_0_0_0_1, i):
															UpperCamelCase_   	=	False
					i += 1






def 		_UpperCAmelCase   (	UpperCamelCase:     int  ):






	"""simple docstring"""


	return seive[n]






def 		_UpperCAmelCase   (	UpperCamelCase:     int  ):






	"""simple docstring"""


	return any(digit in "02468" for digit in str(UpperCamelCase  )  )






def 		_UpperCAmelCase   (	UpperCamelCase:     int = 1_0_0_0_0_0_0  ):






	"""simple docstring"""


	__lowerCAmelCase         =							[2]  # result already includes the number 2.
	for num in range(3			,							limit + 1			,							2  ):
		if is_prime(UpperCamelCase  ) and not contains_an_even_digit(UpperCamelCase  ):
			__lowerCAmelCase         =							str(UpperCamelCase  )
			__lowerCAmelCase         =							[int(str_num[j:] + str_num[:j]  ) for j in range(len(UpperCamelCase  )  )]
			if all(is_prime(UpperCamelCase  ) for i in list_nums  ):
				result.append(UpperCamelCase  )
	return result






def 		_UpperCAmelCase   (	):






	"""simple docstring"""


	return len(find_circular_primes()  )


if __name__ == "__main__":
					print(f'''{len(find_circular_primes()) = }''')






