

'''simple docstring'''
from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
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.models.distilbert.modeling_tf_distilbert import (
         TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
         TFDistilBertForMaskedLM,
         TFDistilBertForMultipleChoice,
         TFDistilBertForQuestionAnswering,
         TFDistilBertForSequenceClassification,
         TFDistilBertForTokenClassification,
         TFDistilBertModel,
     )







class 							A__   :





  def __init__(		self				:     Optional[int]							, _a				:     Any							, )     ->   Optional[int]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =parent
       _SCREAMING_SNAKE_CASE							   =13
       _SCREAMING_SNAKE_CASE							   =7
       _SCREAMING_SNAKE_CASE							   =True
       _SCREAMING_SNAKE_CASE							   =True
       _SCREAMING_SNAKE_CASE							   =False
       _SCREAMING_SNAKE_CASE							   =True
       _SCREAMING_SNAKE_CASE							   =99
       _SCREAMING_SNAKE_CASE							   =32
       _SCREAMING_SNAKE_CASE							   =2
       _SCREAMING_SNAKE_CASE							   =4
       _SCREAMING_SNAKE_CASE							   =37
       _SCREAMING_SNAKE_CASE							   ='gelu'
       _SCREAMING_SNAKE_CASE							   =0.1
       _SCREAMING_SNAKE_CASE							   =0.1
       _SCREAMING_SNAKE_CASE							   =512
       _SCREAMING_SNAKE_CASE							   =16
       _SCREAMING_SNAKE_CASE							   =2
       _SCREAMING_SNAKE_CASE							   =0.02
       _SCREAMING_SNAKE_CASE							   =3
       _SCREAMING_SNAKE_CASE							   =4
       _SCREAMING_SNAKE_CASE							   =None





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





       '''simple docstring'''






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

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

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

       _SCREAMING_SNAKE_CASE							   =DistilBertConfig(
           vocab_size=self.vocab_size							, dim=self.hidden_size							, n_layers=self.num_hidden_layers							, n_heads=self.num_attention_heads							, hidden_dim=self.intermediate_size							, hidden_act=self.hidden_act							, dropout=self.hidden_dropout_prob							, attention_dropout=self.attention_probs_dropout_prob							, max_position_embeddings=self.max_position_embeddings							, initializer_range=self.initializer_range							, )

       return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels





  def 						A  (		self				:     Any							, _a				:     int							, _a				:     str							, _a				:     List[str]							, _a				:     Union[str, Any]							, _a				:     List[str]							, _a				:     Tuple			)     ->   Optional[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =TFDistilBertModel(config=_a			)
       _SCREAMING_SNAKE_CASE							   ={'input_ids': input_ids, 'attention_mask': input_mask}

       _SCREAMING_SNAKE_CASE							   =model(_a			)

       _SCREAMING_SNAKE_CASE							   =[input_ids, input_mask]

       _SCREAMING_SNAKE_CASE							   =model(_a			)

       self.parent.assertEqual(result.last_hidden_state.shape							, (self.batch_size, self.seq_length, self.hidden_size)			)





  def 						A  (		self				:     Optional[Any]							, _a				:     int							, _a				:     List[Any]							, _a				:     Dict							, _a				:     Tuple							, _a				:     List[Any]							, _a				:     Tuple			)     ->   str:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =TFDistilBertForMaskedLM(config=_a			)
       _SCREAMING_SNAKE_CASE							   ={'input_ids': input_ids, 'attention_mask': input_mask}
       _SCREAMING_SNAKE_CASE							   =model(_a			)
       self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.seq_length, self.vocab_size)			)





  def 						A  (		self				:     Dict							, _a				:     List[str]							, _a				:     Optional[int]							, _a				:     List[str]							, _a				:     int							, _a				:     Tuple							, _a				:     str			)     ->   List[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =TFDistilBertForQuestionAnswering(config=_a			)
       _SCREAMING_SNAKE_CASE							   ={
           'input_ids': input_ids,
           'attention_mask': input_mask,
       }
       _SCREAMING_SNAKE_CASE							   =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 						A  (		self				:     Union[str, Any]							, _a				:     Optional[int]							, _a				:     Optional[int]							, _a				:     Optional[int]							, _a				:     List[str]							, _a				:     Optional[int]							, _a				:     List[Any]			)     ->   Union[str, Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.num_labels
       _SCREAMING_SNAKE_CASE							   =TFDistilBertForSequenceClassification(_a			)
       _SCREAMING_SNAKE_CASE							   ={'input_ids': input_ids, 'attention_mask': input_mask}
       _SCREAMING_SNAKE_CASE							   =model(_a			)
       self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.num_labels)			)





  def 						A  (		self				:     Optional[int]							, _a				:     List[str]							, _a				:     Dict							, _a				:     str							, _a				:     Dict							, _a				:     Any							, _a				:     int			)     ->   Optional[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.num_choices
       _SCREAMING_SNAKE_CASE							   =TFDistilBertForMultipleChoice(_a			)
       _SCREAMING_SNAKE_CASE							   =tf.tile(tf.expand_dims(_a							, 1			)							, (1, self.num_choices, 1)			)
       _SCREAMING_SNAKE_CASE							   =tf.tile(tf.expand_dims(_a							, 1			)							, (1, self.num_choices, 1)			)
       _SCREAMING_SNAKE_CASE							   ={
           'input_ids': multiple_choice_inputs_ids,
           'attention_mask': multiple_choice_input_mask,
       }
       _SCREAMING_SNAKE_CASE							   =model(_a			)
       self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.num_choices)			)





  def 						A  (		self				:     str							, _a				:     str							, _a				:     Tuple							, _a				:     Any							, _a				:     Union[str, Any]							, _a				:     str							, _a				:     Tuple			)     ->   Optional[int]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.num_labels
       _SCREAMING_SNAKE_CASE							   =TFDistilBertForTokenClassification(_a			)
       _SCREAMING_SNAKE_CASE							   ={'input_ids': input_ids, 'attention_mask': input_mask}
       _SCREAMING_SNAKE_CASE							   =model(_a			)
       self.parent.assertEqual(result.logits.shape							, (self.batch_size, self.seq_length, self.num_labels)			)





  def 						A  (		self				:     Dict			)     ->   Any:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.prepare_config_and_inputs()
       ((_SCREAMING_SNAKE_CASE)   ,						(_SCREAMING_SNAKE_CASE)   ,						(_SCREAMING_SNAKE_CASE)   ,						(_SCREAMING_SNAKE_CASE)   ,						(_SCREAMING_SNAKE_CASE)   ,						(_SCREAMING_SNAKE_CASE))							   =config_and_inputs
       _SCREAMING_SNAKE_CASE							   ={'input_ids': input_ids, 'attention_mask': input_mask}
       return config, inputs_dict







