



"""simple docstring"""







import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation, MobileNetVaModel
							from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import MobileNetVaImageProcessor
class 			__A			(      __a       ):







		'''simple docstring'''





		def    UpperCAmelCase       (      self		:    Optional[int]		)   ->						Any:






				"""simple docstring"""



				lowercase__  :       Any												=     self.config_class(**self.inputs_dict		)
				self.parent.assertTrue(hasattr(__UpperCamelCase     ,'''tf_padding'''		)		)
				self.parent.assertTrue(hasattr(__UpperCamelCase     ,'''depth_multiplier'''		)		)





class 			__A			:







		'''simple docstring'''





		def __init__(      self		:    Union[str, Any]     ,_snake_case		:    Union[str, Any]     ,_snake_case		:    str=13     ,_snake_case		:    int=3     ,_snake_case		:    List[str]=32     ,_snake_case		:    List[str]=0.25     ,_snake_case		:    int=8     ,_snake_case		:    Optional[Any]=8     ,_snake_case		:    Optional[Any]=6     ,_snake_case		:    Optional[int]=32     ,_snake_case		:    str=True     ,_snake_case		:    Optional[Any]=True     ,_snake_case		:    Union[str, Any]=True     ,_snake_case		:    Any="relu6"     ,_snake_case		:    int=1_280     ,_snake_case		:    Tuple=0.1     ,_snake_case		:    Tuple=0.02     ,_snake_case		:    Optional[int]=True     ,_snake_case		:    List[Any]=True     ,_snake_case		:    List[Any]=10     ,_snake_case		:    Any=None     ,)   ->						Optional[int]:






				"""simple docstring"""



				lowercase__  :       Union[str, Any]												=     parent
				lowercase__  :       List[str]												=     batch_size
				lowercase__  :       int												=     num_channels
				lowercase__  :       Any												=     image_size
				lowercase__  :       Any												=     depth_multiplier
				lowercase__  :       str												=     depth_divisible_by
				lowercase__  :       List[str]												=     min_depth
				lowercase__  :       List[str]												=     expand_ratio
				lowercase__  :       Optional[int]												=     tf_padding
				lowercase__  :       int												=     output_stride
				lowercase__  :       Union[str, Any]												=     first_layer_is_expansion
				lowercase__  :       Any												=     finegrained_output
				lowercase__  :       Tuple												=     hidden_act
				lowercase__  :       Dict												=     last_hidden_size if finegrained_output else int(last_hidden_size * depth_multiplier		)
				lowercase__  :       Tuple												=     classifier_dropout_prob
				lowercase__  :       Union[str, Any]												=     use_labels
				lowercase__  :       Union[str, Any]												=     is_training
				lowercase__  :       int												=     num_labels
				lowercase__  :       Tuple												=     initializer_range
				lowercase__  :       List[Any]												=     scope







		def    UpperCAmelCase       (      self		:    List[Any]		)   ->						Union[str, Any]:






				"""simple docstring"""



				lowercase__  :       Optional[Any]												=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

				lowercase__  :       Optional[Any]												=     None
				lowercase__  :       Optional[Any]												=     None
				if self.use_labels:
						lowercase__  :       List[Any]												=     ids_tensor([self.batch_size]     ,self.num_labels		)
						lowercase__  :       str												=     ids_tensor([self.batch_size, self.image_size, self.image_size]     ,self.num_labels		)

				lowercase__  :       Any												=     self.get_config()

				return config, pixel_values, labels, pixel_labels







		def    UpperCAmelCase       (      self		:    Tuple		)   ->						List[str]:






				"""simple docstring"""



				return MobileNetVaConfig(
				    num_channels=self.num_channels     ,image_size=self.image_size     ,depth_multiplier=self.depth_multiplier     ,depth_divisible_by=self.depth_divisible_by     ,min_depth=self.min_depth     ,expand_ratio=self.expand_ratio     ,output_stride=self.output_stride     ,first_layer_is_expansion=self.first_layer_is_expansion     ,finegrained_output=self.finegrained_output     ,hidden_act=self.hidden_act     ,tf_padding=self.tf_padding     ,classifier_dropout_prob=self.classifier_dropout_prob     ,initializer_range=self.initializer_range     ,)







		def    UpperCAmelCase       (      self		:    Tuple     ,_snake_case		:    List[Any]     ,_snake_case		:    List[str]     ,_snake_case		:    Union[str, Any]     ,_snake_case		:    Dict		)   ->						List[Any]:






				"""simple docstring"""



				lowercase__  :       Optional[Any]												=     MobileNetVaModel(config=__UpperCamelCase		)
				model.to(__UpperCamelCase		)
				model.eval()
				lowercase__  :       Union[str, Any]												=     model(__UpperCamelCase		)
				self.parent.assertEqual(
				    result.last_hidden_state.shape     ,(
				        self.batch_size,
				        self.last_hidden_size,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )     ,)
				self.parent.assertEqual(
				    result.pooler_output.shape     ,(self.batch_size, self.last_hidden_size)     ,)







		def    UpperCAmelCase       (      self		:    List[Any]     ,_snake_case		:    Optional[Any]     ,_snake_case		:    int     ,_snake_case		:    int     ,_snake_case		:    Optional[int]		)   ->						Union[str, Any]:






				"""simple docstring"""



				lowercase__  :       Tuple												=     self.num_labels
				lowercase__  :       Tuple												=     MobileNetVaForImageClassification(__UpperCamelCase		)
				model.to(__UpperCamelCase		)
				model.eval()
				lowercase__  :       Dict												=     model(__UpperCamelCase     ,labels=__UpperCamelCase		)
				self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.num_labels)		)







		def    UpperCAmelCase       (      self		:    Optional[int]     ,_snake_case		:    Optional[int]     ,_snake_case		:    Tuple     ,_snake_case		:    str     ,_snake_case		:    List[str]		)   ->						int:






				"""simple docstring"""



				lowercase__  :       Dict												=     self.num_labels
				lowercase__  :       List[Any]												=     MobileNetVaForSemanticSegmentation(__UpperCamelCase		)
				model.to(__UpperCamelCase		)
				model.eval()
				lowercase__  :       Dict												=     model(__UpperCamelCase		)
				self.parent.assertEqual(
				    result.logits.shape     ,(
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )     ,)
				lowercase__  :       List[str]												=     model(__UpperCamelCase     ,labels=__UpperCamelCase		)
				self.parent.assertEqual(
				    result.logits.shape     ,(
				        self.batch_size,
				        self.num_labels,
				        self.image_size // self.output_stride,
				        self.image_size // self.output_stride,
				    )     ,)







		def    UpperCAmelCase       (      self		:    Union[str, Any]		)   ->						Any:






				"""simple docstring"""



				lowercase__  :       List[Any]												=     self.prepare_config_and_inputs()
				lowercase__  :       Optional[Any]												=     config_and_inputs
				lowercase__  :       Tuple												=     {"""pixel_values""": pixel_values}
				return config, inputs_dict





