

'''simple docstring'''







import shutil
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_tf_cross_test,
    require_tf,
    require_torch,
    require_torchvision,
    require_vision,
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available


if is_vision_available():
      from PIL import Image

      from transformers import AutoProcessor, SamImageProcessor, SamProcessor

if is_torch_available():
      import torch

if is_tf_available():
      import tensorflow as tf


@require_vision
@require_torchvision
class    A__ ( unittest.TestCase     ):



    def    snake_case_     (   self    )  -> Optional[Any]:





           '''simple docstring'''
           A_		   = tempfile.mkdtemp()
           A_		   = SamImageProcessor()
           A_		   = SamProcessor(UpperCamelCase__    )
           processor.save_pretrained(self.tmpdirname    )



    def    snake_case_     (   self						,			**UpperCamelCase__    )  -> Tuple:





           '''simple docstring'''
           return AutoProcessor.from_pretrained(self.tmpdirname						,			**UpperCamelCase__    ).image_processor



    def    snake_case_     (   self    )  -> List[Any]:





           '''simple docstring'''
           shutil.rmtree(self.tmpdirname    )



    def    snake_case_     (   self    )  -> Optional[Any]:





           '''simple docstring'''
           A_		   = [np.random.randint(255						,			size=(3, 30, 400)						,			dtype=np.uinta    )]

           A_		   = [Image.fromarray(np.moveaxis(UpperCamelCase__						,			0						,			-1    )    ) for x in image_inputs]

           return image_inputs



    def    snake_case_     (   self    )  -> Optional[int]:





           '''simple docstring'''
           A_		   = SamProcessor(image_processor=self.get_image_processor()    )
           processor.save_pretrained(self.tmpdirname    )

           A_		   = self.get_image_processor(do_normalize=UpperCamelCase__						,			padding_value=1.0    )

           A_		   = SamProcessor.from_pretrained(self.tmpdirname						,			do_normalize=UpperCamelCase__						,			padding_value=1.0    )

           self.assertEqual(processor.image_processor.to_json_string()						,			image_processor_add_kwargs.to_json_string()    )
           self.assertIsInstance(processor.image_processor						,			UpperCamelCase__    )



    def    snake_case_     (   self    )  -> Any:





           '''simple docstring'''
           A_		   = self.get_image_processor()

           A_		   = SamProcessor(image_processor=UpperCamelCase__    )

           A_		   = self.prepare_image_inputs()

           A_		   = image_processor(UpperCamelCase__						,			return_tensors="""np"""    )
           A_		   = processor(images=UpperCamelCase__						,			return_tensors="""np"""    )

           input_feat_extract.pop("""original_sizes"""    )  # pop original_sizes as it is popped in the processor
           input_feat_extract.pop("""reshaped_input_sizes"""    )  # pop original_sizes as it is popped in the processor

           for key in input_feat_extract.keys():
                  self.assertAlmostEqual(input_feat_extract[key].sum()						,			input_processor[key].sum()						,			delta=1e-2    )







    @require_torch
    def    snake_case_     (   self    )  -> Optional[int]:





           '''simple docstring'''
           A_		   = self.get_image_processor()

           A_		   = SamProcessor(image_processor=UpperCamelCase__    )
           A_		   = [torch.ones((1, 3, 5, 5)    )]

           A_		   = [[1764, 2646]]

           A_		   = [[683, 1024]]
           A_		   = processor.post_process_masks(UpperCamelCase__						,			UpperCamelCase__						,			UpperCamelCase__    )
           self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)    )

           A_		   = processor.post_process_masks(
               UpperCamelCase__						,			torch.tensor(UpperCamelCase__    )						,			torch.tensor(UpperCamelCase__    )    )
           self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)    )

           # should also work with np
           A_		   = [np.ones((1, 3, 5, 5)    )]
           A_		   = processor.post_process_masks(UpperCamelCase__						,			np.array(UpperCamelCase__    )						,			np.array(UpperCamelCase__    )    )

           self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)    )

           A_		   = [[1, 0], [0, 1]]
           with self.assertRaises(UpperCamelCase__    ):
                  A_		   = processor.post_process_masks(UpperCamelCase__						,			np.array(UpperCamelCase__    )						,			np.array(UpperCamelCase__    )    )


