



import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
			import jax

			from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel



class 						lowerCamelCase   (    unittest.TestCase	):







					'''simple docstring'''







					def __init__(      self     ,						lowerCAmelCase     ,						lowerCAmelCase=13     ,						lowerCAmelCase=30     ,						lowerCAmelCase=2     ,						lowerCAmelCase=3     ,						lowerCAmelCase=True     ,						lowerCAmelCase=True     ,						lowerCAmelCase=32     ,						lowerCAmelCase=5     ,						lowerCAmelCase=4     ,						lowerCAmelCase=37     ,						lowerCAmelCase="gelu"     ,						lowerCAmelCase=0.1     ,						lowerCAmelCase=0.1     ,						lowerCAmelCase=10     ,						lowerCAmelCase=0.02     ,						):
							UpperCAmelCase_						       =					parent
							UpperCAmelCase_						       =					batch_size
							UpperCAmelCase_						       =					image_size
							UpperCAmelCase_						       =					patch_size
							UpperCAmelCase_						       =					num_channels
							UpperCAmelCase_						       =					is_training
							UpperCAmelCase_						       =					use_labels
							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_						       =					type_sequence_label_size
							UpperCAmelCase_						       =					initializer_range

							# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
							UpperCAmelCase_						       =					(image_size // patch_size) ** 2
							UpperCAmelCase_						       =					num_patches + 1



					def  A__		(      self  ):
							UpperCAmelCase_						       =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

							UpperCAmelCase_						       =					ViTConfig(
							    image_size=self.image_size     ,						patch_size=self.patch_size     ,						num_channels=self.num_channels     ,						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     ,						is_decoder=__lowerCamelCase     ,						initializer_range=self.initializer_range     ,						)

							return config, pixel_values



					def  A__		(      self     ,						lowerCAmelCase     ,						lowerCAmelCase  ):
							UpperCAmelCase_						       =					FlaxViTModel(config=__lowerCamelCase  )
							UpperCAmelCase_						       =					model(__lowerCamelCase  )
							# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
							UpperCAmelCase_						       =					(self.image_size, self.image_size)
							UpperCAmelCase_						       =					(self.patch_size, self.patch_size)
							UpperCAmelCase_						       =					(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
							self.parent.assertEqual(result.last_hidden_state.shape     ,						(self.batch_size, num_patches + 1, self.hidden_size)  )



					def  A__		(      self     ,						lowerCAmelCase     ,						lowerCAmelCase  ):
							UpperCAmelCase_						       =					self.type_sequence_label_size
							UpperCAmelCase_						       =					FlaxViTForImageClassification(config=__lowerCamelCase  )
							UpperCAmelCase_						       =					model(__lowerCamelCase  )
							self.parent.assertEqual(result.logits.shape     ,						(self.batch_size, self.type_sequence_label_size)  )

							# test greyscale images
							UpperCAmelCase_						       =					1
							UpperCAmelCase_						       =					FlaxViTForImageClassification(__lowerCamelCase  )

							UpperCAmelCase_						       =					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
							UpperCAmelCase_						       =					model(__lowerCamelCase  )



					def  A__		(      self  ):
							UpperCAmelCase_						       =					self.prepare_config_and_inputs()
							(
							    (
							    UpperCAmelCase_	
							)       ,    (
							    UpperCAmelCase_	
							)       ,    	
							)						       =					config_and_inputs
							UpperCAmelCase_						       =					{"pixel_values": pixel_values}
							return config, inputs_dict





@require_flax
class 						lowerCamelCase   (    __snake_case,  unittest.TestCase	):







					'''simple docstring'''







					lowerCAmelCase_					:     int					       =	(FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()



					def  A__		(      self  ):
							UpperCAmelCase_						       =					FlaxViTModelTester(self  )
							UpperCAmelCase_						       =					ConfigTester(self     ,						config_class=__lowerCamelCase     ,						has_text_modality=__lowerCamelCase     ,						hidden_size=37  )



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



					def  A__		(      self  ):
							UpperCAmelCase_						       =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__lowerCamelCase  )



					def  A__		(      self  ):
							UpperCAmelCase_						       =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase  )



					def  A__		(      self  ):
							UpperCAmelCase_       ,    UpperCAmelCase_						       =					self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									UpperCAmelCase_						       =					model_class(__lowerCamelCase  )
									UpperCAmelCase_						       =					inspect.signature(model.__call__  )
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									UpperCAmelCase_						       =					[*signature.parameters.keys()]

									UpperCAmelCase_						       =					["pixel_values"]
									self.assertListEqual(arg_names[:1]     ,						__lowerCamelCase  )



					def  A__		(      self  ):
							UpperCAmelCase_       ,    UpperCAmelCase_						       =					self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									with self.subTest(model_class.__name__  ):
											UpperCAmelCase_						       =					self._prepare_for_class(__lowerCamelCase     ,						__lowerCamelCase  )
											UpperCAmelCase_						       =					model_class(__lowerCamelCase  )

											@jax.jit
											def model_jitted(lowerCAmelCase     ,						**lowerCAmelCase  ):
													return model(pixel_values=__lowerCamelCase     ,						**__lowerCamelCase  )

											with self.subTest("JIT Enabled"  ):
													UpperCAmelCase_						       =					model_jitted(**__lowerCamelCase  ).to_tuple()

											with self.subTest("JIT Disabled"  ):
													with jax.disable_jit():
															UpperCAmelCase_						       =					model_jitted(**__lowerCamelCase  ).to_tuple()

											self.assertEqual(len(__lowerCamelCase  )     ,						len(__lowerCamelCase  )  )
											for jitted_output, output in zip(__lowerCamelCase     ,						__lowerCamelCase  ):
													self.assertEqual(jitted_output.shape     ,						output.shape  )



					@slow
					def  A__		(      self  ):
							for model_class_name in self.all_model_classes:
									UpperCAmelCase_						       =					model_class_name.from_pretrained("google/vit-base-patch16-224"  )
									UpperCAmelCase_						       =					model(np.ones((1, 3, 224, 224)  )  )
									self.assertIsNotNone(__lowerCamelCase  )




from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

__A			:					List[Any]						=			{'UserAgent': UserAgent().random}





def 	__a     (      A__			:  List[Any]       ):
    SCREAMING_SNAKE_CASE										=   script.contents[0]
    SCREAMING_SNAKE_CASE										=   json.loads(data[data.find("{\"config\""       ) : -1]       )
    return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]





