


"""simple docstring"""







import warnings

from transformers import AutoTokenizer
from transformers.utils import is_torch_available
from transformers.utils.generic import ExplicitEnum

from ...processing_utils import ProcessorMixin


if is_torch_available():
		import torch




class 			UpperCamelCase_     (			_a):

	"""simple docstring"""





	snake_case__    :  List[Any]    =      "char"
	snake_case__    :  str    =      "bpe"
	snake_case__    :  Any    =      "wp"


a__    :							str            =					(DecodeType.CHARACTER, DecodeType.BPE, DecodeType.WORDPIECE)




class 			UpperCamelCase_     (			_a):

	"""simple docstring"""





	snake_case__    :  Optional[int]    =      ["image_processor", "char_tokenizer"]
	snake_case__    :  Union[str, Any]    =      "ViTImageProcessor"
	snake_case__    :  Union[str, Any]    =      "MgpstrTokenizer"




	def __init__(			self      :    Optional[Any]      ,      UpperCAmelCase__      :    List[str]=None      ,      UpperCAmelCase__      :    str=None      ,      **UpperCAmelCase__      :    List[Any]       )	->     str:
						__SCREAMING_SNAKE_CASE						       =    None
						if "feature_extractor" in kwargs:
											warnings.warn(
											    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
											    " instead."      ,      snake_case_      ,      )
											__SCREAMING_SNAKE_CASE						       =    kwargs.pop("feature_extractor"       )

						__SCREAMING_SNAKE_CASE						       =    image_processor if image_processor is not None else feature_extractor
						if image_processor is None:
											raise ValueError("You need to specify an `image_processor`."       )
						if tokenizer is None:
											raise ValueError("You need to specify a `tokenizer`."       )

						__SCREAMING_SNAKE_CASE						       =    tokenizer
						__SCREAMING_SNAKE_CASE						       =    AutoTokenizer.from_pretrained("gpt2"       )
						__SCREAMING_SNAKE_CASE						       =    AutoTokenizer.from_pretrained("bert-base-uncased"       )

						super().__init__(snake_case_      ,      snake_case_       )




	def __call__(			self      :    str      ,      UpperCAmelCase__      :    Dict=None      ,      UpperCAmelCase__      :    List[str]=None      ,      UpperCAmelCase__      :    Optional[int]=None      ,      **UpperCAmelCase__      :    str       )	->     Dict:
						if images is None and text is None:
											raise ValueError("You need to specify either an `images` or `text` input to process."       )

						if images is not None:
											__SCREAMING_SNAKE_CASE						       =    self.image_processor(snake_case_      ,      return_tensors=snake_case_      ,      **snake_case_       )
						if text is not None:
											__SCREAMING_SNAKE_CASE						       =    self.char_tokenizer(snake_case_      ,      return_tensors=snake_case_      ,      **snake_case_       )

						if text is None:
											return inputs
						elif images is None:
											return encodings
						else:
											__SCREAMING_SNAKE_CASE						       =    encodings["""input_ids"""]
											return inputs




	def   UpperCAmelCase_				(			self      :    Tuple      ,      UpperCAmelCase__      :    Tuple       )	->     Optional[int]:
						__SCREAMING_SNAKE_CASE						       =    sequences
						__SCREAMING_SNAKE_CASE						       =    char_preds.size(0       )

						__SCREAMING_SNAKE_CASE						       =    self._decode_helper(snake_case_      ,      "char"       )
						__SCREAMING_SNAKE_CASE						       =    self._decode_helper(snake_case_      ,      "bpe"       )
						__SCREAMING_SNAKE_CASE						       =    self._decode_helper(snake_case_      ,      "wp"       )

						__SCREAMING_SNAKE_CASE						       =    []
						__SCREAMING_SNAKE_CASE						       =    []
						for i in range(snake_case_       ):
											__SCREAMING_SNAKE_CASE						       =    [char_scores[i], bpe_scores[i], wp_scores[i]]
											__SCREAMING_SNAKE_CASE						       =    [char_strs[i], bpe_strs[i], wp_strs[i]]
											__SCREAMING_SNAKE_CASE						       =    scores.index(max(snake_case_       )       )
											final_strs.append(strs[max_score_index]       )
											final_scores.append(scores[max_score_index]       )

						__SCREAMING_SNAKE_CASE						       =    {}
						__SCREAMING_SNAKE_CASE						       =    final_strs
						__SCREAMING_SNAKE_CASE						       =    final_scores
						__SCREAMING_SNAKE_CASE						       =    char_strs
						__SCREAMING_SNAKE_CASE						       =    bpe_strs
						__SCREAMING_SNAKE_CASE						       =    wp_strs
						return out




	def   UpperCAmelCase_				(			self      :    Dict      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    Dict       )	->     Optional[Any]:
						if format == DecodeType.CHARACTER:
											__SCREAMING_SNAKE_CASE						       =    self.char_decode
											__SCREAMING_SNAKE_CASE						       =    1
											__SCREAMING_SNAKE_CASE						       =    """[s]"""
						elif format == DecodeType.BPE:
											__SCREAMING_SNAKE_CASE						       =    self.bpe_decode
											__SCREAMING_SNAKE_CASE						       =    2
											__SCREAMING_SNAKE_CASE						       =    """#"""
						elif format == DecodeType.WORDPIECE:
											__SCREAMING_SNAKE_CASE						       =    self.wp_decode
											__SCREAMING_SNAKE_CASE						       =    1_0_2
											__SCREAMING_SNAKE_CASE						       =    """[SEP]"""
						else:
											raise ValueError(F"""Format {format} is not supported."""       )

						__SCREAMING_SNAKE_CASE						       =    [], []
						__SCREAMING_SNAKE_CASE						       =    pred_logits.size(0       )
						__SCREAMING_SNAKE_CASE						       =    pred_logits.size(1       )
						__SCREAMING_SNAKE_CASE						       =    pred_logits.topk(1      ,      dim=-1      ,      largest=snake_case_      ,      sorted=snake_case_       )
						__SCREAMING_SNAKE_CASE						       =    preds_index.view(-1      ,      snake_case_       )[:, 1:]
						__SCREAMING_SNAKE_CASE						       =    decoder(snake_case_       )
						__SCREAMING_SNAKE_CASE						       =    torch.nn.functional.softmax(snake_case_      ,      dim=2       ).max(dim=2       )
						__SCREAMING_SNAKE_CASE						       =    preds_max_prob[:, 1:]

						for index in range(snake_case_       ):
											__SCREAMING_SNAKE_CASE						       =    preds_str[index].find(snake_case_       )
											__SCREAMING_SNAKE_CASE						       =    preds_str[index][:pred_eos]
											__SCREAMING_SNAKE_CASE						       =    preds_index[index].cpu().tolist()
											__SCREAMING_SNAKE_CASE						       =    pred_index.index(snake_case_       ) if eos_token in pred_index else -1
											__SCREAMING_SNAKE_CASE						       =    preds_max_prob[index][: pred_eos_index + 1]
											__SCREAMING_SNAKE_CASE						       =    pred_max_prob.cumprod(dim=0       )[-1] if pred_max_prob.nelement() != 0 else 0.0
											dec_strs.append(snake_case_       )
											conf_scores.append(snake_case_       )

						return dec_strs, conf_scores




	def   UpperCAmelCase_				(			self      :    str      ,      UpperCAmelCase__      :    Union[str, Any]       )	->     int:
						__SCREAMING_SNAKE_CASE						       =    [seq.replace(" "      ,      ""       ) for seq in self.char_tokenizer.batch_decode(snake_case_       )]
						return decode_strs




	def   UpperCAmelCase_				(			self      :    List[Any]      ,      UpperCAmelCase__      :    Optional[Any]       )	->     Optional[Any]:
						return self.bpe_tokenizer.batch_decode(snake_case_       )




	def   UpperCAmelCase_				(			self      :    Union[str, Any]      ,      UpperCAmelCase__      :    Optional[Any]       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    [seq.replace(" "      ,      ""       ) for seq in self.wp_tokenizer.batch_decode(snake_case_       )]
						return decode_strs




"""simple docstring"""







from datetime import datetime

import requests




def        UpperCAmelCase__	(lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    "https://downloadgram.net/wp-json/wppress/video-downloader/video?url="
					__SCREAMING_SNAKE_CASE						       =    requests.get(base_url + url       ).json()[0]["urls"][0]["src"]
					return requests.get(lowerCAmelCase_       ).content


if __name__ == "__main__":
		a__    :							str            =					input('''Enter Video/IGTV url: ''').strip()
		a__    :							List[Any]            =					F"{datetime.now():%Y-%m-%d_%H:%M:%S}.mp4"
		with open(file_name, '''wb''') as fp:
				fp.write(download_video(url))
		print(F"Done. Video saved to disk as {file_name}.")