@require_vision
@require_tf
class    A__ ( unittest.TestCase     ):



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





           '''simple docstring'''
           A_		   = tempfile.mkdtemp()
           A_		   = SamImageProcessor()
           A_		   = SamProcessor(UpperCamelCase__    )
           processor.save_pretrained(self.tmpdirname    )



    def    snake_case_     (   self						,			**UpperCamelCase__    )  -> List[Any]:





           '''simple docstring'''
           return AutoProcessor.from_pretrained(self.tmpdirname						,			**UpperCamelCase__    ).image_processor



    def    snake_case_     (   self    )  -> str:





           '''simple docstring'''
           shutil.rmtree(self.tmpdirname    )



    def    snake_case_     (   self    )  -> Tuple:





           '''simple docstring'''
           A_		   = [np.random.randint(255						,			size=(3, 30, 400)						,			dtype=np.uinta    )]

           A_		   = [Image.fromarray(np.moveaxis(UpperCamelCase__						,			0						,			-1    )    ) for x in image_inputs]

           return image_inputs



    def    snake_case_     (   self    )  -> Tuple:





           '''simple docstring'''
           A_		   = SamProcessor(image_processor=self.get_image_processor()    )
           processor.save_pretrained(self.tmpdirname    )

           A_		   = self.get_image_processor(do_normalize=UpperCamelCase__						,			padding_value=1.0    )

           A_		   = SamProcessor.from_pretrained(self.tmpdirname						,			do_normalize=UpperCamelCase__						,			padding_value=1.0    )

           self.assertEqual(processor.image_processor.to_json_string()						,			image_processor_add_kwargs.to_json_string()    )
           self.assertIsInstance(processor.image_processor						,			UpperCamelCase__    )



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





           '''simple docstring'''
           A_		   = self.get_image_processor()

           A_		   = SamProcessor(image_processor=UpperCamelCase__    )

           A_		   = self.prepare_image_inputs()

           A_		   = image_processor(UpperCamelCase__						,			return_tensors="""np"""    )
           A_		   = processor(images=UpperCamelCase__						,			return_tensors="""np"""    )

           input_feat_extract.pop("""original_sizes"""    )  # pop original_sizes as it is popped in the processor
           input_feat_extract.pop("""reshaped_input_sizes"""    )  # pop reshaped_input_sizes as it is popped in the processor

           for key in input_feat_extract.keys():
                  self.assertAlmostEqual(input_feat_extract[key].sum()						,			input_processor[key].sum()						,			delta=1e-2    )







    @require_tf
    def    snake_case_     (   self    )  -> Any:





           '''simple docstring'''
           A_		   = self.get_image_processor()

           A_		   = SamProcessor(image_processor=UpperCamelCase__    )
           A_		   = [tf.ones((1, 3, 5, 5)    )]

           A_		   = [[1764, 2646]]

           A_		   = [[683, 1024]]
           A_		   = processor.post_process_masks(UpperCamelCase__						,			UpperCamelCase__						,			UpperCamelCase__						,			return_tensors="""tf"""    )
           self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)    )

           A_		   = processor.post_process_masks(
               UpperCamelCase__						,			tf.convert_to_tensor(UpperCamelCase__    )						,			tf.convert_to_tensor(UpperCamelCase__    )						,			return_tensors="""tf"""						,			)
           self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)    )

           # should also work with np
           A_		   = [np.ones((1, 3, 5, 5)    )]
           A_		   = processor.post_process_masks(
               UpperCamelCase__						,			np.array(UpperCamelCase__    )						,			np.array(UpperCamelCase__    )						,			return_tensors="""tf"""    )

           self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)    )

           A_		   = [[1, 0], [0, 1]]
           with self.assertRaises(tf.errors.InvalidArgumentError    ):
                  A_		   = processor.post_process_masks(
                      UpperCamelCase__						,			np.array(UpperCamelCase__    )						,			np.array(UpperCamelCase__    )						,			return_tensors="""tf"""    )


