



import unittest
from queue import Empty
from threading import Thread

from transformers import AutoTokenizer, TextIteratorStreamer, TextStreamer, is_torch_available
from transformers.testing_utils import CaptureStdout, require_torch, torch_device

from ..test_modeling_common import ids_tensor


if is_torch_available():
		import torch

		from transformers import AutoModelForCausalLM




@require_torch
class 							lowerCAmelCase__  (	unittest.TestCase						):







					def  _lowercase			(       self      :     Optional[int]):
											A__	:							List[str]						    = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-gpt2")
											A__	:							Optional[Any]						    = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2").to(_A)
											A__	:							str						    = -1

											A__	:							Optional[int]						    = ids_tensor((1, 5)			,		vocab_size=model.config.vocab_size).to(_A)
											A__	:							Tuple						    = model.generate(_A			,		max_new_tokens=10			,		do_sample=_A)
											A__	:							List[Any]						    = tokenizer.decode(greedy_ids[0])

											with CaptureStdout() as cs:
																	A__	:							List[str]						    = TextStreamer(_A)
																	model.generate(_A			,		max_new_tokens=10			,		do_sample=_A			,		streamer=_A)
											# The greedy text should be printed to stdout, except for the final "\n" in the streamer
											A__	:							Union[str, Any]						    = cs.out[:-1]

											self.assertEqual(_A			,		_A)







					def  _lowercase			(       self      :     Union[str, Any]):
											A__	:							Any						    = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-gpt2")
											A__	:							str						    = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2").to(_A)
											A__	:							List[str]						    = -1

											A__	:							Tuple						    = ids_tensor((1, 5)			,		vocab_size=model.config.vocab_size).to(_A)
											A__	:							Tuple						    = model.generate(_A			,		max_new_tokens=10			,		do_sample=_A)
											A__	:							Any						    = tokenizer.decode(greedy_ids[0])

											A__	:							Any						    = TextIteratorStreamer(_A)
											A__	:							Optional[int]						    = {"input_ids": input_ids, "max_new_tokens": 10, "do_sample": False, "streamer": streamer}
											A__	:							List[Any]						    = Thread(target=model.generate			,		kwargs=_A)
											thread.start()
											A__	:							List[Any]						    = ""
											for new_text in streamer:
																	streamer_text += new_text

											self.assertEqual(_A			,		_A)







					def  _lowercase			(       self      :     Tuple):
											A__	:							List[Any]						    = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-gpt2")
											A__	:							List[Any]						    = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2").to(_A)
											A__	:							List[Any]						    = -1

											A__	:							List[Any]						    = ids_tensor((1, 5)			,		vocab_size=model.config.vocab_size).to(_A)
											A__	:							Tuple						    = model.generate(_A			,		max_new_tokens=10			,		do_sample=_A)
											A__	:							int						    = greedy_ids[:, input_ids.shape[1] :]
											A__	:							Optional[Any]						    = tokenizer.decode(new_greedy_ids[0])

											with CaptureStdout() as cs:
																	A__	:							Tuple						    = TextStreamer(_A			,		skip_prompt=_A)
																	model.generate(_A			,		max_new_tokens=10			,		do_sample=_A			,		streamer=_A)
											# The greedy text should be printed to stdout, except for the final "\n" in the streamer
											A__	:							Optional[Any]						    = cs.out[:-1]

											self.assertEqual(_A			,		_A)







					def  _lowercase			(       self      :     Dict):
											# Tests that we can pass `decode_kwargs` to the streamer to control how the tokens are decoded. Must be tested
											# with actual models -- the dummy models' tokenizers are not aligned with their models, and
											# `skip_special_tokens=True` has no effect on them
											A__	:							Union[str, Any]						    = AutoTokenizer.from_pretrained("distilgpt2")
											A__	:							Dict						    = AutoModelForCausalLM.from_pretrained("distilgpt2").to(_A)
											A__	:							List[Any]						    = -1

											A__	:							Union[str, Any]						    = torch.ones((1, 5)			,		device=_A).long() * model.config.bos_token_id
											with CaptureStdout() as cs:
																	A__	:							int						    = TextStreamer(_A			,		skip_special_tokens=_A)
																	model.generate(_A			,		max_new_tokens=1			,		do_sample=_A			,		streamer=_A)

											# The prompt contains a special token, so the streamer should not print it. As such, the output text, when
											# re-tokenized, must only contain one token
											A__	:							Optional[int]						    = cs.out[:-1]  # Remove the final "\n"
											A__	:							Any						    = tokenizer(_A			,		return_tensors="pt")
											self.assertEqual(streamer_text_tokenized.input_ids.shape			,		(1, 1))







					def  _lowercase			(       self      :     List[str]):
											A__	:							Optional[int]						    = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-gpt2")
											A__	:							Dict						    = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2").to(_A)
											A__	:							Optional[int]						    = -1

											A__	:							List[Any]						    = ids_tensor((1, 5)			,		vocab_size=model.config.vocab_size).to(_A)
											A__	:							Dict						    = TextIteratorStreamer(_A			,		timeout=0.0_01)
											A__	:							Dict						    = {"input_ids": input_ids, "max_new_tokens": 10, "do_sample": False, "streamer": streamer}
											A__	:							Tuple						    = Thread(target=model.generate			,		kwargs=_A)
											thread.start()

											# The streamer will timeout after 0.001 seconds, so an exception will be raised
											with self.assertRaises(_A):
																	A__	:							List[Any]						    = ""
																	for new_text in streamer:
																							streamer_text += new_text




import requests

snake_case    :						int  =						''  # <-- Put your OpenWeatherMap appid here!
snake_case    :						int  =						'https://api.openweathermap.org/data/2.5/'
def 	snake_case__       (					__lowercase = "Chicago"							,     __lowercase = APPID       )		->		dict:







						"""simple docstring"""

						return requests.get(URL_BASE + "weather"							,     params=locals()       ).json()
def 	snake_case__       (					__lowercase = "Kolkata, India"							,     __lowercase = APPID       )		->		dict:







						"""simple docstring"""

						return requests.get(URL_BASE + "forecast"							,     params=locals()       ).json()
def 	snake_case__       (					__lowercase = 55.68							,     __lowercase = 12.57							,     __lowercase = APPID       )		->		dict:







						"""simple docstring"""

						return requests.get(URL_BASE + "onecall"							,     params=locals()       ).json()


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

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