




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      :  Union[str, Any]      						=						logging.get_logger(__name__)
@add_end_docstrings(_a		)
class        __snake_case  (_a		):



				def __init__(      self      :		str		,	*_UpperCAmelCase      :		Any		,	**_UpperCAmelCase      :		List[str]      )  ->    str:





								'''simple docstring'''




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



				def       SCREAMING_SNAKE_CASE       (      self      :		Union[str, Any]		,	_UpperCAmelCase      :		Any=None		,	_UpperCAmelCase      :		List[str]=None		,	_UpperCAmelCase      :		Union[str, Any]=None      )  ->    Tuple:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      {}
								if frame_sampling_rate is not None:
												_lowerCAmelCase    :    Union[str, Any]										=      frame_sampling_rate
								if num_frames is not None:
												_lowerCAmelCase    :    Union[str, Any]										=      num_frames

								_lowerCAmelCase    :    Dict										=      {}
								if top_k is not None:
												_lowerCAmelCase    :    List[str]										=      top_k
								return preprocess_params, {}, postprocess_params



				def __call__(      self      :		Tuple		,	_UpperCAmelCase      :		Union[str, List[str]]		,	**_UpperCAmelCase      :		Optional[Any]      )  ->    Tuple:





								'''simple docstring'''




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



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		List[str]=None		,	_UpperCAmelCase      :		Dict=1      )  ->    Any:





								'''simple docstring'''




								if num_frames is None:
												_lowerCAmelCase    :    Tuple										=      self.model.config.num_frames

								if video.startswith("""http://"""      ) or video.startswith("""https://"""      ):
												_lowerCAmelCase    :    str										=      BytesIO(requests.get(_UpperCAmelCase      ).content      )

								_lowerCAmelCase    :    Any										=      VideoReader(_UpperCAmelCase      )
								videoreader.seek(0      )

								_lowerCAmelCase    :    Tuple										=      0
								_lowerCAmelCase    :    Tuple										=      num_frames * frame_sampling_rate - 1
								_lowerCAmelCase    :    Any										=      np.linspace(_UpperCAmelCase		,	_UpperCAmelCase		,	num=_UpperCAmelCase		,	dtype=np.intaa      )

								_lowerCAmelCase    :    Union[str, Any]										=      videoreader.get_batch(_UpperCAmelCase      ).asnumpy()
								_lowerCAmelCase    :    Tuple										=      list(_UpperCAmelCase      )

								_lowerCAmelCase    :    List[str]										=      self.image_processor(_UpperCAmelCase		,	return_tensors=self.framework      )
								return model_inputs



				def       SCREAMING_SNAKE_CASE       (      self      :		List[str]		,	_UpperCAmelCase      :		Tuple      )  ->    Union[str, Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[str]										=      self.model(**_UpperCAmelCase      )
								return model_outputs



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		List[Any]=5      )  ->    int:





								'''simple docstring'''




								if top_k > self.model.config.num_labels:
												_lowerCAmelCase    :    Any										=      self.model.config.num_labels

								if self.framework == "pt":
												_lowerCAmelCase    :    int										=      model_outputs.logits.softmax(-1      )[0]
												_lowerCAmelCase					,    _lowerCAmelCase    :    Optional[Any]										=      probs.topk(_UpperCAmelCase      )
								else:
												raise ValueError(f"Unsupported framework: {self.framework}"      )

								_lowerCAmelCase    :    Union[str, Any]										=      scores.tolist()
								_lowerCAmelCase    :    Any										=      ids.tolist()
								return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(_UpperCAmelCase		,	_UpperCAmelCase      )]







def 							_UpperCAmelCase  (UpperCamelCase_ : str       ):
				'''simple docstring'''
				_lowerCAmelCase    :    List[str]										=      [int(UpperCamelCase_       ) for i in ip_va_address.split("""."""       ) if i.isdigit()]
				return len(UpperCamelCase_       ) == 4 and all(0 <= int(UpperCamelCase_       ) <= 254 for octet in octets       )


if __name__ == "__main__":
	_lowerCamelCase      :  List[str]      						=						input().strip()
	_lowerCamelCase      :  int      						=						"valid" if is_ip_va_address_valid(ip) else "invalid"
	print(F'''{ip} is a {valid_or_invalid} IP v4 address.''')