@require_torch
class 			__A			(      __a	,__a	,unittest.TestCase       ):







		'''simple docstring'''





		lowerCAmelCase     :   Tuple        =							(
		    (MobileNetVaModel, MobileNetVaForImageClassification, MobileNetVaForSemanticSegmentation)
		    if is_torch_available()
		    else ()
		)
		lowerCAmelCase     :   Tuple        =							(
		    {
		        '''feature-extraction''': MobileNetVaModel,
		        '''image-classification''': MobileNetVaForImageClassification,
		        '''image-segmentation''': MobileNetVaForSemanticSegmentation,
		    }
		    if is_torch_available()
		    else {}
		)

		lowerCAmelCase     :   Union[str, Any]        =							False
		lowerCAmelCase     :   List[str]        =							False
		lowerCAmelCase     :   Dict        =							False
		lowerCAmelCase     :   List[str]        =							False







		def    UpperCAmelCase       (      self		:    int		)   ->						List[Any]:






				"""simple docstring"""



				lowercase__  :       List[Any]												=     MobileNetVaModelTester(self		)
				lowercase__  :       List[Any]												=     MobileNetVaConfigTester(self     ,config_class=__UpperCamelCase     ,has_text_modality=__UpperCamelCase		)







		def    UpperCAmelCase       (      self		:    Optional[int]		)   ->						Optional[Any]:






				"""simple docstring"""



				self.config_tester.run_common_tests()







		@unittest.skip(reason='''MobileNetV2 does not use inputs_embeds'''		)
		def    UpperCAmelCase       (      self		:    Tuple		)   ->						Any:






				"""simple docstring"""



				pass







		@unittest.skip(reason='''MobileNetV2 does not support input and output embeddings'''		)
		def    UpperCAmelCase       (      self		:    Optional[int]		)   ->						int:






				"""simple docstring"""



				pass







		@unittest.skip(reason='''MobileNetV2 does not output attentions'''		)
		def    UpperCAmelCase       (      self		:    Union[str, Any]		)   ->						Any:






				"""simple docstring"""



				pass







		def    UpperCAmelCase       (      self		:    str		)   ->						Tuple:






				"""simple docstring"""



				lowercase__  :       Tuple												=     self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
						lowercase__  :       str												=     model_class(__UpperCamelCase		)
						lowercase__  :       str												=     inspect.signature(model.forward		)
						# signature.parameters is an OrderedDict => so arg_names order is deterministic
						lowercase__  :       List[str]												=     [*signature.parameters.keys()]

						lowercase__  :       List[str]												=     ["""pixel_values"""]
						self.assertListEqual(arg_names[:1]     ,__UpperCamelCase		)







		def    UpperCAmelCase       (      self		:    Optional[Any]		)   ->						List[str]:






				"""simple docstring"""



				lowercase__  :       int												=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*__UpperCamelCase		)







		def    UpperCAmelCase       (      self		:    Dict		)   ->						Dict:






				"""simple docstring"""



				def check_hidden_states_output(_snake_case		:    List[Any]     ,_snake_case		:    Optional[int]     ,_snake_case		:    Tuple		):
						lowercase__  :       Dict												=     model_class(__UpperCamelCase		)
						model.to(__UpperCamelCase		)
						model.eval()

						with torch.no_grad():
								lowercase__  :       Optional[int]												=     model(**self._prepare_for_class(__UpperCamelCase     ,__UpperCamelCase		)		)

						lowercase__  :       Optional[int]												=     outputs.hidden_states

						lowercase__  :       Union[str, Any]												=     16
						self.assertEqual(len(__UpperCamelCase		)     ,__UpperCamelCase		)

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

				for model_class in self.all_model_classes:
						lowercase__  :       int												=     True
						check_hidden_states_output(__UpperCamelCase     ,__UpperCamelCase     ,__UpperCamelCase		)

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

						check_hidden_states_output(__UpperCamelCase     ,__UpperCamelCase     ,__UpperCamelCase		)







		def    UpperCAmelCase       (      self		:    Optional[Any]		)   ->						Optional[Any]:






				"""simple docstring"""



				lowercase__  :       Union[str, Any]												=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*__UpperCamelCase		)







		def    UpperCAmelCase       (      self		:    Any		)   ->						Any:






				"""simple docstring"""



				lowercase__  :       Dict												=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_semantic_segmentation(*__UpperCamelCase		)







		@slow
		def    UpperCAmelCase       (      self		:    Any		)   ->						str:






				"""simple docstring"""



				for model_name in MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						lowercase__  :       List[str]												=     MobileNetVaModel.from_pretrained(__UpperCamelCase		)
						self.assertIsNotNone(__UpperCamelCase		)





