



"""simple docstring"""
from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, 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 import (
      TFConvBertForMaskedLM,
      TFConvBertForMultipleChoice,
      TFConvBertForQuestionAnswering,
      TFConvBertForSequenceClassification,
      TFConvBertForTokenClassification,
      TFConvBertModel,
  )
class 				_UpperCAmelCase				:





     '''simple docstring'''



     def __init__(   self			,      A			,      A=1_3			,      A=7			,      A=True			,      A=True			,      A=True			,      A=True			,      A=9_9			,      A=3_2			,      A=2			,      A=4			,      A=3_7			,      A="gelu"			,      A=0.1			,      A=0.1			,      A=5_1_2			,      A=1_6			,      A=2			,      A=0.02			,      A=3			,      A=4			,      A=None			,      )				->   str:
         _UpperCAmelCase				:    int											=       parent
         _UpperCAmelCase				:    List[str]											=       1_3
         _UpperCAmelCase				:    Tuple											=       7
         _UpperCAmelCase				:    Dict											=       True
         _UpperCAmelCase				:    Optional[Any]											=       True
         _UpperCAmelCase				:    List[str]											=       True
         _UpperCAmelCase				:    str											=       True
         _UpperCAmelCase				:    Optional[Any]											=       9_9
         _UpperCAmelCase				:    Union[str, Any]											=       3_8_4
         _UpperCAmelCase				:    Union[str, Any]											=       2
         _UpperCAmelCase				:    List[str]											=       4
         _UpperCAmelCase				:    Union[str, Any]											=       3_7
         _UpperCAmelCase				:    Optional[Any]											=       '''gelu'''
         _UpperCAmelCase				:    List[Any]											=       0.1
         _UpperCAmelCase				:    List[str]											=       0.1
         _UpperCAmelCase				:    Optional[int]											=       5_1_2
         _UpperCAmelCase				:    Tuple											=       1_6
         _UpperCAmelCase				:    Optional[int]											=       2
         _UpperCAmelCase				:    Tuple											=       0.02
         _UpperCAmelCase				:    List[Any]											=       3
         _UpperCAmelCase				:    Tuple											=       4
         _UpperCAmelCase				:    Optional[Any]											=       1_2_8
         _UpperCAmelCase				:    Tuple											=       2
         _UpperCAmelCase				:    Optional[int]											=       9
         _UpperCAmelCase				:    List[str]											=       1
         _UpperCAmelCase				:    Union[str, Any]											=       None





     def 					__lowerCAmelCase      (   self						)				->   Tuple:
         _UpperCAmelCase				:    List[str]											=       ids_tensor([self.batch_size, self.seq_length]			,      self.vocab_size						)

         _UpperCAmelCase				:    Optional[int]											=       None
         if self.use_input_mask:
             _UpperCAmelCase				:    List[str]											=       random_attention_mask([self.batch_size, self.seq_length]						)

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

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

         _UpperCAmelCase				:    str											=       ConvBertConfig(
             vocab_size=self.vocab_size			,      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			,      max_position_embeddings=self.max_position_embeddings			,      type_vocab_size=self.type_vocab_size			,      initializer_range=self.initializer_range			,      return_dict=A			,      )

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





     def 					__lowerCAmelCase      (   self			,      A			,      A			,      A			,      A			,      A			,      A			,      A						)				->   List[Any]:
         _UpperCAmelCase				:    str											=       TFConvBertModel(config=A						)
         _UpperCAmelCase				:    List[str]											=       {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

         _UpperCAmelCase				:    List[Any]											=       [input_ids, input_mask]
         _UpperCAmelCase				:    str											=       model(A						)

         _UpperCAmelCase				:    str											=       model(A						)

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





     def 					__lowerCAmelCase      (   self			,      A			,      A			,      A			,      A			,      A			,      A			,      A						)				->   str:
         _UpperCAmelCase				:    str											=       TFConvBertForMaskedLM(config=A						)
         _UpperCAmelCase				:    List[str]											=       {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }
         _UpperCAmelCase				:    str											=       model(A						)
         self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length, self.vocab_size)						)





     def 					__lowerCAmelCase      (   self			,      A			,      A			,      A			,      A			,      A			,      A			,      A						)				->   str:
         _UpperCAmelCase				:    Optional[Any]											=       self.num_labels
         _UpperCAmelCase				:    str											=       TFConvBertForSequenceClassification(config=A						)
         _UpperCAmelCase				:    List[str]											=       {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }

         _UpperCAmelCase				:    Dict											=       model(A						)
         self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.num_labels)						)





     def 					__lowerCAmelCase      (   self			,      A			,      A			,      A			,      A			,      A			,      A			,      A						)				->   Optional[Any]:
         _UpperCAmelCase				:    Any											=       self.num_choices
         _UpperCAmelCase				:    str											=       TFConvBertForMultipleChoice(config=A						)
         _UpperCAmelCase				:    Tuple											=       tf.tile(tf.expand_dims(A			,      1						)			,      (1, self.num_choices, 1)						)
         _UpperCAmelCase				:    int											=       tf.tile(tf.expand_dims(A			,      1						)			,      (1, self.num_choices, 1)						)
         _UpperCAmelCase				:    List[Any]											=       tf.tile(tf.expand_dims(A			,      1						)			,      (1, self.num_choices, 1)						)
         _UpperCAmelCase				:    Optional[int]											=       {
             '''input_ids''': multiple_choice_inputs_ids,
             '''attention_mask''': multiple_choice_input_mask,
             '''token_type_ids''': multiple_choice_token_type_ids,
         }
         _UpperCAmelCase				:    List[str]											=       model(A						)
         self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.num_choices)						)





     def 					__lowerCAmelCase      (   self			,      A			,      A			,      A			,      A			,      A			,      A			,      A						)				->   int:
         _UpperCAmelCase				:    Dict											=       self.num_labels
         _UpperCAmelCase				:    List[str]											=       TFConvBertForTokenClassification(config=A						)
         _UpperCAmelCase				:    int											=       {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }
         _UpperCAmelCase				:    Tuple											=       model(A						)
         self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length, self.num_labels)						)





     def 					__lowerCAmelCase      (   self			,      A			,      A			,      A			,      A			,      A			,      A			,      A						)				->   Any:
         _UpperCAmelCase				:    Optional[Any]											=       TFConvBertForQuestionAnswering(config=A						)
         _UpperCAmelCase				:    List[str]											=       {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }

         _UpperCAmelCase				:    str											=       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 					__lowerCAmelCase      (   self						)				->   Tuple:
         _UpperCAmelCase				:    List[Any]											=       self.prepare_config_and_inputs()
         (
             (
             _UpperCAmelCase  
         )				,							(
             _UpperCAmelCase  
         )				,							(
             _UpperCAmelCase  
         )				,							(
             _UpperCAmelCase  
         )				,							(
             _UpperCAmelCase  
         )				,							(
             _UpperCAmelCase  
         )				,							(
             _UpperCAmelCase  
         )				,							  
         )				:    Tuple											=       config_and_inputs
         _UpperCAmelCase				:    Dict											=       {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
         return config, inputs_dict



@require_tf
class 				_UpperCAmelCase				(					UpperCamelCase__						,UpperCamelCase__						,unittest.TestCase ):





     '''simple docstring'''



     a__   							=(
         (
             TFConvBertModel,
             TFConvBertForMaskedLM,
             TFConvBertForQuestionAnswering,
             TFConvBertForSequenceClassification,
             TFConvBertForTokenClassification,
             TFConvBertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     a__   							=(
         {
             'feature-extraction': TFConvBertModel,
             'fill-mask': TFConvBertForMaskedLM,
             'question-answering': TFConvBertForQuestionAnswering,
             'text-classification': TFConvBertForSequenceClassification,
             'token-classification': TFConvBertForTokenClassification,
             'zero-shot': TFConvBertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     a__   							=False
     a__   							=False
     a__   							=False





     def 					__lowerCAmelCase      (   self						)				->   Optional[int]:
         _UpperCAmelCase				:    Union[str, Any]											=       TFConvBertModelTester(self						)
         _UpperCAmelCase				:    List[str]											=       ConfigTester(self			,      config_class=A			,      hidden_size=3_7						)





     def 					__lowerCAmelCase      (   self						)				->   int:
         self.config_tester.run_common_tests()





     def 					__lowerCAmelCase      (   self						)				->   Any:
         _UpperCAmelCase				:    int											=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*A						)





     def 					__lowerCAmelCase      (   self						)				->   Tuple:
         _UpperCAmelCase				:    Optional[int]											=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*A						)





     def 					__lowerCAmelCase      (   self						)				->   Optional[Any]:
         _UpperCAmelCase				:    Dict											=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*A						)





     def 					__lowerCAmelCase      (   self						)				->   Dict:
         _UpperCAmelCase				:    Union[str, Any]											=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*A						)





     def 					__lowerCAmelCase      (   self						)				->   str:
         _UpperCAmelCase				:    List[str]											=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*A						)





     def 					__lowerCAmelCase      (   self						)				->   Any:
         _UpperCAmelCase				:    Dict											=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*A						)





     @slow
     def 					__lowerCAmelCase      (   self						)				->   List[str]:
         _UpperCAmelCase				,							_UpperCAmelCase				:    Any											=       self.model_tester.prepare_config_and_inputs_for_common()
         _UpperCAmelCase				:    List[str]											=       True
         _UpperCAmelCase				:    Dict											=       True

         if hasattr(A			,      '''use_cache'''						):
             _UpperCAmelCase				:    Union[str, Any]											=       True

         _UpperCAmelCase				:    int											=       getattr(self.model_tester			,      '''encoder_seq_length'''			,      self.model_tester.seq_length						)
         _UpperCAmelCase				:    int											=       getattr(self.model_tester			,      '''key_length'''			,      A						)

         for model_class in self.all_model_classes:
             _UpperCAmelCase				:    Optional[Any]											=       self._prepare_for_class(A			,      A						)
             _UpperCAmelCase				:    str											=       model_class(A						)
             _UpperCAmelCase				:    Optional[Any]											=       len(model(A						)						)

             with tempfile.TemporaryDirectory() as tmpdirname:
                 model.save_pretrained(A			,      saved_model=A						)
                 _UpperCAmelCase				:    Tuple											=       os.path.join(A			,      '''saved_model'''			,      '''1'''						)
                 _UpperCAmelCase				:    List[Any]											=       tf.keras.models.load_model(A						)
                 _UpperCAmelCase				:    List[Any]											=       model(A						)

                 if self.is_encoder_decoder:
                     _UpperCAmelCase				:    Tuple											=       outputs['''encoder_hidden_states''']
                     _UpperCAmelCase				:    str											=       outputs['''encoder_attentions''']
                 else:
                     _UpperCAmelCase				:    Optional[Any]											=       outputs['''hidden_states''']
                     _UpperCAmelCase				:    Dict											=       outputs['''attentions''']

                 self.assertEqual(len(A						)			,      A						)

                 _UpperCAmelCase				:    Optional[Any]											=       getattr(
                     self.model_tester			,      '''expected_num_hidden_layers'''			,      self.model_tester.num_hidden_layers + 1						)

                 self.assertEqual(len(A						)			,      A						)
                 self.assertListEqual(
                     list(output_hidden_states[0].shape[-2:]						)			,      [self.model_tester.seq_length, self.model_tester.hidden_size]			,      )

                 self.assertEqual(len(A						)			,      self.model_tester.num_hidden_layers						)
                 self.assertListEqual(
                     list(output_attentions[0].shape[-3:]						)			,      [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]			,      )





     @slow
     def 					__lowerCAmelCase      (   self						)				->   Union[str, Any]:
         _UpperCAmelCase				:    int											=       TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''						)
         self.assertIsNotNone(A						)





     def 					__lowerCAmelCase      (   self						)				->   Dict:
         _UpperCAmelCase				,							_UpperCAmelCase				:    Dict											=       self.model_tester.prepare_config_and_inputs_for_common()
         _UpperCAmelCase				:    Union[str, Any]											=       True
         _UpperCAmelCase				:    Optional[int]											=       getattr(self.model_tester			,      '''decoder_seq_length'''			,      self.model_tester.seq_length						)
         _UpperCAmelCase				:    List[Any]											=       getattr(self.model_tester			,      '''encoder_seq_length'''			,      self.model_tester.seq_length						)
         _UpperCAmelCase				:    Tuple											=       getattr(self.model_tester			,      '''key_length'''			,      A						)
         _UpperCAmelCase				:    str											=       getattr(self.model_tester			,      '''key_length'''			,      A						)

         def check_decoder_attentions_output(A						):
             _UpperCAmelCase				:    int											=       len(A						)
             self.assertEqual(out_len % 2			,      0						)
             _UpperCAmelCase				:    int											=       outputs.decoder_attentions
             self.assertEqual(len(A						)			,      self.model_tester.num_hidden_layers						)
             self.assertListEqual(
                 list(decoder_attentions[0].shape[-3:]						)			,      [self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]			,      )

         def check_encoder_attentions_output(A						):
             _UpperCAmelCase				:    Union[str, Any]											=       [
                 t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
             ]
             self.assertEqual(len(A						)			,      self.model_tester.num_hidden_layers						)
             self.assertListEqual(
                 list(attentions[0].shape[-3:]						)			,      [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]			,      )

         for model_class in self.all_model_classes:
             _UpperCAmelCase				:    Union[str, Any]											=       True
             _UpperCAmelCase				:    List[str]											=       False
             _UpperCAmelCase				:    Optional[int]											=       model_class(A						)
             _UpperCAmelCase				:    Dict											=       model(self._prepare_for_class(A			,      A						)						)
             _UpperCAmelCase				:    List[Any]											=       len(A						)
             self.assertEqual(config.output_hidden_states			,      A						)
             check_encoder_attentions_output(A						)

             if self.is_encoder_decoder:
                 _UpperCAmelCase				:    Tuple											=       model_class(A						)
                 _UpperCAmelCase				:    Any											=       model(self._prepare_for_class(A			,      A						)						)
                 self.assertEqual(config.output_hidden_states			,      A						)
                 check_decoder_attentions_output(A						)

             # Check that output attentions can also be changed via the config
             del inputs_dict["output_attentions"]
             _UpperCAmelCase				:    Tuple											=       True
             _UpperCAmelCase				:    Any											=       model_class(A						)
             _UpperCAmelCase				:    Union[str, Any]											=       model(self._prepare_for_class(A			,      A						)						)
             self.assertEqual(config.output_hidden_states			,      A						)
             check_encoder_attentions_output(A						)

             # Check attention is always last and order is fine
             _UpperCAmelCase				:    Dict											=       True
             _UpperCAmelCase				:    str											=       True
             _UpperCAmelCase				:    Any											=       model_class(A						)
             _UpperCAmelCase				:    Optional[Any]											=       model(self._prepare_for_class(A			,      A						)						)

             self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)			,      len(A						)						)
             self.assertEqual(model.config.output_hidden_states			,      A						)
             check_encoder_attentions_output(A						)



