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

import unittest

from transformers import LEDConfig, 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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
		import tensorflow as tf

		from transformers import TFLEDForConditionalGeneration, TFLEDModel







@require_tf
class   a_ :
			lowerCamelCase__	:			Optional[Any]       =    LEDConfig
			lowerCamelCase__	:			int       =    {}
			lowerCamelCase__	:			Any       =    'gelu'




			def __init__(       self					,   UpperCAmelCase					,   UpperCAmelCase=13					,   UpperCAmelCase=7					,   UpperCAmelCase=True					,   UpperCAmelCase=False					,   UpperCAmelCase=99					,   UpperCAmelCase=32					,   UpperCAmelCase=2					,   UpperCAmelCase=4					,   UpperCAmelCase=37					,   UpperCAmelCase=0.1					,   UpperCAmelCase=0.1					,   UpperCAmelCase=20					,   UpperCAmelCase=2					,   UpperCAmelCase=1					,   UpperCAmelCase=0					,   UpperCAmelCase=4					,   ):
				a_      				=						parent
				a_      				=						batch_size
				a_      				=						seq_length
				a_      				=						is_training
				a_      				=						use_labels
				a_      				=						vocab_size
				a_      				=						hidden_size
				a_      				=						num_hidden_layers
				a_      				=						num_attention_heads
				a_      				=						intermediate_size

				a_      				=						hidden_dropout_prob
				a_      				=						attention_probs_dropout_prob
				a_      				=						max_position_embeddings
				a_      				=						eos_token_id
				a_      				=						pad_token_id
				a_      				=						bos_token_id
				a_      				=						attention_window

				# `ModelTesterMixin.test_attention_outputs` is expecting attention tensors to be of size
				# [num_attention_heads, encoder_seq_length, encoder_key_length], but TFLongformerSelfAttention
				# returns attention of shape [num_attention_heads, encoder_seq_length, self.attention_window + 1]
				# because its local attention only attends to `self.attention_window` and one before and one after
				a_      				=						self.attention_window + 2

				# because of padding `encoder_seq_length`, is different from `seq_length`. Relevant for
				# the `test_attention_outputs` and `test_hidden_states_output` tests
				a_      				=						(
				    self.seq_length + (self.attention_window - self.seq_length % self.attention_window) % self.attention_window
				)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						ids_tensor([self.batch_size, self.seq_length - 1]					,   self.vocab_size	)
				a_      				=						tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size	)					,   1	)
				a_      				=						tf.concat([input_ids, eos_tensor]					,   axis=1	)

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

				a_      				=						self.config_cls(
				    vocab_size=self.vocab_size					,   d_model=self.hidden_size					,   encoder_layers=self.num_hidden_layers					,   decoder_layers=self.num_hidden_layers					,   encoder_attention_heads=self.num_attention_heads					,   decoder_attention_heads=self.num_attention_heads					,   encoder_ffn_dim=self.intermediate_size					,   decoder_ffn_dim=self.intermediate_size					,   dropout=self.hidden_dropout_prob					,   attention_dropout=self.attention_probs_dropout_prob					,   max_position_embeddings=self.max_position_embeddings					,   eos_token_ids=[2]					,   bos_token_id=self.bos_token_id					,   pad_token_id=self.pad_token_id					,   decoder_start_token_id=self.pad_token_id					,   attention_window=self.attention_window					,   **self.config_updates					,   )
				a_      				=						prepare_led_inputs_dict(UpperCAmelCase					,   UpperCAmelCase					,   UpperCAmelCase	)
				a_      				=						tf.concat(
				    [tf.zeros_like(UpperCAmelCase	)[:, :-1], tf.ones_like(UpperCAmelCase	)[:, -1:]]					,   axis=-1					,   )
				a_      				=						global_attention_mask
				return config, inputs_dict






			def 					lowerCAmelCase__					(       self					,   UpperCAmelCase					,   UpperCAmelCase	):
				a_      				=						TFLEDModel(config=UpperCAmelCase	).get_decoder()
				a_      				=						inputs_dict["""input_ids"""]

				a_      				=						input_ids[:1, :]
				a_      				=						inputs_dict["""attention_mask"""][:1, :]
				a_      				=						1

				# first forward pass
				a_      				=						model(UpperCAmelCase					,   attention_mask=UpperCAmelCase					,   use_cache=UpperCAmelCase	)

				a_				,  a_      				=						outputs.to_tuple()

				# create hypothetical next token and extent to next_input_ids
				a_      				=						ids_tensor((self.batch_size, 3)					,   config.vocab_size	)
				a_      				=						tf.cast(ids_tensor((self.batch_size, 3)					,   2	)					,   tf.inta	)

				# append to next input_ids and
				a_      				=						tf.concat([input_ids, next_tokens]					,   axis=-1	)
				a_      				=						tf.concat([attention_mask, next_attn_mask]					,   axis=-1	)

				a_      				=						model(UpperCAmelCase					,   attention_mask=UpperCAmelCase	)[0]
				a_      				=						model(UpperCAmelCase					,   attention_mask=UpperCAmelCase					,   past_key_values=UpperCAmelCase	)[0]

				self.parent.assertEqual(next_tokens.shape[1]					,   output_from_past.shape[1]	)

				# select random slice
				a_      				=						int(ids_tensor((1,)					,   output_from_past.shape[-1]	)	)
				a_      				=						output_from_no_past[:, -3:, random_slice_idx]
				a_      				=						output_from_past[:, :, random_slice_idx]

				# test that outputs are equal for slice
				tf.debugging.assert_near(UpperCAmelCase					,   UpperCAmelCase					,   rtol=1e-3	)







