





'''simple docstring'''






import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
		import jax.numpy as jnp







class 			lowerCamelCase       (						UpperCAmelCase_  ):


					def __get__(					self	:  str       ,     __snake_case	:  List[str]       ,     __snake_case	:  List[Any]=None       ):





											'''simple docstring'''





											if obj is None:
																	return self
											if self.fget is None:
																	raise AttributeError('unreadable attribute'       )
											_snake_case:   Tuple  					=		'__cached_' + self.fget.__name__
											_snake_case:   Tuple  					=		getattr(_snake_case       ,     _snake_case       ,     _snake_case       )
											if cached is None:
																	_snake_case:   Any  					=		self.fget(_snake_case       )
																	setattr(_snake_case       ,     _snake_case       ,     _snake_case       )
											return cached





def       lowercase_      (		lowercase__						)   ->Optional[Any]:
						_snake_case:   Tuple  					=		val.lower()
						if val in {"y", "yes", "t", "true", "on", "1"}:
												return 1
						if val in {"n", "no", "f", "false", "off", "0"}:
												return 0
						raise ValueError(F'''invalid truth value {val!r}'''						)





def       lowercase_      (		lowercase__						)   ->Any:
						if is_torch_fx_proxy(__UpperCamelCase						):
												return True
						if is_torch_available():
												import torch

												if isinstance(__UpperCamelCase				,  torch.Tensor						):
																		return True
						if is_tf_available():
												import tensorflow as tf

												if isinstance(__UpperCamelCase				,  tf.Tensor						):
																		return True

						if is_flax_available():
												import jax.numpy as jnp
												from jax.core import Tracer

												if isinstance(__UpperCamelCase				,  (jnp.ndarray, Tracer)						):
																		return True

						return isinstance(__UpperCamelCase				,  np.ndarray						)





def       lowercase_      (		lowercase__						)   ->Union[str, Any]:
						return isinstance(__UpperCamelCase				,  np.ndarray						)





def       lowercase_      (		lowercase__						)   ->List[Any]:
						return _is_numpy(__UpperCamelCase						)





def       lowercase_      (		lowercase__						)   ->str:
						import torch

						return isinstance(__UpperCamelCase				,  torch.Tensor						)





def       lowercase_      (		lowercase__						)   ->Any:
						return False if not is_torch_available() else _is_torch(__UpperCamelCase						)





def       lowercase_      (		lowercase__						)   ->str:
						import torch

						return isinstance(__UpperCamelCase				,  torch.device						)





def       lowercase_      (		lowercase__						)   ->List[Any]:
						return False if not is_torch_available() else _is_torch_device(__UpperCamelCase						)





def       lowercase_      (		lowercase__						)   ->List[Any]:
						import torch

						if isinstance(__UpperCamelCase				,  __UpperCamelCase						):
												if hasattr(__UpperCamelCase				,  __UpperCamelCase						):
																		_snake_case:   Optional[int]  					=		getattr(__UpperCamelCase				,  __UpperCamelCase						)
												else:
																		return False
						return isinstance(__UpperCamelCase				,  torch.dtype						)





def       lowercase_      (		lowercase__						)   ->List[Any]:
						return False if not is_torch_available() else _is_torch_dtype(__UpperCamelCase						)





def       lowercase_      (		lowercase__						)   ->Any:
						import tensorflow as tf

						return isinstance(__UpperCamelCase				,  tf.Tensor						)





def       lowercase_      (		lowercase__						)   ->List[Any]:
						return False if not is_tf_available() else _is_tensorflow(__UpperCamelCase						)





def       lowercase_      (		lowercase__						)   ->Any:
						import tensorflow as tf

						# the `is_symbolic_tensor` predicate is only available starting with TF 2.14
						if hasattr(__UpperCamelCase				,  'is_symbolic_tensor'						):
												return tf.is_symbolic_tensor(__UpperCamelCase						)
						return type(__UpperCamelCase						) == tf.Tensor





