





"""simple docstring"""


from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import RegNetConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

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


if is_tf_available():
		import tensorflow as tf

		from transformers import TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST, TFRegNetForImageClassification, TFRegNetModel


if is_vision_available():
		from PIL import Image

		from transformers import AutoImageProcessor






class 							lowercase__			:

			"""simple docstring"""







			def __init__(      self						,   _A						,   _A=3						,   _A=3_2						,   _A=3						,   _A=1_0						,   _A=[1_0, 2_0, 3_0, 4_0]						,   _A=[1, 1, 2, 1]						,   _A=True						,   _A=True						,   _A="relu"						,   _A=3						,   _A=None						,   ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			parent
									UpperCamelCase				:		Tuple				   =			batch_size
									UpperCamelCase				:		Any				   =			image_size
									UpperCamelCase				:		List[str]				   =			num_channels
									UpperCamelCase				:		str				   =			embeddings_size
									UpperCamelCase				:		Union[str, Any]				   =			hidden_sizes
									UpperCamelCase				:		str				   =			depths
									UpperCamelCase				:		Dict				   =			is_training
									UpperCamelCase				:		Any				   =			use_labels
									UpperCamelCase				:		Any				   =			hidden_act
									UpperCamelCase				:		Tuple				   =			num_labels
									UpperCamelCase				:		Any				   =			scope
									UpperCamelCase				:		Union[str, Any]				   =			len(_A    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[Any]				   =			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

									UpperCamelCase				:		Tuple				   =			None
									if self.use_labels:
															UpperCamelCase				:		int				   =			ids_tensor([self.batch_size]						,   self.num_labels    )

									UpperCamelCase				:		Tuple				   =			self.get_config()
									return config, pixel_values, labels







			def   _a      (      self    ):






									'''simple docstring'''







									return RegNetConfig(
									    num_channels=self.num_channels						,   embeddings_size=self.embeddings_size						,   hidden_sizes=self.hidden_sizes						,   depths=self.depths						,   hidden_act=self.hidden_act						,   num_labels=self.num_labels						,   )







			def   _a      (      self						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		Tuple				   =			TFRegNetModel(config=_A    )
									UpperCamelCase				:		Optional[Any]				   =			model(_A						,   training=_A    )
									# expected last hidden states: B, C, H // 32, W // 32
									self.parent.assertEqual(
									    result.last_hidden_state.shape						,   (self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)						,   )







			def   _a      (      self						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		Tuple				   =			self.num_labels
									UpperCamelCase				:		Any				   =			TFRegNetForImageClassification(_A    )
									UpperCamelCase				:		Any				   =			model(_A						,   labels=_A						,   training=_A    )
									self.parent.assertEqual(result.logits.shape						,   (self.batch_size, self.num_labels)    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			self.prepare_config_and_inputs()
									UpperCamelCase   ,						UpperCamelCase   ,						UpperCamelCase				:		List[str]				   =			config_and_inputs
									UpperCamelCase				:		int				   =			{"""pixel_values""": pixel_values}
									return config, inputs_dict






@require_tf
class 							lowercase__			(   __SCREAMING_SNAKE_CASE					,     __SCREAMING_SNAKE_CASE					,     unittest.TestCase	):

			"""simple docstring"""
			__lowerCAmelCase     :				int										=  (TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else ()
			__lowerCAmelCase     :				Tuple										=  (
			    {"""feature-extraction""": TFRegNetModel, """image-classification""": TFRegNetForImageClassification}
			    if is_tf_available()
			    else {}
			)

			__lowerCAmelCase     :				int										=  False
			__lowerCAmelCase     :				Optional[int]										=  False
			__lowerCAmelCase     :				List[Any]										=  False
			__lowerCAmelCase     :				Union[str, Any]										=  False
			__lowerCAmelCase     :				str										=  False







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Union[str, Any]				   =			TFRegNetModelTester(self    )
									UpperCamelCase				:		Union[str, Any]				   =			ConfigTester(self						,   config_class=_A						,   has_text_modality=_A    )







			def   _a      (      self    ):






									'''simple docstring'''







									return







			@unittest.skip(reason="""RegNet does not use inputs_embeds"""    )
			def   _a      (      self    ):






									'''simple docstring'''







									pass







			@unittest.skipIf(
			    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""    )    ) == 0						,   reason="""TF does not support backprop for grouped convolutions on CPU."""						,   )
			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									super().test_keras_fit()







			@unittest.skip(reason="""RegNet does not support input and output embeddings"""    )
			def   _a      (      self    ):






									'''simple docstring'''







									pass







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase   ,						UpperCamelCase				:		List[str]				   =			self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
															UpperCamelCase				:		List[str]				   =			model_class(_A    )
															UpperCamelCase				:		Any				   =			inspect.signature(model.call    )
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															UpperCamelCase				:		Optional[int]				   =			[*signature.parameters.keys()]

															UpperCamelCase				:		Any				   =			["""pixel_values"""]
															self.assertListEqual(arg_names[:1]						,   _A    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Union[str, Any]				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_A    )







			def   _a      (      self    ):






									'''simple docstring'''







									def check_hidden_states_output(_A						,   _A						,   _A    ):
															UpperCamelCase				:		int				   =			model_class(_A    )
															UpperCamelCase				:		Dict				   =			model(**self._prepare_for_class(_A						,   _A    )						,   training=_A    )

															UpperCamelCase				:		Optional[Any]				   =			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

															UpperCamelCase				:		Dict				   =			self.model_tester.num_stages
															self.assertEqual(len(_A    )						,   expected_num_stages + 1    )

															# RegNet's feature maps are of shape (batch_size, num_channels, height, width)
															self.assertListEqual(
															    list(hidden_states[0].shape[-2:]    )						,   [self.model_tester.image_size // 2, self.model_tester.image_size // 2]						,   )

									UpperCamelCase   ,						UpperCamelCase				:		List[Any]				   =			self.model_tester.prepare_config_and_inputs_for_common()
									UpperCamelCase				:		Dict				   =			["""basic""", """bottleneck"""]
									for model_class in self.all_model_classes:
															for layer_type in layers_type:
																					UpperCamelCase				:		Tuple				   =			layer_type
																					UpperCamelCase				:		Dict				   =			True
																					check_hidden_states_output(_A						,   _A						,   _A    )

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					UpperCamelCase				:		Optional[Any]				   =			True

																					check_hidden_states_output(_A						,   _A						,   _A    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase   ,						UpperCamelCase				:		Optional[Any]				   =			self.model_tester.prepare_config_and_inputs_for_common()

									def check_equivalence(_A						,   _A						,   _A						,   _A={}    ):
															UpperCamelCase				:		Tuple				   =			model(_A						,   return_dict=_A						,   **_A    )
															UpperCamelCase				:		int				   =			model(_A						,   return_dict=_A						,   **_A    ).to_tuple()

															def recursive_check(_A						,   _A    ):
																					if isinstance(_A						,   (List, Tuple)    ):
																											for tuple_iterable_value, dict_iterable_value in zip(_A						,   _A    ):
																																	recursive_check(_A						,   _A    )
																					elif tuple_object is None:
																											return
																					else:
																											self.assertTrue(
																											    all(tf.equal(_A						,   _A    )    )						,   msg=(
																											        """Tuple and dict output are not equal. Difference:"""
																											        f""" {tf.math.reduce_max(tf.abs(tuple_object - dict_object    )    )}"""
																											    )						,   )

																					recursive_check(_A						,   _A    )

									for model_class in self.all_model_classes:
															UpperCamelCase				:		Any				   =			model_class(_A    )

															UpperCamelCase				:		Union[str, Any]				   =			self._prepare_for_class(_A						,   _A    )
															UpperCamelCase				:		str				   =			self._prepare_for_class(_A						,   _A    )
															check_equivalence(_A						,   _A						,   _A    )

															UpperCamelCase				:		Union[str, Any]				   =			self._prepare_for_class(_A						,   _A						,   return_labels=_A    )
															UpperCamelCase				:		Any				   =			self._prepare_for_class(_A						,   _A						,   return_labels=_A    )
															check_equivalence(_A						,   _A						,   _A    )

															UpperCamelCase				:		Any				   =			self._prepare_for_class(_A						,   _A    )
															UpperCamelCase				:		str				   =			self._prepare_for_class(_A						,   _A    )
															check_equivalence(_A						,   _A						,   _A						,   {"""output_hidden_states""": True}    )

															UpperCamelCase				:		List[Any]				   =			self._prepare_for_class(_A						,   _A						,   return_labels=_A    )
															UpperCamelCase				:		Optional[Any]				   =			self._prepare_for_class(_A						,   _A						,   return_labels=_A    )
															check_equivalence(_A						,   _A						,   _A						,   {"""output_hidden_states""": True}    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Dict				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*_A    )







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									for model_name in TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCamelCase				:		int				   =			TFRegNetModel.from_pretrained(_A    )
															self.assertIsNotNone(_A    )


def      UpperCamelCase							():
						UpperCamelCase				:		Any				   =			Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""     )
						return image






@require_tf
@require_vision
class 							lowercase__			(   unittest.TestCase	):

			"""simple docstring"""







			@cached_property
			def   _a      (      self    ):






									'''simple docstring'''







									return (
									    AutoImageProcessor.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]    )
									    if is_vision_available()
									    else None
									)







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Any				   =			TFRegNetForImageClassification.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]    )

									UpperCamelCase				:		List[Any]				   =			self.default_image_processor
									UpperCamelCase				:		List[Any]				   =			prepare_img()
									UpperCamelCase				:		Any				   =			image_processor(images=_A						,   return_tensors="""tf"""    )

									# forward pass
									UpperCamelCase				:		Optional[int]				   =			model(**_A						,   training=_A    )

									# verify the logits
									UpperCamelCase				:		List[Any]				   =			tf.TensorShape((1, 1_0_0_0)    )
									self.assertEqual(outputs.logits.shape						,   _A    )

									UpperCamelCase				:		int				   =			tf.constant([-0.41_80, -1.50_51, -3.48_36]    )

									tf.debugging.assert_near(outputs.logits[0, :3]						,   _A						,   atol=1e-4    )








from datetime import datetime

import requests

def        __a			(   __lowerCAmelCase   )     ->     bytes:
					SCREAMING_SNAKE_CASE							:     int						=				'https://downloadgram.net/wp-json/wppress/video-downloader/video?url='
					SCREAMING_SNAKE_CASE							:     Any						=				requests.get(base_url + url   ).json()[0]['urls'][0]['src']
					return requests.get(__lowerCAmelCase   ).content


if __name__ == "__main__":
			_lowerCamelCase    :		List[Any]		      =    input("""Enter Video/IGTV url: """).strip()
			_lowerCamelCase    :		int		      =    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}.""")