@require_tf
class 				_UpperCAmelCase				(					unittest.TestCase ):





     '''simple docstring'''



     @slow
     def 					__lowerCAmelCase      (   self						)				->   int:
         _UpperCAmelCase				:    List[Any]											=       TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''						)
         _UpperCAmelCase				:    List[Any]											=       tf.constant([[0, 1, 2, 3, 4, 5]]						)
         _UpperCAmelCase				:    Union[str, Any]											=       model(A						)[0]

         _UpperCAmelCase				:    Any											=       [1, 6, 7_6_8]
         self.assertEqual(output.shape			,      A						)

         _UpperCAmelCase				:    List[Any]											=       tf.constant(
             [
                 [
                     [-0.03_475_493, -0.4_686_034, -0.30_638_832],
                     [0.22_637_248, -0.26_988_646, -0.7_423_424],
                     [0.10_324_868, -0.45_013_508, -0.58_280_784],
                 ]
             ]						)
         tf.debugging.assert_near(output[:, :3, :3]			,      A			,      atol=1E-4						)




'''simple docstring'''
import requests

lowercase__											=''  # <-- Put your OpenWeatherMap appid here!
lowercase__											='https://api.openweathermap.org/data/2.5/'






def      UpperCamelCase_				(      A__ = "Chicago"  ,      A__ = APPID						):
	return requests.get(URL_BASE + """weather"""  ,      params=locals()						).json()






def      UpperCamelCase_				(      A__ = "Kolkata, India"  ,      A__ = APPID						):
	return requests.get(URL_BASE + """forecast"""  ,      params=locals()						).json()






def      UpperCamelCase_				(      A__ = 55.68  ,      A__ = 12.57  ,      A__ = APPID						):
	return requests.get(URL_BASE + """onecall"""  ,      params=locals()						).json()


if __name__ == "__main__":
		from pprint import pprint

		while True:
				lowercase__											=input('Enter a location:').strip()
				if location:
						pprint(current_weather(location))
				else:
						break
