





"""simple docstring"""




from __future__ import annotations

import unittest

from transformers import OpenAIGPTConfig, 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.openai.modeling_tf_openai import (
						    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFOpenAIGPTDoubleHeadsModel,
						    TFOpenAIGPTForSequenceClassification,
						    TFOpenAIGPTLMHeadModel,
						    TFOpenAIGPTModel,
						)




class 					_a		:






				def __init__(					self						:       Tuple,					lowerCAmelCase__						:       List[str],					)      -> Dict:




										'''simple docstring'''



										_UpperCamelCase     :   Any      =       parent
										_UpperCamelCase     :   str      =       1_3
										_UpperCamelCase     :   Optional[int]      =       7
										_UpperCamelCase     :   Tuple      =       True
										_UpperCamelCase     :   Dict      =       True
										_UpperCamelCase     :   int      =       True
										_UpperCamelCase     :   Any      =       True
										_UpperCamelCase     :   Union[str, Any]      =       True
										_UpperCamelCase     :   Union[str, Any]      =       9_9
										_UpperCamelCase     :   str      =       3_2
										_UpperCamelCase     :   Any      =       2
										_UpperCamelCase     :   Dict      =       4
										_UpperCamelCase     :   Union[str, Any]      =       3_7
										_UpperCamelCase     :   Any      =       '''gelu'''
										_UpperCamelCase     :   List[str]      =       0.1
										_UpperCamelCase     :   Dict      =       0.1
										_UpperCamelCase     :   List[Any]      =       5_1_2
										_UpperCamelCase     :   Dict      =       1_6
										_UpperCamelCase     :   str      =       2
										_UpperCamelCase     :   Any      =       0.02
										_UpperCamelCase     :   List[Any]      =       3
										_UpperCamelCase     :   List[str]      =       4
										_UpperCamelCase     :   Union[str, Any]      =       None
										_UpperCamelCase     :   Any      =       self.vocab_size - 1






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




										'''simple docstring'''



										_UpperCamelCase     :   Any      =       ids_tensor([self.batch_size, self.seq_length],					self.vocab_size				)

										_UpperCamelCase     :   Any      =       None
										if self.use_input_mask:
																_UpperCamelCase     :   List[Any]      =       random_attention_mask([self.batch_size, self.seq_length]				)

										_UpperCamelCase     :   int      =       None
										if self.use_token_type_ids:
																_UpperCamelCase     :   Union[str, Any]      =       ids_tensor([self.batch_size, self.seq_length],					self.type_vocab_size				)

										_UpperCamelCase     :   Union[str, Any]      =       None
										if self.use_mc_token_ids:
																_UpperCamelCase     :   Optional[Any]      =       ids_tensor([self.batch_size, self.num_choices],					self.seq_length				)

										_UpperCamelCase     :   int      =       None
										_UpperCamelCase     :   Optional[Any]      =       None
										_UpperCamelCase     :   str      =       None
										if self.use_labels:
																_UpperCamelCase     :   str      =       ids_tensor([self.batch_size],					self.type_sequence_label_size				)
																_UpperCamelCase     :   Tuple      =       ids_tensor([self.batch_size, self.seq_length],					self.num_labels				)
																_UpperCamelCase     :   str      =       ids_tensor([self.batch_size],					self.num_choices				)

										_UpperCamelCase     :   List[str]      =       OpenAIGPTConfig(
										    vocab_size=self.vocab_size,					n_embd=self.hidden_size,					n_layer=self.num_hidden_layers,					n_head=self.num_attention_heads,					n_positions=self.max_position_embeddings,					pad_token_id=self.pad_token_id,					)

										_UpperCamelCase     :   int      =       ids_tensor([self.num_hidden_layers, self.num_attention_heads],					2				)

										return (
										    config,
										    input_ids,
										    input_mask,
										    head_mask,
										    token_type_ids,
										    mc_token_ids,
										    sequence_labels,
										    token_labels,
										    choice_labels,
										)






				def 							snake_case      (					self						:       Any,					lowerCAmelCase__						:       Any,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Union[str, Any],					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       Any,					*lowerCAmelCase__						:       Dict				)      -> Any:




										'''simple docstring'''



										_UpperCamelCase     :   Dict      =       TFOpenAIGPTModel(config=lowerCAmelCase__				)
										_UpperCamelCase     :   Any      =       {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
										_UpperCamelCase     :   Optional[int]      =       model(lowerCAmelCase__				)

										_UpperCamelCase     :   str      =       [input_ids, input_mask]
										_UpperCamelCase     :   Union[str, Any]      =       model(lowerCAmelCase__				)

										_UpperCamelCase     :   Any      =       model(lowerCAmelCase__				)

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






				def 							snake_case      (					self						:       Any,					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       str,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       List[str],					*lowerCAmelCase__						:       List[str]				)      -> Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase     :   int      =       TFOpenAIGPTLMHeadModel(config=lowerCAmelCase__				)
										_UpperCamelCase     :   Dict      =       {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
										_UpperCamelCase     :   Any      =       model(lowerCAmelCase__				)
										self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.vocab_size)				)






				def 							snake_case      (					self						:       Tuple,					lowerCAmelCase__						:       Optional[int],					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       Tuple,					lowerCAmelCase__						:       Union[str, Any],					*lowerCAmelCase__						:       int				)      -> List[Any]:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       TFOpenAIGPTDoubleHeadsModel(config=lowerCAmelCase__				)

										_UpperCamelCase     :   Any      =       tf.tile(tf.expand_dims(lowerCAmelCase__,					1				),					(1, self.num_choices, 1)				)
										_UpperCamelCase     :   Union[str, Any]      =       tf.tile(tf.expand_dims(lowerCAmelCase__,					1				),					(1, self.num_choices, 1)				)
										_UpperCamelCase     :   Any      =       tf.tile(tf.expand_dims(lowerCAmelCase__,					1				),					(1, self.num_choices, 1)				)

										_UpperCamelCase     :   int      =       {
										    '''input_ids''': multiple_choice_inputs_ids,
										    '''mc_token_ids''': mc_token_ids,
										    '''attention_mask''': multiple_choice_input_mask,
										    '''token_type_ids''': multiple_choice_token_type_ids,
										}
										_UpperCamelCase     :   List[str]      =       model(lowerCAmelCase__				)
										self.parent.assertEqual(
										    result.logits.shape,					(self.batch_size, self.num_choices, self.seq_length, self.vocab_size)				)
										self.parent.assertEqual(result.mc_logits.shape,					(self.batch_size, self.num_choices)				)






				def 							snake_case      (					self						:       Any,					lowerCAmelCase__						:       List[str],					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Optional[Any],					lowerCAmelCase__						:       List[str],					lowerCAmelCase__						:       Union[str, Any],					*lowerCAmelCase__						:       Tuple				)      -> str:




										'''simple docstring'''



										_UpperCamelCase     :   Tuple      =       self.num_labels
										_UpperCamelCase     :   int      =       ids_tensor([self.batch_size],					self.type_sequence_label_size				)
										_UpperCamelCase     :   List[Any]      =       {
										    '''input_ids''': input_ids,
										    '''attention_mask''': input_mask,
										    '''token_type_ids''': token_type_ids,
										    '''labels''': sequence_labels,
										}
										_UpperCamelCase     :   int      =       TFOpenAIGPTForSequenceClassification(lowerCAmelCase__				)
										_UpperCamelCase     :   List[Any]      =       model(lowerCAmelCase__				)
										self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_labels)				)






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




										'''simple docstring'''



										_UpperCamelCase     :   int      =       self.prepare_config_and_inputs()

										(
										    (
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				
										)     :   List[Any]      =       config_and_inputs

										_UpperCamelCase     :   Tuple      =       {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
										return config, inputs_dict




@require_tf
class 					_a		( _lowerCAmelCase      ,							_lowerCAmelCase      ,							unittest.TestCase							):
				UpperCamelCase								=       (
				    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
				    if is_tf_available()
				    else ()
				)
				UpperCamelCase								=       (
				    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
				)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
				UpperCamelCase								=       (
				    {
				        '''feature-extraction''': TFOpenAIGPTModel,
				        '''text-classification''': TFOpenAIGPTForSequenceClassification,
				        '''text-generation''': TFOpenAIGPTLMHeadModel,
				        '''zero-shot''': TFOpenAIGPTForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				UpperCamelCase								=       False
				UpperCamelCase								=       False






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




										'''simple docstring'''



										if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
																# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
																# `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
																# tiny config could not be created.
																return True

										return False






				def 							snake_case      (					self						:       Tuple				)      -> Dict:




										'''simple docstring'''



										_UpperCamelCase     :   List[Any]      =       TFOpenAIGPTModelTester(self				)
										_UpperCamelCase     :   Any      =       ConfigTester(self,					config_class=lowerCAmelCase__,					n_embd=3_7				)






				def 							snake_case      (					self						:       int				)      -> Tuple:




										'''simple docstring'''



										self.config_tester.run_common_tests()






				def 							snake_case      (					self						:       Tuple				)      -> int:




										'''simple docstring'''



										_UpperCamelCase     :   int      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_model(*lowerCAmelCase__				)






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




										'''simple docstring'''



										_UpperCamelCase     :   int      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_lm_head(*lowerCAmelCase__				)






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




										'''simple docstring'''



										_UpperCamelCase     :   List[str]      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_double_head(*lowerCAmelCase__				)






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




										'''simple docstring'''



										_UpperCamelCase     :   List[Any]      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowerCAmelCase__				)






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




										'''simple docstring'''



										for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																_UpperCamelCase     :   str      =       TFOpenAIGPTModel.from_pretrained(lowerCAmelCase__				)
																self.assertIsNotNone(lowerCAmelCase__				)




@require_tf
class 					_a		( unittest.TestCase							):






				@slow
				def 							snake_case      (					self						:       Optional[Any]				)      -> List[Any]:




										'''simple docstring'''



										_UpperCamelCase     :   Any      =       TFOpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''				)
										_UpperCamelCase     :   Tuple      =       tf.convert_to_tensor([[4_8_1, 4_7_3_5, 5_4_4]],					dtype=tf.intaa				)  # the president is
										_UpperCamelCase     :   str      =       [
										    4_8_1,
										    4_7_3_5,
										    5_4_4,
										    2_4_6,
										    9_6_3,
										    8_7_0,
										    7_6_2,
										    2_3_9,
										    2_4_4,
										    4_0_4_7_7,
										    2_4_4,
										    2_4_9,
										    7_1_9,
										    8_8_1,
										    4_8_7,
										    5_4_4,
										    2_4_0,
										    2_4_4,
										    6_0_3,
										    4_8_1,
										]  # the president is a very good man. " \n " i\'m sure he is, " said the

										_UpperCamelCase     :   Any      =       model.generate(lowerCAmelCase__,					do_sample=lowerCAmelCase__				)
										self.assertListEqual(output_ids[0].numpy().tolist(),					lowerCAmelCase__				)










"""simple docstring"""




import os

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

UpperCamelCase_	 ={"""UserAgent""": UserAgent().random}
UpperCamelCase_	 ="""https://www.mywaifulist.moe/random"""





def 			a_							(				_lowercase			,		_lowercase  ):
						_UpperCamelCase     :   Optional[Any]      =       requests.get(_lowercase			,		headers=_lowercase  )
						with open(_lowercase			,		'''wb'''  ) as file:
												file.write(image.content  )





def 			a_							(				):
						_UpperCamelCase     :   Union[str, Any]      =       BeautifulSoup(requests.get(_lowercase			,		headers=_lowercase  ).text			,		'''html.parser'''  )
						_UpperCamelCase     :   List[str]      =       soup.find('''meta'''			,		attrs={'''property''': '''og:title'''}  ).attrs['''content''']
						_UpperCamelCase     :   Optional[int]      =       soup.find('''meta'''			,		attrs={'''property''': '''og:image'''}  ).attrs['''content''']
						_UpperCamelCase     :   Any      =       soup.find('''p'''			,		id='''description'''  ).get_text()
						_UpperCamelCase  ,				_UpperCamelCase     :   Optional[int]      =       os.path.splitext(os.path.basename(_lowercase  )  )
						_UpperCamelCase     :   Dict      =       title.strip().replace(''' '''			,		'''_'''  )
						_UpperCamelCase     :   str      =       F"""{image_title}{image_extension}"""
						save_image(_lowercase			,		_lowercase  )
						return (title, description, image_title)


if __name__ == "__main__":
						UpperCamelCase_ ,      UpperCamelCase_ ,      UpperCamelCase_	 =random_anime_character()
						print(F"{title}\n\n{desc}\n\nImage saved : {image_title}")