def 	__UpperCAmelCase (       )				-> List[Any]:
		lowercase__  :       Union[str, Any]												=     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
		return image





@require_torch
@require_vision
class 			__A			(      unittest.TestCase       ):







		'''simple docstring'''





		@cached_property
		def    UpperCAmelCase       (      self		:    int		)   ->						List[str]:






				"""simple docstring"""



				return (
				    MobileNetVaImageProcessor.from_pretrained('''google/mobilenet_v2_1.0_224'''		) if is_vision_available() else None
				)







		@slow
		def    UpperCAmelCase       (      self		:    int		)   ->						Optional[int]:






				"""simple docstring"""



				lowercase__  :       Union[str, Any]												=     MobileNetVaForImageClassification.from_pretrained('''google/mobilenet_v2_1.0_224'''		).to(__UpperCamelCase		)

				lowercase__  :       int												=     self.default_image_processor
				lowercase__  :       Optional[int]												=     prepare_img()
				lowercase__  :       str												=     image_processor(images=__UpperCamelCase     ,return_tensors='''pt'''		).to(__UpperCamelCase		)

				# forward pass
				with torch.no_grad():
						lowercase__  :       str												=     model(**__UpperCamelCase		)

				# verify the logits
				lowercase__  :       Union[str, Any]												=     torch.Size((1, 1_001)		)
				self.assertEqual(outputs.logits.shape     ,__UpperCamelCase		)

				lowercase__  :       Union[str, Any]												=     torch.tensor([0.2445, -1.1993, 0.1905]		).to(__UpperCamelCase		)

				self.assertTrue(torch.allclose(outputs.logits[0, :3]     ,__UpperCamelCase     ,atol=1e-4		)		)







		@slow
		def    UpperCAmelCase       (      self		:    Any		)   ->						Union[str, Any]:






				"""simple docstring"""



				lowercase__  :       Tuple												=     MobileNetVaForSemanticSegmentation.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''		)
				lowercase__  :       Union[str, Any]												=     model.to(__UpperCamelCase		)

				lowercase__  :       Any												=     MobileNetVaImageProcessor.from_pretrained('''google/deeplabv3_mobilenet_v2_1.0_513'''		)

				lowercase__  :       str												=     prepare_img()
				lowercase__  :       Union[str, Any]												=     image_processor(images=__UpperCamelCase     ,return_tensors='''pt'''		).to(__UpperCamelCase		)

				# forward pass
				with torch.no_grad():
						lowercase__  :       List[str]												=     model(**__UpperCamelCase		)
				lowercase__  :       Tuple												=     outputs.logits

				# verify the logits
				lowercase__  :       Any												=     torch.Size((1, 21, 65, 65)		)
				self.assertEqual(logits.shape     ,__UpperCamelCase		)

				lowercase__  :       Union[str, Any]												=     torch.tensor(
				    [
				        [[17.5790, 17.7581, 18.3355], [18.3257, 18.4230, 18.8973], [18.6169, 18.8650, 19.2187]],
				        [[-2.1595, -2.0977, -2.3741], [-2.4226, -2.3028, -2.6835], [-2.7819, -2.5991, -2.7706]],
				        [[4.2058, 4.8317, 4.7638], [4.4136, 5.0361, 4.9383], [4.5028, 4.9644, 4.8734]],
				    ]     ,device=__UpperCamelCase     ,)

				self.assertTrue(torch.allclose(logits[0, :3, :3, :3]     ,__UpperCamelCase     ,atol=1e-4		)		)