def       lowercase_      (		lowercase__						)   ->Any:
						return False if not is_tf_available() else _is_tf_symbolic_tensor(__UpperCamelCase						)





def       lowercase_      (		lowercase__						)   ->Optional[Any]:
						import jax.numpy as jnp  # noqa: F811

						return isinstance(__UpperCamelCase				,  jnp.ndarray						)





def       lowercase_      (		lowercase__						)   ->str:
						return False if not is_flax_available() else _is_jax(__UpperCamelCase						)





def       lowercase_      (		lowercase__						)   ->Any:
						if isinstance(__UpperCamelCase				,  (dict, UserDict)						):
												return {k: to_py_obj(__UpperCamelCase						) for k, v in obj.items()}
						elif isinstance(__UpperCamelCase				,  (list, tuple)						):
												return [to_py_obj(__UpperCamelCase						) for o in obj]
						elif is_tf_tensor(__UpperCamelCase						):
												return obj.numpy().tolist()
						elif is_torch_tensor(__UpperCamelCase						):
												return obj.detach().cpu().tolist()
						elif is_jax_tensor(__UpperCamelCase						):
												return np.asarray(__UpperCamelCase						).tolist()
						elif isinstance(__UpperCamelCase				,  (np.ndarray, np.number)						):  # tolist also works on 0d np arrays
												return obj.tolist()
						else:
												return obj





def       lowercase_      (		lowercase__						)   ->Dict:
						if isinstance(__UpperCamelCase				,  (dict, UserDict)						):
												return {k: to_numpy(__UpperCamelCase						) for k, v in obj.items()}
						elif isinstance(__UpperCamelCase				,  (list, tuple)						):
												return np.array(__UpperCamelCase						)
						elif is_tf_tensor(__UpperCamelCase						):
												return obj.numpy()
						elif is_torch_tensor(__UpperCamelCase						):
												return obj.detach().cpu().numpy()
						elif is_jax_tensor(__UpperCamelCase						):
												return np.asarray(__UpperCamelCase						)
						else:
												return obj