def      UpperCamelCase_				(      A__  ,      A__  ,      A__  ,      A__=None  ,      A__=None  ,      A__=None  ,      A__=None  ,      ):
	if attention_mask is None:
		a_      				=						tf.cast(tf.math.not_equal(A__  ,      config.pad_token_id						)  ,      tf.inta						)
	if decoder_attention_mask is None:
		a_      				=						tf.concat(
		    [
		        tf.ones(decoder_input_ids[:, :1].shape  ,      dtype=tf.inta						),
		        tf.cast(tf.math.not_equal(decoder_input_ids[:, 1:]  ,      config.pad_token_id						)  ,      tf.inta						),
		    ]  ,      axis=-1  ,      )
	if head_mask is None:
		a_      				=						tf.ones((config.encoder_layers, config.encoder_attention_heads)						)
	if decoder_head_mask is None:
		a_      				=						tf.ones((config.decoder_layers, config.decoder_attention_heads)						)
	return {
	    "input_ids": input_ids,
	    "attention_mask": attention_mask,
	    "decoder_input_ids": decoder_input_ids,
	    "decoder_attention_mask": decoder_attention_mask,
	    "head_mask": head_mask,
	    "decoder_head_mask": decoder_head_mask,
	}







@require_tf
class   a_ (      UpperCamelCase__		,  UpperCamelCase__		,  unittest.TestCase					):
			lowerCamelCase__	:			Optional[Any]       =    (TFLEDForConditionalGeneration, TFLEDModel) if is_tf_available() else ()
			lowerCamelCase__	:			Union[str, Any]       =    (TFLEDForConditionalGeneration,) if is_tf_available() else ()
			lowerCamelCase__	:			List[Any]       =    (
			    {
			        'conversational': TFLEDForConditionalGeneration,
			        'feature-extraction': TFLEDModel,
			        'summarization': TFLEDForConditionalGeneration,
			        'text2text-generation': TFLEDForConditionalGeneration,
			        'translation': TFLEDForConditionalGeneration,
			    }
			    if is_tf_available()
			    else {}
			)
			lowerCamelCase__	:			Optional[int]       =    True
			lowerCamelCase__	:			Tuple       =    False
			lowerCamelCase__	:			Any       =    False
			lowerCamelCase__	:			List[str]       =    False




			def 					lowerCAmelCase__					(       self	):
				a_      				=						TFLEDModelTester(self	)
				a_      				=						ConfigTester(self					,   config_class=UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				self.config_tester.run_common_tests()




			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.model_tester.prepare_config_and_inputs_for_common()
				self.model_tester.check_decoder_model_past_large_inputs(*UpperCAmelCase	)




			def 					lowerCAmelCase__					(       self	):
				a_				,  a_      				=						self.model_tester.prepare_config_and_inputs_for_common()
				a_      				=						tf.zeros_like(inputs_dict["""attention_mask"""]	)
				a_      				=						2
				a_      				=						tf.where(
				    tf.range(self.model_tester.seq_length	)[None, :] < num_global_attn_indices					,   1					,   inputs_dict["""global_attention_mask"""]					,   )

				a_      				=						True
				a_      				=						self.model_tester.seq_length
				a_      				=						self.model_tester.encoder_seq_length

				def check_decoder_attentions_output(UpperCAmelCase	):
					a_      				=						outputs.decoder_attentions
					self.assertEqual(len(UpperCAmelCase	)					,   self.model_tester.num_hidden_layers	)
					self.assertListEqual(
					    list(decoder_attentions[0].shape[-3:]	)					,   [self.model_tester.num_attention_heads, seq_length, seq_length]					,   )

				def check_encoder_attentions_output(UpperCAmelCase	):
					a_      				=						[t.numpy() for t in outputs.encoder_attentions]
					a_      				=						[t.numpy() for t in outputs.encoder_global_attentions]
					self.assertEqual(len(UpperCAmelCase	)					,   self.model_tester.num_hidden_layers	)
					self.assertEqual(len(UpperCAmelCase	)					,   self.model_tester.num_hidden_layers	)
					self.assertListEqual(
					    list(attentions[0].shape[-3:]	)					,   [self.model_tester.num_attention_heads, seq_length, seq_length]					,   )
					self.assertListEqual(
					    list(global_attentions[0].shape[-3:]	)					,   [self.model_tester.num_attention_heads, encoder_seq_length, num_global_attn_indices]					,   )

				for model_class in self.all_model_classes:
					a_      				=						True
					a_      				=						False
					a_      				=						False
					a_      				=						model_class(UpperCAmelCase	)
					a_      				=						model(self._prepare_for_class(UpperCAmelCase					,   UpperCAmelCase	)	)
					a_      				=						len(UpperCAmelCase	)
					self.assertEqual(config.output_hidden_states					,   UpperCAmelCase	)
					check_encoder_attentions_output(UpperCAmelCase	)

					if self.is_encoder_decoder:
						a_      				=						model_class(UpperCAmelCase	)
						a_      				=						model(self._prepare_for_class(UpperCAmelCase					,   UpperCAmelCase	)	)
						self.assertEqual(config.output_hidden_states					,   UpperCAmelCase	)
						check_decoder_attentions_output(UpperCAmelCase	)

					# Check that output attentions can also be changed via the config
					del inputs_dict["output_attentions"]
					a_      				=						True
					a_      				=						model_class(UpperCAmelCase	)
					a_      				=						model(self._prepare_for_class(UpperCAmelCase					,   UpperCAmelCase	)	)
					self.assertEqual(config.output_hidden_states					,   UpperCAmelCase	)
					check_encoder_attentions_output(UpperCAmelCase	)

					# Check attention is always last and order is fine
					a_      				=						True
					a_      				=						True
					a_      				=						model_class(UpperCAmelCase	)
					a_      				=						model(self._prepare_for_class(UpperCAmelCase					,   UpperCAmelCase	)	)

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




			@unittest.skip("""LED keeps using potentially symbolic tensors in conditionals and breaks tracing."""	)
			def 					lowerCAmelCase__					(       self	):
				pass






			def 					lowerCAmelCase__					(       self	):
				# TODO: Head-masking not yet implement
				pass







def      UpperCamelCase_				(      A__						):
	return tf.constant(A__  ,      dtype=tf.intaa						)


lowercase__											=1E-4







@slow
@require_tf
class   a_ (      unittest.TestCase					):




			def 					lowerCAmelCase__					(       self	):
				a_      				=						TFLEDForConditionalGeneration.from_pretrained("""allenai/led-base-16384"""	).led

				# change to intended input here
				a_      				=						_long_tensor([5_12 * [0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69]]	)
				a_      				=						_long_tensor([1_28 * [0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69]]	)
				a_      				=						prepare_led_inputs_dict(model.config					,   UpperCAmelCase					,   UpperCAmelCase	)
				a_      				=						model(**UpperCAmelCase	)[0]
				a_      				=						(1, 10_24, 7_68)
				self.assertEqual(output.shape					,   UpperCAmelCase	)
				# change to expected output here
				a_      				=						tf.convert_to_tensor(
				    [[2.30_50, 2.82_79, 0.65_31], [-1.84_57, -0.14_55, -3.56_61], [-1.01_86, 0.45_86, -2.20_43]]					,   )
				tf.debugging.assert_near(output[:, :3, :3]					,   UpperCAmelCase					,   atol=1e-3	)






			def 					lowerCAmelCase__					(       self	):
				a_      				=						TFLEDForConditionalGeneration.from_pretrained("""allenai/led-base-16384"""	)

				# change to intended input here
				a_      				=						_long_tensor([5_12 * [0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69]]	)
				a_      				=						_long_tensor([1_28 * [0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69]]	)
				a_      				=						prepare_led_inputs_dict(model.config					,   UpperCAmelCase					,   UpperCAmelCase	)
				a_      				=						model(**UpperCAmelCase	)[0]
				a_      				=						(1, 10_24, model.config.vocab_size)
				self.assertEqual(output.shape					,   UpperCAmelCase	)
				# change to expected output here
				a_      				=						tf.convert_to_tensor(
				    [[33.65_07, 6.45_72, 16.80_89], [5.87_39, -2.42_38, 11.29_02], [-3.21_39, -4.31_49, 4.27_83]]					,   )
				tf.debugging.assert_near(output[:, :3, :3]					,   UpperCAmelCase					,   atol=1e-3					,   rtol=1e-3	)


'''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
