
'''simple docstring'''






from __future__ import annotations

import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
					import tensorflow as tf

					from transformers import TFViTForImageClassification, TFViTModel


if is_vision_available():
					from PIL import Image

					from transformers import ViTImageProcessor




class     __snake_case		:
					def __init__(     self,    A,    A=13,    A=30,    A=2,    A=3,    A=True,    A=True,    A=32,    A=2,    A=4,    A=37,    A="gelu",    A=0.1,    A=0.1,    A=10,    A=0.02,    A=3,    A=None,    ):

									"""simple docstring"""


									lowerCamelCase					:			Any									= parent
									lowerCamelCase					:			Dict									= batch_size
									lowerCamelCase					:			Union[str, Any]									= image_size
									lowerCamelCase					:			Optional[Any]									= patch_size
									lowerCamelCase					:			Dict									= num_channels
									lowerCamelCase					:			Dict									= is_training
									lowerCamelCase					:			List[Any]									= use_labels
									lowerCamelCase					:			Dict									= hidden_size
									lowerCamelCase					:			List[Any]									= num_hidden_layers
									lowerCamelCase					:			Tuple									= num_attention_heads
									lowerCamelCase					:			str									= intermediate_size
									lowerCamelCase					:			List[str]									= hidden_act
									lowerCamelCase					:			str									= hidden_dropout_prob
									lowerCamelCase					:			str									= attention_probs_dropout_prob
									lowerCamelCase					:			Optional[int]									= type_sequence_label_size
									lowerCamelCase					:			Any									= initializer_range
									lowerCamelCase					:			Optional[int]									= scope

									# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
									lowerCamelCase					:			List[Any]									= (image_size // patch_size) ** 2
									lowerCamelCase					:			Optional[int]									= num_patches + 1
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

									lowerCamelCase					:			Any									= None
									if self.use_labels:
													lowerCamelCase					:			List[Any]									= ids_tensor([self.batch_size],    self.type_sequence_label_size      )

									lowerCamelCase					:			Optional[int]									= self.get_config()

									return config, pixel_values, labels
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return ViTConfig(
									    image_size=self.image_size,    patch_size=self.patch_size,    num_channels=self.num_channels,    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,    is_decoder=A,    initializer_range=self.initializer_range,    )
					def     UpperCAmelCase_							(     self,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			List[str]									= TFViTModel(config=A      )
									lowerCamelCase					:			Tuple									= model(A,    training=A      )
									self.parent.assertEqual(result.last_hidden_state.shape,    (self.batch_size, self.seq_length, self.hidden_size)      )

									# Test with an image with different size than the one specified in config.
									lowerCamelCase					:			Optional[Any]									= self.image_size // 2
									lowerCamelCase					:			List[Any]									= pixel_values[:, :, :image_size, :image_size]
									lowerCamelCase					:			Any									= model(A,    interpolate_pos_encoding=A,    training=A      )
									lowerCamelCase					:			List[str]									= (image_size // self.patch_size) ** 2 + 1
									self.parent.assertEqual(result.last_hidden_state.shape,    (self.batch_size, seq_length, self.hidden_size)      )
					def     UpperCAmelCase_							(     self,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= self.type_sequence_label_size
									lowerCamelCase					:			List[Any]									= TFViTForImageClassification(A      )
									lowerCamelCase					:			int									= model(A,    labels=A,    training=A      )
									self.parent.assertEqual(result.logits.shape,    (self.batch_size, self.type_sequence_label_size)      )

									# Test with an image with different size than the one specified in config.
									lowerCamelCase					:			Optional[int]									= self.image_size // 2
									lowerCamelCase					:			Optional[Any]									= pixel_values[:, :, :image_size, :image_size]
									lowerCamelCase					:			int									= model(A,    interpolate_pos_encoding=A,    training=A      )
									self.parent.assertEqual(result.logits.shape,    (self.batch_size, self.type_sequence_label_size)      )

									# test greyscale images
									lowerCamelCase					:			List[str]									= 1
									lowerCamelCase					:			int									= TFViTForImageClassification(A      )
									lowerCamelCase					:			List[Any]									= floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
									lowerCamelCase					:			Optional[int]									= model(A      )
									self.parent.assertEqual(result.logits.shape,    (self.batch_size, self.type_sequence_label_size)      )




					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= self.prepare_config_and_inputs()
									lowerCamelCase			, lowerCamelCase			, lowerCamelCase					:			List[Any]									= config_and_inputs
									lowerCamelCase					:			Tuple									= {'pixel_values': pixel_values}
									return config, inputs_dict





@require_tf
class     __snake_case		(   a__    ,   a__    ,   unittest.TestCase):
					_lowerCAmelCase			     =	(TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
					_lowerCAmelCase			     =	(
					    {'''feature-extraction''': TFViTModel, '''image-classification''': TFViTForImageClassification}
					    if is_tf_available()
					    else {}
					)

					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			List[str]									= TFViTModelTester(self      )
									lowerCamelCase					:			Optional[int]									= ConfigTester(self,    config_class=A,    has_text_modality=A,    hidden_size=37      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									self.config_tester.run_common_tests()
					@unittest.skip(reason='ViT does not use inputs_embeds'      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									pass
					@unittest.skip(reason='ViT does not use inputs_embeds'      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									pass
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase			, lowerCamelCase					:			str									= self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													lowerCamelCase					:			Optional[Any]									= model_class(A      )
													self.assertIsInstance(model.get_input_embeddings(),    (tf.keras.layers.Layer)      )
													lowerCamelCase					:			List[Any]									= model.get_output_embeddings()
													self.assertTrue(x is None or isinstance(A,    tf.keras.layers.Layer      )      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase			, lowerCamelCase					:			int									= self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													lowerCamelCase					:			Optional[int]									= model_class(A      )
													lowerCamelCase					:			str									= inspect.signature(model.call      )
													# signature.parameters is an OrderedDict => so arg_names order is deterministic
													lowerCamelCase					:			Optional[int]									= [*signature.parameters.keys()]

													lowerCamelCase					:			Tuple									= ['pixel_values']
													self.assertListEqual(arg_names[:1],    A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*A      )




					@slow
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= TFViTModel.from_pretrained('google/vit-base-patch16-224'      )
									self.assertIsNotNone(A      )





def    UpperCAmelCase							(  ):
				lowerCamelCase					:			Tuple									= Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
				return image




@require_tf
@require_vision
class     __snake_case		(   unittest.TestCase):
					@cached_property
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return ViTImageProcessor.from_pretrained('google/vit-base-patch16-224'      ) if is_vision_available() else None




					@slow
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			str									= TFViTForImageClassification.from_pretrained('google/vit-base-patch16-224'      )

									lowerCamelCase					:			List[Any]									= self.default_image_processor
									lowerCamelCase					:			Tuple									= prepare_img()
									lowerCamelCase					:			Optional[int]									= image_processor(images=A,    return_tensors='tf'      )

									# forward pass
									lowerCamelCase					:			List[Any]									= model(**A      )

									# verify the logits
									lowerCamelCase					:			List[str]									= tf.TensorShape((1, 1000)      )
									self.assertEqual(outputs.logits.shape,    A      )

									lowerCamelCase					:			List[Any]									= tf.constant([-0.2744, 0.8215, -0.0836]      )

									tf.debugging.assert_near(outputs.logits[0, :3],    A,    atol=1e-4      )


'''simple docstring'''






import requests
from bsa import BeautifulSoup





def    UpperCAmelCase							(  UpperCAmelCase__							:							str = "AAPL"):
				lowerCamelCase					:			List[Any]									= F'''https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'''
				lowerCamelCase					:			Dict									= BeautifulSoup(requests.get(UpperCAmelCase__).text       ,							'html.parser')
				lowerCamelCase					:			Dict									= 'My(6px) Pos(r) smartphone_Mt(6px)'
				return soup.find('div'       ,							class_=class_).find('span').text


if __name__ == "__main__":
					for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
										print(f"""Current {symbol:<4} stock price is {stock_price(symbol):>8}""")
