






'''simple docstring'''







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

__lowerCAmelCase        =							logging.get_logger(__name__)




@add_end_docstrings(__A       )
class   __SCREAMING_SNAKE_CASE       (__A       ):


  """simple docstring"""


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






         """simple docstring"""


         super().__init__(*UpperCamelCase__   ,	**UpperCamelCase__	)
         requires_backends(self   ,	'decord'	)
         self.check_model_type(UpperCamelCase__	)







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






         """simple docstring"""


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

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







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






         """simple docstring"""


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







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






         """simple docstring"""


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

         if video.startswith('http://'	) or video.startswith('https://'	):
                a_						     =			BytesIO(requests.get(UpperCamelCase__	).content	)

         a_						     =			VideoReader(UpperCamelCase__	)
         videoreader.seek(0	)

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

         a_						     =			videoreader.get_batch(UpperCamelCase__	).asnumpy()
         a_						     =			list(UpperCamelCase__	)

         a_						     =			self.image_processor(UpperCamelCase__   ,	return_tensors=self.framework	)
         return model_inputs







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         a_						     =			self.model(**UpperCamelCase__	)
         return model_outputs







  def    _a       (			self   ,	UpperCamelCase__   ,	UpperCamelCase__=5	):






         """simple docstring"""


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

         if self.framework == "pt":
                a_						     =			model_outputs.logits.softmax(-1	)[0]
                a_     ,	a_						     =			probs.topk(UpperCamelCase__	)
         else:
                raise ValueError(f'Unsupported framework: {self.framework}'	)

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












'''simple docstring'''







def       __UpperCamelCase					(      lowercase_       :  int = 1_000_000   ):
       """simple docstring"""




       a_						     =			set(range(3   ,       lowercase_   ,       2   )   )
       primes.add(2   )
       for p in range(3   ,       lowercase_   ,       2   ):
              if p not in primes:
                     continue
              primes.difference_update(set(range(p * p   ,       lowercase_   ,       lowercase_   )   )   )

       a_						     =			[float(lowercase_   ) for n in range(limit + 1   )]

       for p in primes:
              for n in range(lowercase_   ,       limit + 1   ,       lowercase_   ):
                     phi[n] *= 1 - 1 / p

       return int(sum(phi[2:]   )   )


if __name__ == "__main__":
  print(f"""{solution() = }""")




