





from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import tensorflow as tf

				from transformers import (
				    TF_MODEL_FOR_PRETRAINING_MAPPING,
				    TFMobileBertForMaskedLM,
				    TFMobileBertForMultipleChoice,
				    TFMobileBertForNextSentencePrediction,
				    TFMobileBertForPreTraining,
				    TFMobileBertForQuestionAnswering,
				    TFMobileBertForSequenceClassification,
				    TFMobileBertForTokenClassification,
				    TFMobileBertModel,
				)

@require_tf
class 	A_       (a_     ,							a_     ,							unittest.TestCase			):
	UpperCAmelCase__					=			(
	    (
	        TFMobileBertModel,
	        TFMobileBertForMaskedLM,
	        TFMobileBertForNextSentencePrediction,
	        TFMobileBertForPreTraining,
	        TFMobileBertForQuestionAnswering,
	        TFMobileBertForSequenceClassification,
	        TFMobileBertForTokenClassification,
	        TFMobileBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	UpperCAmelCase__					=			(
	    {
	        '''feature-extraction''': TFMobileBertModel,
	        '''fill-mask''': TFMobileBertForMaskedLM,
	        '''question-answering''': TFMobileBertForQuestionAnswering,
	        '''text-classification''': TFMobileBertForSequenceClassification,
	        '''token-classification''': TFMobileBertForTokenClassification,
	        '''zero-shot''': TFMobileBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	UpperCAmelCase__					=			False
	UpperCAmelCase__					=			False
	def      _lowercase				(    self							,					_A							,					_A							,					_A=False		):






				'''simple docstring'''







				UpperCAmelCase   		=				super()._prepare_for_class(_A							,					_A							,					return_labels=_A		)

				if return_labels:
							if model_class in get_values(_A		):
										UpperCAmelCase   		=				tf.zeros(self.model_tester.batch_size							,					dtype=tf.intaa		)

				return inputs_dict

	class 	A_       (a_			):
		def __init__(    self							,					_A							,					_A=1_3							,					_A=7							,					_A=True							,					_A=True							,					_A=True							,					_A=True							,					_A=9_9							,					_A=3_2							,					_A=3_2							,					_A=2							,					_A=4							,					_A=3_7							,					_A="gelu"							,					_A=0.1							,					_A=0.1							,					_A=5_1_2							,					_A=1_6							,					_A=2							,					_A=0.02							,					_A=3							,					_A=4							,					_A=None							,					):






					'''simple docstring'''







					UpperCAmelCase   		=				parent
					UpperCAmelCase   		=				batch_size
					UpperCAmelCase   		=				seq_length
					UpperCAmelCase   		=				is_training
					UpperCAmelCase   		=				use_input_mask
					UpperCAmelCase   		=				use_token_type_ids
					UpperCAmelCase   		=				use_labels
					UpperCAmelCase   		=				vocab_size
					UpperCAmelCase   		=				hidden_size
					UpperCAmelCase   		=				num_hidden_layers
					UpperCAmelCase   		=				num_attention_heads
					UpperCAmelCase   		=				intermediate_size
					UpperCAmelCase   		=				hidden_act
					UpperCAmelCase   		=				hidden_dropout_prob
					UpperCAmelCase   		=				attention_probs_dropout_prob
					UpperCAmelCase   		=				max_position_embeddings
					UpperCAmelCase   		=				type_vocab_size
					UpperCAmelCase   		=				type_sequence_label_size
					UpperCAmelCase   		=				initializer_range
					UpperCAmelCase   		=				num_labels
					UpperCAmelCase   		=				num_choices
					UpperCAmelCase   		=				scope
					UpperCAmelCase   		=				embedding_size
		def      _lowercase				(    self		):






					'''simple docstring'''







					UpperCAmelCase   		=				ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size		)

					UpperCAmelCase   		=				None
					if self.use_input_mask:
								UpperCAmelCase   		=				random_attention_mask([self.batch_size, self.seq_length]		)

					UpperCAmelCase   		=				None
					if self.use_token_type_ids:
								UpperCAmelCase   		=				ids_tensor([self.batch_size, self.seq_length]							,					self.type_vocab_size		)

					UpperCAmelCase   		=				None
					UpperCAmelCase   		=				None
					UpperCAmelCase   		=				None
					if self.use_labels:
								UpperCAmelCase   		=				ids_tensor([self.batch_size]							,					self.type_sequence_label_size		)
								UpperCAmelCase   		=				ids_tensor([self.batch_size, self.seq_length]							,					self.num_labels		)
								UpperCAmelCase   		=				ids_tensor([self.batch_size]							,					self.num_choices		)

					UpperCAmelCase   		=				MobileBertConfig(
					    vocab_size=self.vocab_size							,					hidden_size=self.hidden_size							,					num_hidden_layers=self.num_hidden_layers							,					num_attention_heads=self.num_attention_heads							,					intermediate_size=self.intermediate_size							,					hidden_act=self.hidden_act							,					hidden_dropout_prob=self.hidden_dropout_prob							,					attention_probs_dropout_prob=self.attention_probs_dropout_prob							,					max_position_embeddings=self.max_position_embeddings							,					type_vocab_size=self.type_vocab_size							,					initializer_range=self.initializer_range							,					embedding_size=self.embedding_size							,					)

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				TFMobileBertModel(config=_A		)
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
					UpperCAmelCase   		=				model(_A		)

					UpperCAmelCase   		=				[input_ids, input_mask]
					UpperCAmelCase   		=				model(_A		)

					UpperCAmelCase   		=				model(_A		)

					self.parent.assertEqual(
					    result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size)		)
					self.parent.assertEqual(result.pooler_output.shape							,					(self.batch_size, self.hidden_size)		)
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				TFMobileBertForMaskedLM(config=_A		)
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
					UpperCAmelCase   		=				model(_A		)
					self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)		)
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				TFMobileBertForNextSentencePrediction(config=_A		)
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
					UpperCAmelCase   		=				model(_A		)
					self.parent.assertEqual(result.logits.shape							,					(self.batch_size, 2)		)
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				TFMobileBertForPreTraining(config=_A		)
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
					UpperCAmelCase   		=				model(_A		)
					self.parent.assertEqual(
					    result.prediction_logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)		)
					self.parent.assertEqual(result.seq_relationship_logits.shape							,					(self.batch_size, 2)		)
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				self.num_labels
					UpperCAmelCase   		=				TFMobileBertForSequenceClassification(config=_A		)
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
					UpperCAmelCase   		=				model(_A		)
					self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_labels)		)
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				self.num_choices
					UpperCAmelCase   		=				TFMobileBertForMultipleChoice(config=_A		)
					UpperCAmelCase   		=				tf.tile(tf.expand_dims(_A							,					1		)							,					(1, self.num_choices, 1)		)
					UpperCAmelCase   		=				tf.tile(tf.expand_dims(_A							,					1		)							,					(1, self.num_choices, 1)		)
					UpperCAmelCase   		=				tf.tile(tf.expand_dims(_A							,					1		)							,					(1, self.num_choices, 1)		)
					UpperCAmelCase   		=				{
					    '''input_ids''': multiple_choice_inputs_ids,
					    '''attention_mask''': multiple_choice_input_mask,
					    '''token_type_ids''': multiple_choice_token_type_ids,
					}
					UpperCAmelCase   		=				model(_A		)
					self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_choices)		)
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				self.num_labels
					UpperCAmelCase   		=				TFMobileBertForTokenClassification(config=_A		)
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
					UpperCAmelCase   		=				model(_A		)
					self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.num_labels)		)
		def      _lowercase				(    self							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A							,					_A		):






					'''simple docstring'''







					UpperCAmelCase   		=				TFMobileBertForQuestionAnswering(config=_A		)
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
					UpperCAmelCase   		=				model(_A		)
					self.parent.assertEqual(result.start_logits.shape							,					(self.batch_size, self.seq_length)		)
					self.parent.assertEqual(result.end_logits.shape							,					(self.batch_size, self.seq_length)		)







		def      _lowercase				(    self		):






					'''simple docstring'''







					UpperCAmelCase   		=				self.prepare_config_and_inputs()
					(
					    (
					    UpperCAmelCase
					)		,			(
					    UpperCAmelCase
					)		,			(
					    UpperCAmelCase
					)		,			(
					    UpperCAmelCase
					)		,			(
					    UpperCAmelCase
					)		,			(
					    UpperCAmelCase
					)		,			(
					    UpperCAmelCase
					)		,			
					)   		=				config_and_inputs
					UpperCAmelCase   		=				{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
					return config, inputs_dict
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				TFMobileBertModelTest.TFMobileBertModelTester(self		)
				UpperCAmelCase   		=				ConfigTester(self							,					config_class=_A							,					hidden_size=3_7		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				self.config_tester.run_common_tests()
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_model(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_masked_lm(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_multiple_choice(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_pretraining(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_question_answering(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_sequence_classification(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_token_classification(*_A		)







	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				for model_name in ["google/mobilebert-uncased"]:
							UpperCAmelCase   		=				TFMobileBertModel.from_pretrained(_A		)
							self.assertIsNotNone(_A		)

@require_tf
class 	A_       (unittest.TestCase			):
	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				TFMobileBertForPreTraining.from_pretrained('''google/mobilebert-uncased'''		)
				UpperCAmelCase   		=				tf.constant([[0, 1, 2, 3, 4, 5]]		)
				UpperCAmelCase   		=				model(_A		)[0]

				UpperCAmelCase   		=				[1, 6, 3_0_5_2_2]
				self.assertEqual(output.shape							,					_A		)

				UpperCAmelCase   		=				tf.constant(
				    [
				        [
				            [-4.5_91_95_47, -9.24_82_95, -9.64_52_56],
				            [-6.7_30_61_75, -6.44_02_84, -6.6_05_28_37],
				            [-7.2_74_35_06, -6.7_84_79_15, -6.02_46_73],
				        ]
				    ]		)
				tf.debugging.assert_near(output[:, :3, :3]							,					_A							,					atol=1E-4		)










from datetime import datetime

import requests





def 						__SCREAMING_SNAKE_CASE  (				UpperCamelCase__ )  ->				bytes:







			'''simple docstring'''

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


if __name__ == "__main__":
				__A				:    Union[str, Any]       =   input("Enter Video/IGTV url: ").strip()
				__A				:    Tuple       =   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}.')