class 			lowerCamelCase       (						UpperCAmelCase_  ):


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		fields(self       )

											# Safety and consistency checks
											if not len(_snake_case       ):
																	raise ValueError(f'''{self.__class__.__name__} has no fields.'''       )
											if not all(field.default is None for field in class_fields[1:]       ):
																	raise ValueError(f'''{self.__class__.__name__} should not have more than one required field.'''       )

											_snake_case:   Any  					=		getattr(self       ,     class_fields[0].name       )
											_snake_case:   Any  					=		all(getattr(self       ,     field.name       ) is None for field in class_fields[1:]       )

											if other_fields_are_none and not is_tensor(_snake_case       ):
																	if isinstance(_snake_case       ,     _snake_case       ):
																							_snake_case:   str  					=		first_field.items()
																							_snake_case:   Union[str, Any]  					=		True
																	else:
																							try:
																													_snake_case:   Union[str, Any]  					=		iter(_snake_case       )
																													_snake_case:   List[Any]  					=		True
																							except TypeError:
																													_snake_case:   int  					=		False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
																	if first_field_iterator:
																							for idx, element in enumerate(_snake_case       ):
																													if (
																													    not isinstance(_snake_case       ,     (list, tuple)       )
																													    or not len(_snake_case       ) == 2
																													    or not isinstance(element[0]       ,     _snake_case       )
																													):
																																			if idx == 0:
																																									# If we do not have an iterator of key/values, set it as attribute
																																									_snake_case:   Optional[Any]  					=		first_field
																																			else:
																																									# If we have a mixed iterator, raise an error
																																									raise ValueError(
																																									    f'''Cannot set key/value for {element}. It needs to be a tuple (key, value).'''       )
																																			break
																													setattr(self       ,     element[0]       ,     element[1]       )
																													if element[1] is not None:
																																			_snake_case:   Optional[int]  					=		element[1]
																	elif first_field is not None:
																							_snake_case:   List[Any]  					=		first_field
											else:
																	for field in class_fields:
																							_snake_case:   int  					=		getattr(self       ,     field.name       )
																							if v is not None:
																													_snake_case:   List[Any]  					=		v


					def __delitem__(					self	:  List[Any]       ,     *__snake_case	:  str       ,     **__snake_case	:  Optional[Any]       ):





											'''simple docstring'''





											raise Exception(f'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'''       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ,     *__snake_case	:  List[str]       ,     **__snake_case	:  List[str]       ):





											'''simple docstring'''





											raise Exception(f'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'''       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ,     *__snake_case	:  List[Any]       ,     **__snake_case	:  str       ):





											'''simple docstring'''





											raise Exception(f'''You cannot use ``pop`` on a {self.__class__.__name__} instance.'''       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ,     *__snake_case	:  Tuple       ,     **__snake_case	:  Optional[int]       ):





											'''simple docstring'''





											raise Exception(f'''You cannot use ``update`` on a {self.__class__.__name__} instance.'''       )


					def __getitem__(					self	:  Optional[int]       ,     __snake_case	:  List[Any]       ):





											'''simple docstring'''





											if isinstance(_snake_case       ,     _snake_case       ):
																	_snake_case:   Tuple  					=		dict(self.items()       )
																	return inner_dict[k]
											else:
																	return self.to_tuple()[k]


					def __setattr__(					self	:  Union[str, Any]       ,     __snake_case	:  Tuple       ,     __snake_case	:  int       ):





											'''simple docstring'''





											if name in self.keys() and value is not None:
																	# Don't call self.__setitem__ to avoid recursion errors
																	super().__setitem__(_snake_case       ,     _snake_case       )
											super().__setattr__(_snake_case       ,     _snake_case       )


					def __setitem__(					self	:  List[str]       ,     __snake_case	:  str       ,     __snake_case	:  Any       ):





											'''simple docstring'''





											super().__setitem__(_snake_case       ,     _snake_case       )
											# Don't call self.__setattr__ to avoid recursion errors
											super().__setattr__(_snake_case       ,     _snake_case       )




					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											return tuple(self[k] for k in self.keys()       )







class 			lowerCamelCase       (						UpperCAmelCase_     ,							UpperCAmelCase_  ):


					@classmethod
					def    SCREAMING_SNAKE_CASE_		(					cls	:  Any       ,     __snake_case	:  Optional[int]       ):





											'''simple docstring'''





											raise ValueError(
											    f'''{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys()       )}'''       )







class 			lowerCamelCase       (						UpperCAmelCase_  ):
					_SCREAMING_SNAKE_CASE							   =    "longest"
					_SCREAMING_SNAKE_CASE							   =    "max_length"
					_SCREAMING_SNAKE_CASE							   =    "do_not_pad"







class 			lowerCamelCase       (						UpperCAmelCase_  ):
					_SCREAMING_SNAKE_CASE							   =    "pt"
					_SCREAMING_SNAKE_CASE							   =    "tf"
					_SCREAMING_SNAKE_CASE							   =    "np"
					_SCREAMING_SNAKE_CASE							   =    "jax"







class 			lowerCamelCase       :


					def __init__(					self	:  Optional[int]       ,     __snake_case	:  List[ContextManager]       ):





											'''simple docstring'''





											_snake_case:   Any  					=		context_managers
											_snake_case:   Union[str, Any]  					=		ExitStack()


					def __enter__(					self	:  Tuple       ):





											'''simple docstring'''





											for context_manager in self.context_managers:
																	self.stack.enter_context(_snake_case       )




					def __exit__(					self	:  List[Any]       ,     *__snake_case	:  Tuple       ,     **__snake_case	:  str       ):





											'''simple docstring'''





											self.stack.__exit__(*_snake_case       ,     **_snake_case       )