@require_tf
class 							A__   (	A__					,       A__					,       unittest.TestCase  ):
  A__					=    (
      (
          TFDistilBertModel,
          TFDistilBertForMaskedLM,
          TFDistilBertForQuestionAnswering,
          TFDistilBertForSequenceClassification,
          TFDistilBertForTokenClassification,
          TFDistilBertForMultipleChoice,
      )
      if is_tf_available()
      else None
  )
  A__					=    (
      {
          'feature-extraction': TFDistilBertModel,
          'fill-mask': TFDistilBertForMaskedLM,
          'question-answering': TFDistilBertForQuestionAnswering,
          'text-classification': TFDistilBertForSequenceClassification,
          'token-classification': TFDistilBertForTokenClassification,
          'zero-shot': TFDistilBertForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  A__					=    False
  A__					=    False





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





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =TFDistilBertModelTester(self			)
       _SCREAMING_SNAKE_CASE							   =ConfigTester(self							, config_class=_a							, dim=37			)





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





       '''simple docstring'''






       self.config_tester.run_common_tests()





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





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_model(*_a			)





  def 						A  (		self				:     int			)     ->   List[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_masked_lm(*_a			)





  def 						A  (		self				:     int			)     ->   List[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_question_answering(*_a			)





  def 						A  (		self				:     int			)     ->   List[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_sequence_classification(*_a			)





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





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_multiple_choice(*_a			)





  def 						A  (		self				:     Tuple			)     ->   Any:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_token_classification(*_a			)





  @slow
  def 						A  (		self				:     int			)     ->   str:





       '''simple docstring'''






       for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]			):
            _SCREAMING_SNAKE_CASE							   =TFDistilBertModel.from_pretrained(_a			)
            self.assertIsNotNone(_a			)







@require_tf
class 							A__   (	unittest.TestCase  ):





  @slow
  def 						A  (		self				:     List[Any]			)     ->   Dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =TFDistilBertModel.from_pretrained('distilbert-base-uncased'			)
       _SCREAMING_SNAKE_CASE							   =tf.constant([[0, 1, 2, 3, 4, 5]]			)
       _SCREAMING_SNAKE_CASE							   =model(_a			)[0]

       _SCREAMING_SNAKE_CASE							   =[1, 6, 768]
       self.assertEqual(output.shape							, _a			)

       _SCREAMING_SNAKE_CASE							   =tf.constant(
           [
               [
                   [0.19_26_18_85, -0.13_73_29_55, 0.4_11_97_99],
                   [0.22_15_01_56, -0.07_42_26_61, 0.39_03_72_04],
                   [0.22_75_60_18, -0.0_89_64_14, 0.3_70_14_67],
               ]
           ]			)
       tf.debugging.assert_near(output[:, :3, :3]							, _a							, atol=1e-4			)



'''simple docstring'''
from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

lowerCamelCase			:				List[str] 			=					{"UserAgent": UserAgent().random}


def 	_lowerCAmelCase (						_UpperCamelCase						:					str    )				->      dict:
     """simple docstring"""




     _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 							A__   :





  def __init__(		self				:     int							, _a				:     List[Any]			)     ->   Optional[int]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =f"https://www.instagram.com/{username}/"
       _SCREAMING_SNAKE_CASE							   =self.get_json()





  def 						A  (		self				:     Optional[int]			)     ->   dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =requests.get(self.url							, headers=_a			).text
       _SCREAMING_SNAKE_CASE							   =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				:     str			)     ->   str:





       '''simple docstring'''






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





  def __str__(		self				:     Optional[int]			)     ->   str:





       '''simple docstring'''






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





  @property
  def 						A  (		self				:     List[Any]			)     ->   str:





       '''simple docstring'''






       return self.user_data["username"]





  @property
  def 						A  (		self				:     str			)     ->   str:





       '''simple docstring'''






       return self.user_data["full_name"]





  @property
  def 						A  (		self				:     Any			)     ->   str:





       '''simple docstring'''






       return self.user_data["biography"]





  @property
  def 						A  (		self				:     Optional[Any]			)     ->   str:





       '''simple docstring'''






       return self.user_data["business_email"]





  @property
  def 						A  (		self				:     Tuple			)     ->   str:





       '''simple docstring'''






       return self.user_data["external_url"]





  @property
  def 						A  (		self				:     Optional[int]			)     ->   int:





       '''simple docstring'''






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





  @property
  def 						A  (		self				:     Union[str, Any]			)     ->   int:





       '''simple docstring'''






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





  @property
  def 						A  (		self				:     List[str]			)     ->   int:





       '''simple docstring'''






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





  @property
  def 						A  (		self				:     Union[str, Any]			)     ->   str:





       '''simple docstring'''






       return self.user_data["profile_pic_url_hd"]





  @property
  def 						A  (		self				:     Dict			)     ->   bool:





       '''simple docstring'''






       return self.user_data["is_verified"]





  @property
  def 						A  (		self				:     Tuple			)     ->   bool:





       '''simple docstring'''






       return self.user_data["is_private"]


def 	_lowerCAmelCase (						_UpperCamelCase						:					str = "github"    )				->      None:
     """simple docstring"""




     import os

     if os.environ.get('CI'    ):
          return  # test failing on GitHub Actions
     _SCREAMING_SNAKE_CASE							   =InstagramUser(_UpperCamelCase    )
     assert instagram_user.user_data
     assert isinstance(instagram_user.user_data							,			_UpperCamelCase    )
     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 > 1_50
     assert instagram_user.number_of_followers > 12_00_00
     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			:				Optional[int] 			=					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 = }''')
