




import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import EsmForMaskedLM, EsmForSequenceClassification, EsmForTokenClassification, EsmModel
			from transformers.models.esm.modeling_esm import (
			    ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
			    EsmEmbeddings,
			    create_position_ids_from_input_ids,
			)






class  __magic_name__						:
				'''simple docstring'''







				def __init__(							self:   Optional[Any]		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Tuple=13		,					_lowerCamelCase:   int=7		,					_lowerCamelCase:   Any=False		,					_lowerCamelCase:   Optional[Any]=True		,					_lowerCamelCase:   List[Any]=False		,					_lowerCamelCase:   Tuple=True		,					_lowerCamelCase:   List[Any]=33		,					_lowerCamelCase:   Any=32		,					_lowerCamelCase:   List[Any]=5		,					_lowerCamelCase:   Any=4		,					_lowerCamelCase:   Optional[Any]=37		,					_lowerCamelCase:   Dict="gelu"		,					_lowerCamelCase:   Tuple=0.1		,					_lowerCamelCase:   Union[str, Any]=0.1		,					_lowerCamelCase:   Optional[int]=5_12		,					_lowerCamelCase:   Tuple=16		,					_lowerCamelCase:   str=2		,					_lowerCamelCase:   Tuple=0.02		,					_lowerCamelCase:   List[Any]=3		,					_lowerCamelCase:   Optional[int]=4		,					_lowerCamelCase:   List[str]=None		,					):
											SCREAMING_SNAKE_CASE_   	=    parent
											SCREAMING_SNAKE_CASE_   	=    batch_size
											SCREAMING_SNAKE_CASE_   	=    seq_length
											SCREAMING_SNAKE_CASE_   	=    is_training
											SCREAMING_SNAKE_CASE_   	=    use_input_mask
											SCREAMING_SNAKE_CASE_   	=    use_token_type_ids
											SCREAMING_SNAKE_CASE_   	=    use_labels
											SCREAMING_SNAKE_CASE_   	=    vocab_size
											SCREAMING_SNAKE_CASE_   	=    hidden_size
											SCREAMING_SNAKE_CASE_   	=    num_hidden_layers
											SCREAMING_SNAKE_CASE_   	=    num_attention_heads
											SCREAMING_SNAKE_CASE_   	=    intermediate_size
											SCREAMING_SNAKE_CASE_   	=    hidden_act
											SCREAMING_SNAKE_CASE_   	=    hidden_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    attention_probs_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    max_position_embeddings
											SCREAMING_SNAKE_CASE_   	=    type_vocab_size
											SCREAMING_SNAKE_CASE_   	=    type_sequence_label_size
											SCREAMING_SNAKE_CASE_   	=    initializer_range
											SCREAMING_SNAKE_CASE_   	=    num_labels
											SCREAMING_SNAKE_CASE_   	=    num_choices
											SCREAMING_SNAKE_CASE_   	=    scope


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    ids_tensor([self.batch_size, self.seq_length]		,					self.vocab_size		)

											SCREAMING_SNAKE_CASE_   	=    None
											if self.use_input_mask:
																		SCREAMING_SNAKE_CASE_   	=    random_attention_mask([self.batch_size, self.seq_length]		)

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

											SCREAMING_SNAKE_CASE_   	=    self.get_config()

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


				def     _A							(							self:   Optional[Any]		):
											return EsmConfig(
											    vocab_size=self.vocab_size		,					hidden_size=self.hidden_size		,					pad_token_id=1		,					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		,					initializer_range=self.initializer_range		,					)


				def     _A							(							self:   Any		,					_lowerCamelCase:   int		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Any		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Optional[int]		,					_lowerCamelCase:   List[Any]		):
											SCREAMING_SNAKE_CASE_   	=    EsmModel(config=__lowerCamelCase		)
											model.to(__lowerCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(__lowerCamelCase		,					attention_mask=__lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    model(__lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    model(__lowerCamelCase		)

											self.parent.assertEqual(result.last_hidden_state.shape		,					(self.batch_size, self.seq_length, self.hidden_size)		)
											self.parent.assertEqual(result.pooler_output.shape		,					(self.batch_size, self.hidden_size)		)


				def     _A							(							self:   List[str]		,					_lowerCamelCase:   Optional[Any]		,					_lowerCamelCase:   List[Any]		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Any		,					_lowerCamelCase:   int		,					_lowerCamelCase:   List[Any]		):
											SCREAMING_SNAKE_CASE_   	=    EsmForMaskedLM(config=__lowerCamelCase		)
											model.to(__lowerCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(__lowerCamelCase		,					attention_mask=__lowerCamelCase		,					labels=__lowerCamelCase		)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.vocab_size)		)


				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   Optional[int]		,					_lowerCamelCase:   str		,					_lowerCamelCase:   Optional[Any]		,					_lowerCamelCase:   Tuple		,					_lowerCamelCase:   Optional[Any]		,					_lowerCamelCase:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.num_labels
											SCREAMING_SNAKE_CASE_   	=    EsmForTokenClassification(config=__lowerCamelCase		)
											model.to(__lowerCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(__lowerCamelCase		,					attention_mask=__lowerCamelCase		,					labels=__lowerCamelCase		)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.num_labels)		)





				def     _A							(							self:   Optional[int]		):
											SCREAMING_SNAKE_CASE_   	=    self.prepare_config_and_inputs()
											(
											    SCREAMING_SNAKE_CASE_     
											)   	=    config_and_inputs
											SCREAMING_SNAKE_CASE_   	=    {"input_ids": input_ids, "attention_mask": input_mask}
											return config, inputs_dict






@require_torch
class  __magic_name__						(  lowercase__    ,  lowercase__    ,  unittest.TestCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Optional[int]	      =					False

				SCREAMING_SNAKE_CASE__					:							Dict	      =					(
				    (
				        EsmForMaskedLM,
				        EsmModel,
				        EsmForSequenceClassification,
				        EsmForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE__					:							Optional[int]	      =					()
				SCREAMING_SNAKE_CASE__					:							Optional[int]	      =					(
				    {
				        "feature-extraction": EsmModel,
				        "fill-mask": EsmForMaskedLM,
				        "text-classification": EsmForSequenceClassification,
				        "token-classification": EsmForTokenClassification,
				        "zero-shot": EsmForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				SCREAMING_SNAKE_CASE__					:							int	      =					True


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    EsmModelTester(self		)
											SCREAMING_SNAKE_CASE_   	=    ConfigTester(self		,					config_class=__lowerCamelCase		,					hidden_size=37		)


				def     _A							(							self:   Tuple		):
											self.config_tester.run_common_tests()


				def     _A							(							self:   Dict		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__lowerCamelCase		)


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											for type in ["absolute", "relative_key", "relative_key_query"]:
																		SCREAMING_SNAKE_CASE_   	=    type
																		self.model_tester.create_and_check_model(*__lowerCamelCase		)


				def     _A							(							self:   str		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase		)


				def     _A							(							self:   List[Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase		)


				@slow
				def     _A							(							self:   List[Any]		):



											for model_name in ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		SCREAMING_SNAKE_CASE_   	=    EsmModel.from_pretrained(__lowerCamelCase		)
																		self.assertIsNotNone(__lowerCamelCase		)


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()[0]
											SCREAMING_SNAKE_CASE_   	=    EsmEmbeddings(config=__lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    torch.as_tensor([[12, 31, 13, model.padding_idx]]		)
											SCREAMING_SNAKE_CASE_   	=    torch.as_tensor(
											    [
											        [
											            0 + model.padding_idx + 1,
											            1 + model.padding_idx + 1,
											            2 + model.padding_idx + 1,
											            model.padding_idx,
											        ]
											    ]		)
											SCREAMING_SNAKE_CASE_   	=    create_position_ids_from_input_ids(__lowerCamelCase		,					model.padding_idx		)
											self.assertEqual(position_ids.shape		,					expected_positions.shape		)
											self.assertTrue(torch.all(torch.eq(__lowerCamelCase		,					__lowerCamelCase		)		)		)


				def     _A							(							self:   Optional[Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()[0]
											SCREAMING_SNAKE_CASE_   	=    EsmEmbeddings(config=__lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    torch.empty(2		,					4		,					30		)
											SCREAMING_SNAKE_CASE_   	=    [
											    0 + embeddings.padding_idx + 1,
											    1 + embeddings.padding_idx + 1,
											    2 + embeddings.padding_idx + 1,
											    3 + embeddings.padding_idx + 1,
											]
											SCREAMING_SNAKE_CASE_   	=    torch.as_tensor([expected_single_positions, expected_single_positions]		)
											SCREAMING_SNAKE_CASE_   	=    embeddings.create_position_ids_from_inputs_embeds(__lowerCamelCase		)
											self.assertEqual(position_ids.shape		,					expected_positions.shape		)
											self.assertTrue(torch.all(torch.eq(__lowerCamelCase		,					__lowerCamelCase		)		)		)


				@unittest.skip('''Esm does not support embedding resizing'''		)
				def     _A							(							self:   Union[str, Any]		):
											pass


				@unittest.skip('''Esm does not support embedding resizing'''		)
				def     _A							(							self:   List[Any]		):
											pass





				@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''		)
				def     _A							(							self:   Tuple		):
											pass






@require_torch
class  __magic_name__						(  lowercase__):
				'''simple docstring'''







				@slow
				def     _A							(							self:   List[str]		):



											with torch.no_grad():
																		SCREAMING_SNAKE_CASE_   	=    EsmForMaskedLM.from_pretrained('''facebook/esm2_t6_8M_UR50D'''		)
																		model.eval()
																		SCREAMING_SNAKE_CASE_   	=    torch.tensor([[0, 1, 2, 3, 4, 5]]		)
																		SCREAMING_SNAKE_CASE_   	=    model(__lowerCamelCase		)[0]

																		SCREAMING_SNAKE_CASE_   	=    33

																		SCREAMING_SNAKE_CASE_   	=    torch.Size((1, 6, vocab_size)		)
																		self.assertEqual(output.shape		,					__lowerCamelCase		)

																		SCREAMING_SNAKE_CASE_   	=    torch.tensor(
																		    [[[8.92_15, -10.58_98, -6.46_71], [-6.39_67, -13.91_14, -1.12_12], [-7.78_12, -13.95_16, -3.74_06]]]		)
																		self.assertTrue(torch.allclose(output[:, :3, :3]		,					__lowerCamelCase		,					atol=1E-4		)		)





				@slow
				def     _A							(							self:   Optional[Any]		):



											with torch.no_grad():
																		SCREAMING_SNAKE_CASE_   	=    EsmModel.from_pretrained('''facebook/esm2_t6_8M_UR50D'''		)
																		model.eval()

																		SCREAMING_SNAKE_CASE_   	=    torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]		)
																		SCREAMING_SNAKE_CASE_   	=    model(__lowerCamelCase		)[0]
																		# compare the actual values for a slice.
																		SCREAMING_SNAKE_CASE_   	=    torch.tensor(
																		    [[[0.14_44, 0.54_13, 0.32_48], [0.30_34, 0.00_53, 0.31_08], [0.32_28, -0.24_99, 0.34_15]]]		)
																		self.assertTrue(torch.allclose(output[:, :3, :3]		,					__lowerCamelCase		,					atol=1E-4		)		)












import webbrowser
from sys import argv
from urllib.parse import parse_qs, quote

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
			__SCREAMING_SNAKE_CASE 						="""%20""".join(argv[1:]) if len(argv) > 1 else quote(str(input("""Search: """)))

			print("""Googling.....""")

			__SCREAMING_SNAKE_CASE 						=f"""https://www.google.com/search?q={query}&num=100"""

			__SCREAMING_SNAKE_CASE 						=requests.get(
			    url,
			    headers={"""User-Agent""": str(UserAgent().random)},
			)

			try:
						__SCREAMING_SNAKE_CASE 						=(
						    BeautifulSoup(res.text, """html.parser""")
						    .find("""div""", attrs={"""class""": """yuRUbf"""})
						    .find("""a""")
						    .get("""href""")
						)

			except AttributeError:
						__SCREAMING_SNAKE_CASE 						=parse_qs(
						    BeautifulSoup(res.text, """html.parser""")
						    .find("""div""", attrs={"""class""": """kCrYT"""})
						    .find("""a""")
						    .get("""href""")
						)["""url"""][0]

			webbrowser.open(link)