def       lowercase_      (		lowercase__						)   ->List[Any]:
						_snake_case:   Dict  					=		infer_framework(__UpperCamelCase						)
						if framework == "tf":
												_snake_case:   Union[str, Any]  					=		inspect.signature(model_class.call						)  # TensorFlow models
						elif framework == "pt":
												_snake_case:   Union[str, Any]  					=		inspect.signature(model_class.forward						)  # PyTorch models
						else:
												_snake_case:   Dict  					=		inspect.signature(model_class.__call__						)  # Flax models

						for p in signature.parameters:
												if p == "return_loss" and signature.parameters[p].default is True:
																		return True

						return False





def       lowercase_      (		lowercase__						)   ->Dict:
						_snake_case:   List[Any]  					=		model_class.__name__
						_snake_case:   Optional[Any]  					=		infer_framework(__UpperCamelCase						)
						if framework == "tf":
												_snake_case:   Dict  					=		inspect.signature(model_class.call						)  # TensorFlow models
						elif framework == "pt":
												_snake_case:   Optional[Any]  					=		inspect.signature(model_class.forward						)  # PyTorch models
						else:
												_snake_case:   Optional[Any]  					=		inspect.signature(model_class.__call__						)  # Flax models

						if "QuestionAnswering" in model_name:
												return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
						else:
												return [p for p in signature.parameters if "label" in p]





def       lowercase_      (		lowercase__				,  lowercase__ = ""				,  lowercase__ = "."						)   ->Any:

						def _flatten_dict(lowercase__				,  lowercase__=""				,  lowercase__="."						):
												for k, v in d.items():
																		_snake_case:   List[Any]  					=		str(__UpperCamelCase						) + delimiter + str(__UpperCamelCase						) if parent_key else k
																		if v and isinstance(__UpperCamelCase				,  __UpperCamelCase						):
																								yield from flatten_dict(__UpperCamelCase				,  __UpperCamelCase				,  delimiter=__UpperCamelCase						).items()
																		else:
																								yield key, v

						return dict(_flatten_dict(__UpperCamelCase				,  __UpperCamelCase				,  __UpperCamelCase						)						)





@contextmanager
def       lowercase_      (		lowercase__				,  lowercase__ = False						)   ->int:
						if use_temp_dir:
												with tempfile.TemporaryDirectory() as tmp_dir:
																		yield tmp_dir
						else:
												yield working_dir





def       lowercase_      (		lowercase__				,  lowercase__=None						)   ->List[Any]:
						if is_numpy_array(__UpperCamelCase						):
												return np.transpose(__UpperCamelCase				,  axes=__UpperCamelCase						)
						elif is_torch_tensor(__UpperCamelCase						):
												return array.T if axes is None else array.permute(*__UpperCamelCase						)
						elif is_tf_tensor(__UpperCamelCase						):
												import tensorflow as tf

												return tf.transpose(__UpperCamelCase				,  perm=__UpperCamelCase						)
						elif is_jax_tensor(__UpperCamelCase						):
												return jnp.transpose(__UpperCamelCase				,  axes=__UpperCamelCase						)
						else:
												raise ValueError(F'''Type not supported for transpose: {type(__UpperCamelCase						)}.'''						)





def       lowercase_      (		lowercase__				,  lowercase__						)   ->List[Any]:
						if is_numpy_array(__UpperCamelCase						):
												return np.reshape(__UpperCamelCase				,  __UpperCamelCase						)
						elif is_torch_tensor(__UpperCamelCase						):
												return array.reshape(*__UpperCamelCase						)
						elif is_tf_tensor(__UpperCamelCase						):
												import tensorflow as tf

												return tf.reshape(__UpperCamelCase				,  __UpperCamelCase						)
						elif is_jax_tensor(__UpperCamelCase						):
												return jnp.reshape(__UpperCamelCase				,  __UpperCamelCase						)
						else:
												raise ValueError(F'''Type not supported for reshape: {type(__UpperCamelCase						)}.'''						)





