

"""simple docstring"""






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 	__UpperCamelCase    (    unittest.TestCase						):

  def __init__(		self    ,_A    ,_A=13    ,_A=30    ,_A=2    ,_A=3    ,_A=True    ,_A=True    ,_A=32    ,_A=5    ,_A=4    ,_A=37    ,_A="gelu"    ,_A=0.1    ,_A=0.1    ,_A=10    ,_A=0.0_2    ,):
      '''simple docstring'''

      _lowerCAmelCase       :   List[str]  =    parent
      _lowerCAmelCase       :   List[str]  =    batch_size
      _lowerCAmelCase       :   Optional[Any]  =    image_size
      _lowerCAmelCase       :   Union[str, Any]  =    patch_size
      _lowerCAmelCase       :   Union[str, Any]  =    num_channels
      _lowerCAmelCase       :   int  =    is_training
      _lowerCAmelCase       :   List[Any]  =    use_labels
      _lowerCAmelCase       :   Optional[Any]  =    hidden_size
      _lowerCAmelCase       :   Optional[int]  =    num_hidden_layers
      _lowerCAmelCase       :   Optional[int]  =    num_attention_heads
      _lowerCAmelCase       :   Any  =    intermediate_size
      _lowerCAmelCase       :   Optional[Any]  =    hidden_act
      _lowerCAmelCase       :   List[str]  =    hidden_dropout_prob
      _lowerCAmelCase       :   Dict  =    attention_probs_dropout_prob
      _lowerCAmelCase       :   str  =    type_sequence_label_size
      _lowerCAmelCase       :   List[str]  =    initializer_range

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

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Optional[int]  =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

      _lowerCAmelCase       :   List[Any]  =    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=_A    ,initializer_range=self.initializer_range    ,)

      return config, pixel_values

  def __lowerCamelCase		(		self    ,_A    ,_A      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Tuple  =    FlaxViTModel(config=_A      )
      _lowerCAmelCase       :   str  =    model(_A      )
      # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
      _lowerCAmelCase       :   str  =    (self.image_size, self.image_size)
      _lowerCAmelCase       :   Optional[Any]  =    (self.patch_size, self.patch_size)
      _lowerCAmelCase       :   Optional[Any]  =    (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 __lowerCamelCase		(		self    ,_A    ,_A      ):
      '''simple docstring'''

      _lowerCAmelCase       :   str  =    self.type_sequence_label_size
      _lowerCAmelCase       :   Optional[Any]  =    FlaxViTForImageClassification(config=_A      )
      _lowerCAmelCase       :   str  =    model(_A      )
      self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.type_sequence_label_size)      )

      # test greyscale images
      _lowerCAmelCase       :   str  =    1
      _lowerCAmelCase       :   Tuple  =    FlaxViTForImageClassification(_A      )

      _lowerCAmelCase       :   Union[str, Any]  =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
      _lowerCAmelCase       :   List[Any]  =    model(_A      )







  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Union[str, Any]  =    self.prepare_config_and_inputs()
      (
          (
          _lowerCAmelCase
      ),					(
          _lowerCAmelCase
      ),					
      )       :   Optional[Any]  =    config_and_inputs
      _lowerCAmelCase       :   Optional[Any]  =    {'pixel_values': pixel_values}
      return config, inputs_dict







@require_flax
class 	__UpperCamelCase    (    a__							,							unittest.TestCase						):
  _UpperCAmelCase          =		(FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Any  =    FlaxViTModelTester(self      )
      _lowerCAmelCase       :   Tuple  =    ConfigTester(self    ,config_class=_A    ,has_text_modality=_A    ,hidden_size=37      )

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      self.config_tester.run_common_tests()

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Tuple  =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*_A      )

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

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

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

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

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

          _lowerCAmelCase       :   Optional[int]  =    ['pixel_values']
          self.assertListEqual(arg_names[:1]    ,_A      )

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      _lowerCAmelCase,					_lowerCAmelCase       :   Optional[int]  =    self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
          with self.subTest(model_class.__name__      ):
              _lowerCAmelCase       :   List[str]  =    self._prepare_for_class(_A    ,_A      )
              _lowerCAmelCase       :   Optional[Any]  =    model_class(_A      )

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

              with self.subTest('JIT Enabled'      ):
                  _lowerCAmelCase       :   Any  =    model_jitted(**_A      ).to_tuple()

              with self.subTest('JIT Disabled'      ):
                  with jax.disable_jit():
                      _lowerCAmelCase       :   Dict  =    model_jitted(**_A      ).to_tuple()

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







  @slow
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      for model_class_name in self.all_model_classes:
          _lowerCAmelCase       :   Any  =    model_class_name.from_pretrained('google/vit-base-patch16-224'      )
          _lowerCAmelCase       :   Optional[int]  =    model(np.ones((1, 3, 224, 224)      )      )
          self.assertIsNotNone(_A      )








"""simple docstring"""






from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

_lowerCAmelCase						=		{"""UserAgent""": UserAgent().random}

def 		lowerCamelCase__		(					_lowerCamelCase   ):

    '''simple docstring'''



    _lowerCAmelCase       :   Any  =    script.contents[0]
    _lowerCAmelCase       :   Union[str, Any]  =    json.loads(data[data.find('{"config"'   ) : -1]   )
    return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]







class 	__UpperCamelCase    :

  def __init__(		self    ,_A      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Optional[Any]  =    F"""https://www.instagram.com/{username}/"""
      _lowerCAmelCase       :   str  =    self.get_json()

  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      _lowerCAmelCase       :   str  =    requests.get(self.url    ,headers=_A      ).text
      _lowerCAmelCase       :   Optional[Any]  =    BeautifulSoup(_A    ,'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      ):
      '''simple docstring'''

      return F"""{self.__class__.__name__}('{self.username}')"""

  def __str__(		self      ):
      '''simple docstring'''

      return F"""{self.fullname} ({self.username}) is {self.biography}"""

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["username"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["full_name"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["biography"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["business_email"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["external_url"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["edge_followed_by"]["count"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["edge_follow"]["count"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["edge_owner_to_timeline_media"]["count"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["profile_pic_url_hd"]

  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["is_verified"]







  @property
  def __lowerCamelCase		(		self      ):
      '''simple docstring'''

      return self.user_data["is_private"]





def 		lowerCamelCase__		(					_lowerCamelCase = "github"   ):

    '''simple docstring'''



    import os

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





