
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(__a   )
class        A_   (			__a   ):




	'''simple docstring'''


	def __init__(       self		,    *snake_case		,    **snake_case       ):
		super().__init__(*a_		,    **a_       )
		requires_backends(self		,    'decord'       )
		self.check_model_type(a_       )





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case=None		,    snake_case=None		,    snake_case=None       ):
		lowercase       =    {}
		if frame_sampling_rate is not None:
			lowercase       =    frame_sampling_rate
		if num_frames is not None:
			lowercase       =    num_frames

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





	def __call__(       self		,    snake_case		,    **snake_case       ):
		return super().__call__(a_		,    **a_       )





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case=None		,    snake_case=1       ):



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

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

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

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

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

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





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case       ):
		lowercase       =    self.model(**a_       )
		return model_outputs





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case=5       ):



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

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

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







"""simple docstring"""


from __future__ import annotations


def 					UpperCAmelCase__       (snake_case__							:					list[int]		,   snake_case__							:					int    ):
  """simple docstring"""

  if len(snake_case__    ) < k or k < 0:
    raise ValueError("""Invalid Input"""    )
  _snake_case							:		Optional[int]								=  sum(array[:k]    )
  for i in range(len(snake_case__    ) - k    ):
    _snake_case							:		Optional[Any]								=  current_sum - array[i] + array[i + k]
    _snake_case							:		List[str]								=  max(snake_case__		,   snake_case__    )
  return max_sum


if __name__ == "__main__":
     from doctest import testmod
     from random import randint

     testmod()
     A_						=				[randint(-10_00, 10_00) for i in range(1_00)]
     A_						=				randint(0, 1_10)
     print(F'''The maximum sum of {k} consecutive elements is {max_sum_in_array(array,k)}''')