@require_vision
@require_torchvision
class    A__ ( unittest.TestCase     ):



    def    snake_case_     (   self    )  -> Optional[Any]:





           '''simple docstring'''
           A_		   = tempfile.mkdtemp()
           A_		   = SamImageProcessor()
           A_		   = SamProcessor(UpperCamelCase__    )
           processor.save_pretrained(self.tmpdirname    )



    def    snake_case_     (   self						,			**UpperCamelCase__    )  -> Union[str, Any]:





           '''simple docstring'''
           return AutoProcessor.from_pretrained(self.tmpdirname						,			**UpperCamelCase__    ).image_processor



    def    snake_case_     (   self    )  -> Tuple:





           '''simple docstring'''
           shutil.rmtree(self.tmpdirname    )



    def    snake_case_     (   self    )  -> List[str]:





           '''simple docstring'''
           A_		   = [np.random.randint(255						,			size=(3, 30, 400)						,			dtype=np.uinta    )]

           A_		   = [Image.fromarray(np.moveaxis(UpperCamelCase__						,			0						,			-1    )    ) for x in image_inputs]

           return image_inputs



    @is_pt_tf_cross_test
    def    snake_case_     (   self    )  -> Any:





           '''simple docstring'''
           A_		   = self.get_image_processor()

           A_		   = SamProcessor(image_processor=UpperCamelCase__    )
           A_		   = np.random.randint(0						,			2						,			size=(1, 3, 5, 5)    ).astype(np.floataa    )
           A_		   = [tf.convert_to_tensor(UpperCamelCase__    )]
           A_		   = [torch.tensor(UpperCamelCase__    )]

           A_		   = [[1764, 2646]]

           A_		   = [[683, 1024]]
           A_		   = processor.post_process_masks(
               UpperCamelCase__						,			UpperCamelCase__						,			UpperCamelCase__						,			return_tensors="""tf"""    )
           A_		   = processor.post_process_masks(
               UpperCamelCase__						,			UpperCamelCase__						,			UpperCamelCase__						,			return_tensors="""pt"""    )

           self.assertTrue(np.all(tf_masks[0].numpy() == pt_masks[0].numpy()    )    )







    @is_pt_tf_cross_test
    def    snake_case_     (   self    )  -> Union[str, Any]:





           '''simple docstring'''
           A_		   = self.get_image_processor()

           A_		   = SamProcessor(image_processor=UpperCamelCase__    )

           A_		   = self.prepare_image_inputs()

           A_		   = image_processor(UpperCamelCase__						,			return_tensors="""pt"""    )["""pixel_values"""].numpy()
           A_		   = processor(images=UpperCamelCase__						,			return_tensors="""pt"""    )["""pixel_values"""].numpy()

           A_		   = image_processor(UpperCamelCase__						,			return_tensors="""tf"""    )["""pixel_values"""].numpy()
           A_		   = processor(images=UpperCamelCase__						,			return_tensors="""tf"""    )["""pixel_values"""].numpy()

           self.assertTrue(np.allclose(UpperCamelCase__						,			UpperCamelCase__    )    )
           self.assertTrue(np.allclose(UpperCamelCase__						,			UpperCamelCase__    )    )
           self.assertTrue(np.allclose(UpperCamelCase__						,			UpperCamelCase__    )    )



'''simple docstring'''







import requests

__lowerCamelCase						    =      ''''''  # <-- Put your OpenWeatherMap appid here!
__lowerCamelCase						    =      '''https://api.openweathermap.org/data/2.5/'''
def  UpperCAmelCase__      ( UpperCAmelCase__ = "Chicago",    UpperCAmelCase__ = APPID			)     ->     dict:
       return requests.get(URL_BASE + """weather""",    params=locals()			).json()
def  UpperCAmelCase__      ( UpperCAmelCase__ = "Kolkata, India",    UpperCAmelCase__ = APPID			)     ->     dict:
       return requests.get(URL_BASE + """forecast""",    params=locals()			).json()
def  UpperCAmelCase__      ( UpperCAmelCase__ = 55.68,    UpperCAmelCase__ = 12.57,    UpperCAmelCase__ = APPID			)     ->     dict:
       return requests.get(URL_BASE + """onecall""",    params=locals()			).json()


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

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