def       lowercase_      (		lowercase__				,  lowercase__=None						)   ->Tuple:
						if is_numpy_array(__UpperCamelCase						):
												return np.squeeze(__UpperCamelCase				,  axis=__UpperCamelCase						)
						elif is_torch_tensor(__UpperCamelCase						):
												return array.squeeze() if axis is None else array.squeeze(dim=__UpperCamelCase						)
						elif is_tf_tensor(__UpperCamelCase						):
												import tensorflow as tf

												return tf.squeeze(__UpperCamelCase				,  axis=__UpperCamelCase						)
						elif is_jax_tensor(__UpperCamelCase						):
												return jnp.squeeze(__UpperCamelCase				,  axis=__UpperCamelCase						)
						else:
												raise ValueError(F'''Type not supported for squeeze: {type(__UpperCamelCase						)}.'''						)





def       lowercase_      (		lowercase__				,  lowercase__						)   ->List[Any]:
						if is_numpy_array(__UpperCamelCase						):
												return np.expand_dims(__UpperCamelCase				,  __UpperCamelCase						)
						elif is_torch_tensor(__UpperCamelCase						):
												return array.unsqueeze(dim=__UpperCamelCase						)
						elif is_tf_tensor(__UpperCamelCase						):
												import tensorflow as tf

												return tf.expand_dims(__UpperCamelCase				,  axis=__UpperCamelCase						)
						elif is_jax_tensor(__UpperCamelCase						):
												return jnp.expand_dims(__UpperCamelCase				,  axis=__UpperCamelCase						)
						else:
												raise ValueError(F'''Type not supported for expand_dims: {type(__UpperCamelCase						)}.'''						)





def       lowercase_      (		lowercase__						)   ->Optional[Any]:
						if is_numpy_array(__UpperCamelCase						):
												return np.size(__UpperCamelCase						)
						elif is_torch_tensor(__UpperCamelCase						):
												return array.numel()
						elif is_tf_tensor(__UpperCamelCase						):
												import tensorflow as tf

												return tf.size(__UpperCamelCase						)
						elif is_jax_tensor(__UpperCamelCase						):
												return array.size
						else:
												raise ValueError(F'''Type not supported for expand_dims: {type(__UpperCamelCase						)}.'''						)





def       lowercase_      (		lowercase__				,  lowercase__						)   ->Tuple:
						for key, value in auto_map.items():
												if isinstance(__UpperCamelCase				,  (tuple, list)						):
																		_snake_case:   Tuple  					=		[F'''{repo_id}--{v}''' if (v is not None and '--' not in v) else v for v in value]
												elif value is not None and "--" not in value:
																		_snake_case:   int  					=		F'''{repo_id}--{value}'''

						return auto_map





def       lowercase_      (		lowercase__						)   ->Optional[int]:
						for base_class in inspect.getmro(__UpperCamelCase						):
												_snake_case:   Optional[Any]  					=		base_class.__module__
												_snake_case:   Any  					=		base_class.__name__
												if module.startswith('tensorflow'						) or module.startswith('keras'						) or name == "TFPreTrainedModel":
																		return "tf"
												elif module.startswith('torch'						) or name == "PreTrainedModel":
																		return "pt"
												elif module.startswith('flax'						) or module.startswith('jax'						) or name == "FlaxPreTrainedModel":
																		return "flax"
						else:
												raise TypeError(F'''Could not infer framework from class {model_class}.'''						)












'''simple docstring'''






import sys
import webbrowser

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
		print('Googling.....')
		A   : Optional[int]             =			'https://www.google.com/search?q=' + ' '.join(sys.argv[1:])
		A   : Dict             =			requests.get(url, headers={'UserAgent': UserAgent().random})
		# res.raise_for_status()
		with open('project1a.html', 'wb') as out_file:  # only for knowing the class
				for data in res.iter_content(10_000):
						out_file.write(data)
		A   : List[Any]             =			BeautifulSoup(res.text, 'html.parser')
		A   : List[Any]             =			list(soup.select('.eZt8xd'))[:5]

		print(len(links))
		for link in links:
				if link.text == "Maps":
						webbrowser.open(link.get('href'))
				else:
						webbrowser.open(F'https://google.com{link.get("href")}')





