from __future__ import annotations

import unittest

from transformers import 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 numpy
		import tensorflow as tf

		from transformers import (
		    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    BertConfig,
		    DPRConfig,
		    TFDPRContextEncoder,
		    TFDPRQuestionEncoder,
		    TFDPRReader,
		)




class   _UpperCamelCase :


			"""simple docstring"""






			def __init__(  self ,  lowerCAmelCase__ ,  lowerCAmelCase__=13 ,  lowerCAmelCase__=7 ,  lowerCAmelCase__=True ,  lowerCAmelCase__=True ,  lowerCAmelCase__=True ,  lowerCAmelCase__=True ,  lowerCAmelCase__=99 ,  lowerCAmelCase__=32 ,  lowerCAmelCase__=2 ,  lowerCAmelCase__=4 ,  lowerCAmelCase__=37 ,  lowerCAmelCase__="gelu" ,  lowerCAmelCase__=0.1 ,  lowerCAmelCase__=0.1 ,  lowerCAmelCase__=5_12 ,  lowerCAmelCase__=16 ,  lowerCAmelCase__=2 ,  lowerCAmelCase__=0.02 ,  lowerCAmelCase__=3 ,  lowerCAmelCase__=4 ,  lowerCAmelCase__=None ,  lowerCAmelCase__=0 ,  )	->   str:

							'''simple docstring'''


							__lowercase					     =				parent
							__lowercase					     =				batch_size
							__lowercase					     =				seq_length
							__lowercase					     =				is_training
							__lowercase					     =				use_input_mask
							__lowercase					     =				use_token_type_ids
							__lowercase					     =				use_labels
							__lowercase					     =				vocab_size
							__lowercase					     =				hidden_size
							__lowercase					     =				num_hidden_layers
							__lowercase					     =				num_attention_heads
							__lowercase					     =				intermediate_size
							__lowercase					     =				hidden_act
							__lowercase					     =				hidden_dropout_prob
							__lowercase					     =				attention_probs_dropout_prob
							__lowercase					     =				max_position_embeddings
							__lowercase					     =				type_vocab_size
							__lowercase					     =				type_sequence_label_size
							__lowercase					     =				initializer_range
							__lowercase					     =				num_labels
							__lowercase					     =				num_choices
							__lowercase					     =				scope
							__lowercase					     =				projection_dim





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   int:

							'''simple docstring'''


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

							__lowercase					     =				None
							if self.use_input_mask:
											# follow test_modeling_tf_ctrl.py
											__lowercase					     =				random_attention_mask([self.batch_size, self.seq_length]		)

							__lowercase					     =				None
							if self.use_token_type_ids:
											__lowercase					     =				ids_tensor([self.batch_size, self.seq_length] ,  self.type_vocab_size		)

							__lowercase					     =				None
							__lowercase					     =				None
							__lowercase					     =				None
							if self.use_labels:
											__lowercase					     =				ids_tensor([self.batch_size] ,  self.type_sequence_label_size		)
											__lowercase					     =				ids_tensor([self.batch_size, self.seq_length] ,  self.num_labels		)
											__lowercase					     =				ids_tensor([self.batch_size] ,  self.num_choices		)

							__lowercase					     =				BertConfig(
							    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 ,  is_decoder=lowerCAmelCase__ ,  initializer_range=self.initializer_range ,  )
							__lowercase					     =				DPRConfig(projection_dim=self.projection_dim ,  **config.to_dict()		)

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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   Tuple:

							'''simple docstring'''


							__lowercase					     =				TFDPRContextEncoder(config=lowerCAmelCase__		)
							__lowercase					     =				model(lowerCAmelCase__ ,  attention_mask=lowerCAmelCase__ ,  token_type_ids=lowerCAmelCase__		)
							__lowercase					     =				model(lowerCAmelCase__ ,  token_type_ids=lowerCAmelCase__		)
							__lowercase					     =				model(lowerCAmelCase__		)
							self.parent.assertEqual(result.pooler_output.shape ,  (self.batch_size, self.projection_dim or self.hidden_size)		)





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   Tuple:

							'''simple docstring'''


							__lowercase					     =				TFDPRQuestionEncoder(config=lowerCAmelCase__		)
							__lowercase					     =				model(lowerCAmelCase__ ,  attention_mask=lowerCAmelCase__ ,  token_type_ids=lowerCAmelCase__		)
							__lowercase					     =				model(lowerCAmelCase__ ,  token_type_ids=lowerCAmelCase__		)
							__lowercase					     =				model(lowerCAmelCase__		)
							self.parent.assertEqual(result.pooler_output.shape ,  (self.batch_size, self.projection_dim or self.hidden_size)		)





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   Tuple:

							'''simple docstring'''


							__lowercase					     =				TFDPRReader(config=lowerCAmelCase__		)
							__lowercase					     =				model(lowerCAmelCase__ ,  attention_mask=lowerCAmelCase__		)

							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)		)
							self.parent.assertEqual(result.relevance_logits.shape ,  (self.batch_size,)		)





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

							'''simple docstring'''


							__lowercase					     =				self.prepare_config_and_inputs()
							(
							    (
							    __lowercase
							)     ,	(
							    __lowercase
							)     ,	(
							    __lowercase
							)     ,	(
							    __lowercase
							)     ,	(
							    __lowercase
							)     ,	(
							    __lowercase
							)     ,	(
							    __lowercase
							)     ,	
							)					     =				config_and_inputs
							__lowercase					     =				{'''input_ids''': input_ids}
							return config, inputs_dict




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


			"""simple docstring"""






			__a    :					str     					=		(
			    (
			        TFDPRContextEncoder,
			        TFDPRQuestionEncoder,
			        TFDPRReader,
			    )
			    if is_tf_available()
			    else ()
			)
			__a    :					int     					=		{'''feature-extraction''': TFDPRQuestionEncoder} if is_tf_available() else {}

			__a    :					int     					=		False
			__a    :					Tuple     					=		False
			__a    :					List[Any]     					=		False
			__a    :					Any     					=		False
			__a    :					Dict     					=		False





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   Any:

							'''simple docstring'''


							__lowercase					     =				TFDPRModelTester(self		)
							__lowercase					     =				ConfigTester(self ,  config_class=lowerCAmelCase__ ,  hidden_size=37		)





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

							'''simple docstring'''


							self.config_tester.run_common_tests()





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   Dict:

							'''simple docstring'''


							__lowercase					     =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_context_encoder(*lowerCAmelCase__		)





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

							'''simple docstring'''


							__lowercase					     =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_question_encoder(*lowerCAmelCase__		)





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   Tuple:

							'''simple docstring'''


							__lowercase					     =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_reader(*lowerCAmelCase__		)





			@slow
			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   Union[str, Any]:

							'''simple docstring'''


							for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowercase					     =				TFDPRContextEncoder.from_pretrained(lowerCAmelCase__		)
											self.assertIsNotNone(lowerCAmelCase__		)

							for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowercase					     =				TFDPRContextEncoder.from_pretrained(lowerCAmelCase__		)
											self.assertIsNotNone(lowerCAmelCase__		)

							for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowercase					     =				TFDPRQuestionEncoder.from_pretrained(lowerCAmelCase__		)
											self.assertIsNotNone(lowerCAmelCase__		)

							for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowercase					     =				TFDPRReader.from_pretrained(lowerCAmelCase__		)
											self.assertIsNotNone(lowerCAmelCase__		)