class 			_SCREAMING_SNAKE_CASE :







   '''simple docstring'''




   def __init__(       self					:			List[str]     , __lowerCamelCase					:			Optional[Any]			):
       SCREAMING_SNAKE_CASE										=   f"https://www.instagram.com/{username}/"
       SCREAMING_SNAKE_CASE										=   self.get_json()





   def      _snake_case		(       self					:			Tuple			):
       SCREAMING_SNAKE_CASE										=   requests.get(self.url     , headers=__lowerCamelCase			).text
       SCREAMING_SNAKE_CASE										=   BeautifulSoup(__lowerCamelCase     , "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					:			Union[str, Any]			):
       return f"{self.__class__.__name__}('{self.username}')"





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





   @property
   def      _snake_case		(       self					:			Optional[int]			):
       return self.user_data["username"]





   @property
   def      _snake_case		(       self					:			List[Any]			):
       return self.user_data["full_name"]





   @property
   def      _snake_case		(       self					:			List[str]			):
       return self.user_data["biography"]





   @property
   def      _snake_case		(       self					:			Tuple			):
       return self.user_data["business_email"]





   @property
   def      _snake_case		(       self					:			Optional[Any]			):
       return self.user_data["external_url"]





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





   @property
   def      _snake_case		(       self					:			List[str]			):
       return self.user_data["edge_follow"]["count"]





   @property
   def      _snake_case		(       self					:			List[Any]			):
       return self.user_data["edge_owner_to_timeline_media"]["count"]





   @property
   def      _snake_case		(       self					:			Any			):
       return self.user_data["profile_pic_url_hd"]





   @property
   def      _snake_case		(       self					:			Optional[int]			):
       return self.user_data["is_verified"]





   @property
   def      _snake_case		(       self					:			Dict			):
       return self.user_data["is_private"]





def 	__a     (      A__			:  str = "github"       ):
    import os

    if os.environ.get("CI"       ):
        return  # test failing on GitHub Actions
    SCREAMING_SNAKE_CASE										=   InstagramUser(A__       )
    assert instagram_user.user_data
    assert isinstance(instagram_user.user_data			,  A__       )
    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 > 120000
    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()
    __A			:					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 = }')