


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    UpperCAmelCase_	:
       '''simple docstring'''






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




              """simple docstring"""




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

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






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	str   	=		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

              UpperCamelCase    :	Optional[Any]   	=		None
              if self.use_labels:
                     UpperCamelCase    :	Union[str, Any]   	=		ids_tensor([self.batch_size] ,					self.type_sequence_label_size						)

              UpperCamelCase    :	Union[str, Any]   	=		self.get_config()

              return config, pixel_values, labels






       def  _lowercase   (     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=__SCREAMING_SNAKE_CASE ,					initializer_range=self.initializer_range ,					)






       def  _lowercase   (     self ,					__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              UpperCamelCase    :	Dict   	=		TFViTModel(config=__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	List[str]   	=		model(__SCREAMING_SNAKE_CASE ,					training=__SCREAMING_SNAKE_CASE						)
              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.
              UpperCamelCase    :	Any   	=		self.image_size // 2
              UpperCamelCase    :	Any   	=		pixel_values[:, :, :image_size, :image_size]
              UpperCamelCase    :	Union[str, Any]   	=		model(__SCREAMING_SNAKE_CASE ,					interpolate_pos_encoding=__SCREAMING_SNAKE_CASE ,					training=__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	Any   	=		(image_size // self.patch_size) ** 2 + 1
              self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, seq_length, self.hidden_size)						)






       def  _lowercase   (     self ,					__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              UpperCamelCase    :	int   	=		self.type_sequence_label_size
              UpperCamelCase    :	List[str]   	=		TFViTForImageClassification(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	Tuple   	=		model(__SCREAMING_SNAKE_CASE ,					labels=__SCREAMING_SNAKE_CASE ,					training=__SCREAMING_SNAKE_CASE						)
              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.
              UpperCamelCase    :	Any   	=		self.image_size // 2
              UpperCamelCase    :	Tuple   	=		pixel_values[:, :, :image_size, :image_size]
              UpperCamelCase    :	Optional[Any]   	=		model(__SCREAMING_SNAKE_CASE ,					interpolate_pos_encoding=__SCREAMING_SNAKE_CASE ,					training=__SCREAMING_SNAKE_CASE						)
              self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.type_sequence_label_size)						)

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






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	List[Any]   	=		self.prepare_config_and_inputs()
              UpperCamelCase	, UpperCamelCase	, UpperCamelCase    :	List[str]   	=		config_and_inputs
              UpperCamelCase    :	Union[str, Any]   	=		{'''pixel_values''': pixel_values}
              return config, inputs_dict




@require_tf
class    UpperCAmelCase_	(							_a,     _a,     unittest.TestCase):
       '''simple docstring'''
       __UpperCamelCase      :     Optional[int]							=					(TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
       __UpperCamelCase      :     Optional[int]							=					(
           {"feature-extraction": TFViTModel, "image-classification": TFViTForImageClassification}
           if is_tf_available()
           else {}
       )

       __UpperCamelCase      :     int							=					False
       __UpperCamelCase      :     Dict							=					False
       __UpperCamelCase      :     Tuple							=					False






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Optional[Any]   	=		TFViTModelTester(self						)
              UpperCamelCase    :	Any   	=		ConfigTester(self ,					config_class=__SCREAMING_SNAKE_CASE ,					has_text_modality=__SCREAMING_SNAKE_CASE ,					hidden_size=37						)






       def  _lowercase   (     self						):




              """simple docstring"""




              self.config_tester.run_common_tests()






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




              """simple docstring"""




              pass






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




              """simple docstring"""




              pass






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase	, UpperCamelCase    :	Any   	=		self.model_tester.prepare_config_and_inputs_for_common()

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






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase	, UpperCamelCase    :	Tuple   	=		self.model_tester.prepare_config_and_inputs_for_common()

              for model_class in self.all_model_classes:
                     UpperCamelCase    :	Optional[Any]   	=		model_class(__SCREAMING_SNAKE_CASE						)
                     UpperCamelCase    :	Dict   	=		inspect.signature(model.call						)
                     # signature.parameters is an OrderedDict => so arg_names order is deterministic
                     UpperCamelCase    :	Any   	=		[*signature.parameters.keys()]

                     UpperCamelCase    :	Optional[int]   	=		['''pixel_values''']
                     self.assertListEqual(arg_names[:1] ,					__SCREAMING_SNAKE_CASE						)






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	List[str]   	=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE						)






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	str   	=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_image_classification(*__SCREAMING_SNAKE_CASE						)






       @slow
       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	List[Any]   	=		TFViTModel.from_pretrained('''google/vit-base-patch16-224'''						)
              self.assertIsNotNone(__SCREAMING_SNAKE_CASE						)




def      a	(							):






       """simple docstring"""





       UpperCamelCase    :	Union[str, Any]   	=		Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''       )
       return image



@require_tf
@require_vision
class    UpperCAmelCase_	(							unittest.TestCase):
       '''simple docstring'''






       @cached_property
       def  _lowercase   (     self						):




              """simple docstring"""




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






       @slow
       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Tuple   	=		TFViTForImageClassification.from_pretrained('''google/vit-base-patch16-224'''						)

              UpperCamelCase    :	Any   	=		self.default_image_processor
              UpperCamelCase    :	str   	=		prepare_img()
              UpperCamelCase    :	Any   	=		image_processor(images=__SCREAMING_SNAKE_CASE ,					return_tensors='''tf'''						)

              # forward pass
              UpperCamelCase    :	List[Any]   	=		model(**__SCREAMING_SNAKE_CASE						)

              # verify the logits
              UpperCamelCase    :	Tuple   	=		tf.TensorShape((1, 1_000)						)
              self.assertEqual(outputs.logits.shape ,					__SCREAMING_SNAKE_CASE						)

              UpperCamelCase    :	Optional[Any]   	=		tf.constant([-0.2_744, 0.8_215, -0.0_836]						)

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





import requests
from bsa import BeautifulSoup


def      a	(							SCREAMING_SNAKE_CASE_      :		str = "AAPL"       ):






       """simple docstring"""





       UpperCamelCase    :	Dict   	=		F"""https://in.finance.yahoo.com/quote/{symbol}?s={symbol}"""
       UpperCamelCase    :	Any   	=		BeautifulSoup(requests.get(SCREAMING_SNAKE_CASE_       ).text							,			'''html.parser'''       )
       UpperCamelCase    :	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}''')