@require_tf
class   _UpperCamelCase (		unittest.TestCase					):


			"""simple docstring"""






			@slow
			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   List[str]:

							'''simple docstring'''


							__lowercase					     =				TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base'''		)

							__lowercase					     =				tf.constant(
							    [[1_01, 75_92, 10_10, 20_03, 20_26, 38_99, 1_01_40, 10_29, 1_02]]		)  # [CLS] hello, is my dog cute? [SEP]
							__lowercase					     =				model(lowerCAmelCase__		)[0]  # embedding shape = (1, 768)
							# compare the actual values for a slice.
							__lowercase					     =				tf.constant(
							    [
							        [
							            0.0323_6253,
							            0.1275_3335,
							            0.1681_8509,
							            0.0027_9786,
							            0.389_6933,
							            0.2426_4945,
							            0.217_8971,
							            -0.0233_5227,
							            -0.0848_1959,
							            -0.1432_4117,
							        ]
							    ]		)
							self.assertTrue(numpy.allclose(output[:, :10].numpy() ,  expected_slice.numpy() ,  atol=1E-4		)		)
import sys
import webbrowser

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
		print("""Googling.....""")
		__a    :	Tuple         =    """https://www.google.com/search?q=""" + """ """.join(sys.argv[1:])
		__a    :	List[str]         =    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(1_0_0_0_0):
						out_file.write(data)
		__a    :	Dict         =    BeautifulSoup(res.text, """html.parser""")
		__a    :	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")}''')