





import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
		from PIL import Image

		from transformers import AutoProcessor, BertTokenizer, BlipImageProcessor, BlipProcessor, PreTrainedTokenizerFast


@require_vision
class 						lowerCamelCase       (unittest.TestCase      ):







							"""simple docstring"""




							def  A_     ( self     :					List[Any]						)				->			str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						tempfile.mkdtemp()

														SCREAMING_SNAKE_CASE__       :      Dict     =						BlipImageProcessor()
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						BertTokenizer.from_pretrained("hf-internal-testing/tiny-random-BertModel"						)

														SCREAMING_SNAKE_CASE__       :      Tuple     =						BlipProcessor(_UpperCAmelCase,			_UpperCAmelCase						)

														processor.save_pretrained(self.tmpdirname						)






							def  A_     ( self     :					List[str],			**_UpperCAmelCase     :					int						)				->			Union[str, Any]:





														"""simple docstring"""
														return AutoProcessor.from_pretrained(self.tmpdirname,			**_UpperCAmelCase						).tokenizer






							def  A_     ( self     :					Optional[int],			**_UpperCAmelCase     :					Any						)				->			Union[str, Any]:





														"""simple docstring"""
														return AutoProcessor.from_pretrained(self.tmpdirname,			**_UpperCAmelCase						).image_processor






							def  A_     ( self     :					Optional[Any]						)				->			Dict:





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






							def  A_     ( self     :					List[Any]						)				->			Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Any     =						[np.random.randint(2_5_5,			size=(3, 3_0, 4_0_0),			dtype=np.uinta						)]

														SCREAMING_SNAKE_CASE__       :      Tuple     =						[Image.fromarray(np.moveaxis(_UpperCAmelCase,			0,			-1						)						) for x in image_inputs]

														return image_inputs






							def  A_     ( self     :					List[Any]						)				->			str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						BlipProcessor(tokenizer=self.get_tokenizer(),			image_processor=self.get_image_processor()						)
														processor.save_pretrained(self.tmpdirname						)

														SCREAMING_SNAKE_CASE__       :      Dict     =						self.get_tokenizer(bos_token="(BOS)",			eos_token="(EOS)"						)
														SCREAMING_SNAKE_CASE__       :      int     =						self.get_image_processor(do_normalize=_UpperCAmelCase,			padding_value=1.0						)

														SCREAMING_SNAKE_CASE__       :      str     =						BlipProcessor.from_pretrained(
														    self.tmpdirname,			bos_token="(BOS)",			eos_token="(EOS)",			do_normalize=_UpperCAmelCase,			padding_value=1.0						)

														self.assertEqual(processor.tokenizer.get_vocab(),			tokenizer_add_kwargs.get_vocab()						)
														self.assertIsInstance(processor.tokenizer,			_UpperCAmelCase						)

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






							def  A_     ( self     :					Optional[Any]						)				->			Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      int     =						self.get_image_processor()
														SCREAMING_SNAKE_CASE__       :      int     =						self.get_tokenizer()

														SCREAMING_SNAKE_CASE__       :      Dict     =						BlipProcessor(tokenizer=_UpperCAmelCase,			image_processor=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.prepare_image_inputs()

														SCREAMING_SNAKE_CASE__       :      Any     =						image_processor(_UpperCAmelCase,			return_tensors="np"						)
														SCREAMING_SNAKE_CASE__       :      int     =						processor(images=_UpperCAmelCase,			return_tensors="np"						)

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






							def  A_     ( self     :					Optional[Any]						)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      str     =						self.get_image_processor()
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						self.get_tokenizer()

														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						BlipProcessor(tokenizer=_UpperCAmelCase,			image_processor=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Any     =						"lower newer"

														SCREAMING_SNAKE_CASE__       :      Tuple     =						processor(text=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						tokenizer(_UpperCAmelCase,			return_token_type_ids=_UpperCAmelCase						)

														for key in encoded_tok.keys():
																					self.assertListEqual(encoded_tok[key],			encoded_processor[key]						)






							def  A_     ( self     :					Optional[int]						)				->			Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						self.get_image_processor()
														SCREAMING_SNAKE_CASE__       :      Any     =						self.get_tokenizer()

														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						BlipProcessor(tokenizer=_UpperCAmelCase,			image_processor=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      str     =						"lower newer"
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						self.prepare_image_inputs()

														SCREAMING_SNAKE_CASE__       :      Any     =						processor(text=_UpperCAmelCase,			images=_UpperCAmelCase						)

														self.assertListEqual(list(inputs.keys()						),			["pixel_values", "input_ids", "attention_mask"]						)

														# test if it raises when no input is passed
														with pytest.raises(_UpperCAmelCase						):
																					processor()






							def  A_     ( self     :					List[Any]						)				->			Optional[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						self.get_image_processor()
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						self.get_tokenizer()

														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						BlipProcessor(tokenizer=_UpperCAmelCase,			image_processor=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

														SCREAMING_SNAKE_CASE__       :      Any     =						processor.batch_decode(_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						tokenizer.batch_decode(_UpperCAmelCase						)

														self.assertListEqual(_UpperCAmelCase,			_UpperCAmelCase						)






							def  A_     ( self     :					Any						)				->			str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[str]     =						self.get_image_processor()
														SCREAMING_SNAKE_CASE__       :      List[str]     =						self.get_tokenizer()

														SCREAMING_SNAKE_CASE__       :      str     =						BlipProcessor(tokenizer=_UpperCAmelCase,			image_processor=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Tuple     =						"lower newer"
														SCREAMING_SNAKE_CASE__       :      Tuple     =						self.prepare_image_inputs()

														SCREAMING_SNAKE_CASE__       :      List[str]     =						processor(text=_UpperCAmelCase,			images=_UpperCAmelCase						)

														# For now the processor supports only ['pixel_values', 'input_ids', 'attention_mask']
														self.assertListEqual(list(inputs.keys()						),			["pixel_values", "input_ids", "attention_mask"]						)













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__":
		_lowerCamelCase :    Union[str, Any]  							= '''%20'''.join(argv[1:]) if len(argv) > 1 else quote(str(input('''Search: ''')))

		print('''Googling.....''')

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

		_lowerCamelCase :    Optional[Any]  							= requests.get(
		    url,
		    headers={'''User-Agent''': str(UserAgent().random)},
		)

		try:
				_lowerCamelCase :    Union[str, Any]  							= (
				    BeautifulSoup(res.text, '''html.parser''')
				    .find('''div''', attrs={'''class''': '''yuRUbf'''})
				    .find('''a''')
				    .get('''href''')
				)

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

		webbrowser.open(link)