from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

SCREAMING_SNAKE_CASE		:     Union[str, Any]         =	{"UserAgent": UserAgent().random}






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				Dict			):
						UpperCamelCase_		:							Tuple  =		script.contents[0]
						UpperCamelCase_		:							List[Any]  =		json.loads(data[data.find("""{\"config\""""			) : -1]			)
						return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]

class        UpperCamelCase						:





						def __init__(self			,     __UpperCamelCase						)				->				List[str]:
												UpperCamelCase_		:							Union[str, Any]  =		f'''https://www.instagram.com/{username}/'''
												UpperCamelCase_		:							Optional[int]  =		self.get_json()





						def        A_							(self						)				->				dict:
												UpperCamelCase_		:							Optional[Any]  =		requests.get(self.url			,     headers=__UpperCamelCase						).text
												UpperCamelCase_		:							Any  =		BeautifulSoup(__UpperCamelCase			,     """html.parser"""						).find_all("""script"""						)
												try:
																		return extract_user_profile(scripts[4]						)
												except (json.decoder.JSONDecodeError, KeyError):
																		return extract_user_profile(scripts[3]						)





						def __repr__(self						)				->				str:
												return f'''{self.__class__.__name__}(\'{self.username}\')'''





						def __str__(self						)				->				str:
												return f'''{self.fullname} ({self.username}) is {self.biography}'''





						@property
						def        A_							(self						)				->				str:
												return self.user_data["username"]





						@property
						def        A_							(self						)				->				str:
												return self.user_data["full_name"]





						@property
						def        A_							(self						)				->				str:
												return self.user_data["biography"]





						@property
						def        A_							(self						)				->				str:
												return self.user_data["business_email"]





						@property
						def        A_							(self						)				->				str:
												return self.user_data["external_url"]





						@property
						def        A_							(self						)				->				int:
												return self.user_data["edge_followed_by"]["count"]





						@property
						def        A_							(self						)				->				int:
												return self.user_data["edge_follow"]["count"]





						@property
						def        A_							(self						)				->				int:
												return self.user_data["edge_owner_to_timeline_media"]["count"]





						@property
						def        A_							(self						)				->				str:
												return self.user_data["profile_pic_url_hd"]





						@property
						def        A_							(self						)				->				bool:
												return self.user_data["is_verified"]





						@property
						def        A_							(self						)				->				bool:
												return self.user_data["is_private"]






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				str = "github"			):
						import os

						if os.environ.get("""CI"""			):
												return  # test failing on GitHub Actions
						UpperCamelCase_		:							Any  =		InstagramUser(_SCREAMING_SNAKE_CASE			)
						assert instagram_user.user_data
						assert isinstance(instagram_user.user_data		, _SCREAMING_SNAKE_CASE			)
						assert instagram_user.username == username
						if username != "github":
												return
						assert instagram_user.fullname == "GitHub"
						assert instagram_user.biography == "Built for developers."
						assert instagram_user.number_of_posts > 150
						assert instagram_user.number_of_followers > 12_0000
						assert instagram_user.number_of_followings > 15
						assert instagram_user.email == "support@github.com"
						assert instagram_user.website == "https://github.com/readme"
						assert instagram_user.profile_picture_url.startswith("""https://instagram."""			)
						assert instagram_user.is_verified is True
						assert instagram_user.is_private is False


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	SCREAMING_SNAKE_CASE		:     Dict         =	InstagramUser("github")
	print(instagram_user)
	print(F'''{instagram_user.number_of_posts = }''')
	print(F'''{instagram_user.number_of_followers = }''')
	print(F'''{instagram_user.number_of_followings = }''')
	print(F'''{instagram_user.email = }''')
	print(F'''{instagram_user.website = }''')
	print(F'''{instagram_user.profile_picture_url = }''')
	print(F'''{instagram_user.is_verified = }''')
	print(F'''{instagram_user.is_private = }''')






