

from __future__ import annotations

import unittest

from transformers import CTRLConfig, 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.ctrl.modeling_tf_ctrl import (
         TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
         TFCTRLForSequenceClassification,
         TFCTRLLMHeadModel,
         TFCTRLModel,
     )


class     lowerCAmelCase				(    __UpperCamelCase				):


       '''simple docstring'''







       def __init__(	self					:  Optional[int]						,	__snake_case					:  Optional[int]						,	)   -> str:







        '''simple docstring'''

        lowerCamelCase      						=    parent
        lowerCamelCase      						=    13
        lowerCamelCase      						=    7
        lowerCamelCase      						=    True
        lowerCamelCase      						=    True
        lowerCamelCase      						=    True
        lowerCamelCase      						=    True
        lowerCamelCase      						=    True
        lowerCamelCase      						=    99
        lowerCamelCase      						=    32
        lowerCamelCase      						=    2
        lowerCamelCase      						=    4
        lowerCamelCase      						=    37
        lowerCamelCase      						=    'gelu'
        lowerCamelCase      						=    0.1
        lowerCamelCase      						=    0.1
        lowerCamelCase      						=    512
        lowerCamelCase      						=    16
        lowerCamelCase      						=    2
        lowerCamelCase      						=    0.02
        lowerCamelCase      						=    3
        lowerCamelCase      						=    4
        lowerCamelCase      						=    None
        lowerCamelCase      						=    self.vocab_size - 1

       def   lowerCamelCase__						(	self					:  Tuple     )   -> Tuple:







        '''simple docstring'''

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

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

        lowerCamelCase      						=    None
        if self.use_token_type_ids:
         lowerCamelCase      						=    ids_tensor([self.batch_size, self.seq_length]						,	self.type_vocab_size     )

        lowerCamelCase      						=    None
        if self.use_mc_token_ids:
         lowerCamelCase      						=    ids_tensor([self.batch_size, self.num_choices]						,	self.seq_length     )

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

        lowerCamelCase      						=    CTRLConfig(
            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						,	)

        lowerCamelCase      						=    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   lowerCamelCase__						(	self					:  Union[str, Any]						,	__snake_case					:  Dict						,	__snake_case					:  Any						,	__snake_case					:  str						,	__snake_case					:  Optional[int]						,	__snake_case					:  Dict						,	*__snake_case					:  Optional[Any]     )   -> Tuple:







        '''simple docstring'''

        lowerCamelCase      						=    TFCTRLModel(config=__snake_case     )
        lowerCamelCase      						=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        lowerCamelCase      						=    model(__snake_case     )

        lowerCamelCase      						=    [input_ids, None, input_mask]  # None is the input for 'past'
        lowerCamelCase      						=    model(__snake_case     )

        lowerCamelCase      						=    model(__snake_case     )

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

       def   lowerCamelCase__						(	self					:  Any						,	__snake_case					:  Any						,	__snake_case					:  List[Any]						,	__snake_case					:  Optional[Any]						,	__snake_case					:  Tuple						,	__snake_case					:  str						,	*__snake_case					:  Optional[Any]     )   -> Dict:







        '''simple docstring'''

        lowerCamelCase      						=    TFCTRLLMHeadModel(config=__snake_case     )
        lowerCamelCase      						=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        lowerCamelCase      						=    model(__snake_case     )
        self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.seq_length, self.vocab_size)     )

       def   lowerCamelCase__						(	self					:  Any						,	__snake_case					:  Tuple						,	__snake_case					:  List[Any]						,	__snake_case					:  Union[str, Any]						,	__snake_case					:  Any						,	__snake_case					:  Dict						,	*__snake_case					:  Dict     )   -> Any:







        '''simple docstring'''

        lowerCamelCase      						=    self.num_labels
        lowerCamelCase      						=    ids_tensor([self.batch_size]						,	self.type_sequence_label_size     )
        lowerCamelCase      						=    {
            'input_ids': input_ids,
            'token_type_ids': token_type_ids,
            'labels': sequence_labels,
        }
        lowerCamelCase      						=    TFCTRLForSequenceClassification(__snake_case     )
        lowerCamelCase      						=    model(__snake_case     )
        self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.num_labels)     )





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







        '''simple docstring'''

        lowerCamelCase      						=    self.prepare_config_and_inputs()

        (
            (
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	(
            lowerCamelCase
        )						,	
        )      						=    config_and_inputs

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


@require_tf
class     lowerCAmelCase				(    __UpperCamelCase   ,				__UpperCamelCase   ,				unittest.TestCase				):


       '''simple docstring'''







       snake_case    							=	(TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
       snake_case    							=	(TFCTRLLMHeadModel,) if is_tf_available() else ()
       snake_case    							=	(
           {
               'feature-extraction': TFCTRLModel,
               'text-classification': TFCTRLForSequenceClassification,
               'text-generation': TFCTRLLMHeadModel,
               'zero-shot': TFCTRLForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       snake_case    							=	False
       snake_case    							=	False

       def   lowerCamelCase__						(	self					:  Any						,	__snake_case					:  List[Any]						,	__snake_case					:  List[str]						,	__snake_case					:  List[str]						,	__snake_case					:  Any						,	__snake_case					:  str     )   -> Dict:







        '''simple docstring'''

        if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
         # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
         # `CTRLConfig` 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   lowerCamelCase__						(	self					:  List[Any]     )   -> Optional[int]:







        '''simple docstring'''

        lowerCamelCase      						=    TFCTRLModelTester(self     )
        lowerCamelCase      						=    ConfigTester(self						,	config_class=__snake_case						,	n_embd=37     )

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







        '''simple docstring'''

        self.config_tester.run_common_tests()

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







        '''simple docstring'''

        lowerCamelCase      						=    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_model(*__snake_case     )

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







        '''simple docstring'''

        lowerCamelCase      						=    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_lm_head(*__snake_case     )

       def   lowerCamelCase__						(	self					:  int     )   -> Tuple:







        '''simple docstring'''

        lowerCamelCase      						=    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_for_sequence_classification(*__snake_case     )

       def   lowerCamelCase__						(	self					:  str     )   -> int:







        '''simple docstring'''

        lowerCamelCase						,	lowerCamelCase      						=    self.model_tester.prepare_config_and_inputs_for_common()
        lowerCamelCase      						=    [TFCTRLLMHeadModel]
        lowerCamelCase      						=    [TFCTRLForSequenceClassification]

        for model_class in self.all_model_classes:
         lowerCamelCase      						=    model_class(__snake_case     )
         model.build()  # may be needed for the get_bias() call below
         assert isinstance(model.get_input_embeddings()						,	tf.keras.layers.Layer     )

         if model_class in list_lm_models:
          lowerCamelCase      						=    model.get_output_embeddings()
          assert isinstance(__snake_case						,	tf.keras.layers.Layer     )
          lowerCamelCase      						=    model.get_bias()
          assert isinstance(__snake_case						,	__snake_case     )
          for k, v in name.items():
           assert isinstance(__snake_case						,	tf.Variable     )
         elif model_class in list_other_models_with_output_ebd:
          lowerCamelCase      						=    model.get_output_embeddings()
          assert isinstance(__snake_case						,	tf.keras.layers.Layer     )
          lowerCamelCase      						=    model.get_bias()
          assert name is None
         else:
          lowerCamelCase      						=    model.get_output_embeddings()
          assert x is None
          lowerCamelCase      						=    model.get_bias()
          assert name is None





       @slow
       def   lowerCamelCase__						(	self					:  str     )   -> List[Any]:







        '''simple docstring'''

        for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         lowerCamelCase      						=    TFCTRLModel.from_pretrained(__snake_case     )
         self.assertIsNotNone(__snake_case     )


@require_tf
class     lowerCAmelCase				(    unittest.TestCase				):


       '''simple docstring'''







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







        '''simple docstring'''

        lowerCamelCase      						=    TFCTRLLMHeadModel.from_pretrained('ctrl'     )
        lowerCamelCase      						=    tf.convert_to_tensor([[11859, 0, 1611, 8]]						,	dtype=tf.intaa     )  # Legal the president is
        lowerCamelCase      						=    [
            11859,
            0,
            1611,
            8,
            5,
            150,
            26449,
            2,
            19,
            348,
            469,
            3,
            2595,
            48,
            20740,
            246533,
            246533,
            19,
            30,
            5,
        ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

        lowerCamelCase      						=    model.generate(__snake_case						,	do_sample=__snake_case     )
        self.assertListEqual(output_ids[0].numpy().tolist()						,	__snake_case     )







import requests
from bsa import BeautifulSoup







def a_		(       UpperCamelCase_   :							int   ,					UpperCamelCase_   :							str  )							->   str:







 """simple docstring"""

 lowerCamelCase      						=    (
     'https://www.horoscope.com/us/horoscopes/general/'
     f'''horoscope-general-daily-{day}.aspx?sign={zodiac_sign}'''
 )
 lowerCamelCase      						=    BeautifulSoup(requests.get(UpperCamelCase_  ).content   ,					'html.parser'  )
 return soup.find('div'   ,					class_='main-horoscope'  ).p.text


if __name__ == "__main__":
     print('Daily Horoscope. \n')
     print(
         'enter your Zodiac sign number:\n',
         '1. Aries\n',
         '2. Taurus\n',
         '3. Gemini\n',
         '4. Cancer\n',
         '5. Leo\n',
         '6. Virgo\n',
         '7. Libra\n',
         '8. Scorpio\n',
         '9. Sagittarius\n',
         '10. Capricorn\n',
         '11. Aquarius\n',
         '12. Pisces\n',
     )
     _lowerCAmelCase :	Dict     				=    int(input('number> ').strip())
     print('choose some day:\n', 'yesterday\n', 'today\n', 'tomorrow\n')
     _lowerCAmelCase :	Optional[Any]     				=    input('enter the day> ')
     _lowerCAmelCase :	int     				=    horoscope(zodiac_sign, day)
     print(horoscope_text)




