



from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch


@require_torch
@require_tf
class      __lowerCAmelCase     (		__lowercase      ):
					"""simple docstring"""






					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								A__       =    SMALL_MODEL_IDENTIFIER
								A__       =    'pt'
								A__       =    'tf'



					def     _a							(     self					:       Any				,					_snake_case					:       Tuple					):






								"""simple docstring"""


								A__       =    AutoModel.from_pretrained(self.test_model					)
								model_pt.save_pretrained(_A					)



					def     _a							(     self					:       Any				,					_snake_case					:       Union[str, Any]					):






								"""simple docstring"""


								A__       =    TFAutoModel.from_pretrained(self.test_model				,					from_pt=_A					)
								model_tf.save_pretrained(_A					)



					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								A__       =    'mock_framework'

								# Framework provided - return whatever the user provides
								A__       =    FeaturesManager.determine_framework(self.test_model				,					_A					)
								self.assertEqual(_A				,					_A					)

								# Local checkpoint and framework provided - return provided framework
								# PyTorch checkpoint
								with TemporaryDirectory() as local_pt_ckpt:
											self._setup_pt_ckpt(_A					)
											A__       =    FeaturesManager.determine_framework(_A				,					_A					)
											self.assertEqual(_A				,					_A					)

								# TensorFlow checkpoint
								with TemporaryDirectory() as local_tf_ckpt:
											self._setup_tf_ckpt(_A					)
											A__       =    FeaturesManager.determine_framework(_A				,					_A					)
											self.assertEqual(_A				,					_A					)



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								with TemporaryDirectory() as local_pt_ckpt:
											self._setup_pt_ckpt(_A					)
											A__       =    FeaturesManager.determine_framework(_A					)
											self.assertEqual(_A				,					self.framework_pt					)

								# TensorFlow checkpoint
								with TemporaryDirectory() as local_tf_ckpt:
											self._setup_tf_ckpt(_A					)
											A__       =    FeaturesManager.determine_framework(_A					)
											self.assertEqual(_A				,					self.framework_tf					)

								# Invalid local checkpoint
								with TemporaryDirectory() as local_invalid_ckpt:
											with self.assertRaises(_A					):
														A__       =    FeaturesManager.determine_framework(_A					)



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






								"""simple docstring"""


								A__       =    MagicMock(return_value=_A					)
								with patch('transformers.onnx.features.is_tf_available'				,					_A					):
											A__       =    FeaturesManager.determine_framework(self.test_model					)
											self.assertEqual(_A				,					self.framework_pt					)

								# PyTorch not in environment -> use TensorFlow
								A__       =    MagicMock(return_value=_A					)
								with patch('transformers.onnx.features.is_torch_available'				,					_A					):
											A__       =    FeaturesManager.determine_framework(self.test_model					)
											self.assertEqual(_A				,					self.framework_tf					)

								# Both in environment -> use PyTorch
								A__       =    MagicMock(return_value=_A					)
								A__       =    MagicMock(return_value=_A					)
								with patch('transformers.onnx.features.is_tf_available'				,					_A					), patch(
								    'transformers.onnx.features.is_torch_available'				,					_A					):
											A__       =    FeaturesManager.determine_framework(self.test_model					)
											self.assertEqual(_A				,					self.framework_pt					)

								# Both not in environment -> raise error
								A__       =    MagicMock(return_value=_A					)
								A__       =    MagicMock(return_value=_A					)
								with patch('transformers.onnx.features.is_tf_available'				,					_A					), patch(
								    'transformers.onnx.features.is_torch_available'				,					_A					):
											with self.assertRaises(_A					):
														A__       =    FeaturesManager.determine_framework(self.test_model					)











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)




