


'''simple docstring'''
import inspect
import unittest

from transformers import MobileViTConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
		import torch

		from transformers import MobileViTForImageClassification, MobileViTForSemanticSegmentation, MobileViTModel
		from transformers.models.mobilevit.modeling_mobilevit import MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import MobileViTImageProcessor
class   lowercase      (				A__   ):

		"""simple docstring"""

		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :List[str]				   =					self.config_class(**self.inputs_dict				)
							self.parent.assertTrue(hasattr(UpperCamelCase_       ,  '''hidden_sizes'''				)				)
							self.parent.assertTrue(hasattr(UpperCamelCase_       ,  '''neck_hidden_sizes'''				)				)
							self.parent.assertTrue(hasattr(UpperCamelCase_       ,  '''num_attention_heads'''				)				)



class   lowercase      :

		"""simple docstring"""

		def __init__(						self       ,  UpperCamelCase_       ,  UpperCamelCase_=13       ,  UpperCamelCase_=32       ,  UpperCamelCase_=2       ,  UpperCamelCase_=3       ,  UpperCamelCase_=640       ,  UpperCamelCase_=4       ,  UpperCamelCase_="silu"       ,  UpperCamelCase_=3       ,  UpperCamelCase_=32       ,  UpperCamelCase_=0.1       ,  UpperCamelCase_=0.1       ,  UpperCamelCase_=0.1       ,  UpperCamelCase_=0.02       ,  UpperCamelCase_=True       ,  UpperCamelCase_=True       ,  UpperCamelCase_=10       ,  UpperCamelCase_=None       ,  ):

							'''simple docstring'''


							UpperCamelCase__  :Union[str, Any]				   =					parent
							UpperCamelCase__  :List[Any]				   =					batch_size
							UpperCamelCase__  :Union[str, Any]				   =					image_size
							UpperCamelCase__  :Dict				   =					patch_size
							UpperCamelCase__  :str				   =					num_channels
							UpperCamelCase__  :List[Any]				   =					last_hidden_size
							UpperCamelCase__  :List[str]				   =					num_attention_heads
							UpperCamelCase__  :List[Any]				   =					hidden_act
							UpperCamelCase__  :int				   =					conv_kernel_size
							UpperCamelCase__  :Optional[int]				   =					output_stride
							UpperCamelCase__  :str				   =					hidden_dropout_prob
							UpperCamelCase__  :List[str]				   =					attention_probs_dropout_prob
							UpperCamelCase__  :Any				   =					classifier_dropout_prob
							UpperCamelCase__  :Union[str, Any]				   =					use_labels
							UpperCamelCase__  :Union[str, Any]				   =					is_training
							UpperCamelCase__  :List[str]				   =					num_labels
							UpperCamelCase__  :Optional[int]				   =					initializer_range
							UpperCamelCase__  :int				   =					scope




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Union[str, Any]				   =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

							UpperCamelCase__  :List[Any]				   =					None
							UpperCamelCase__  :Optional[Any]				   =					None
							if self.use_labels:
												UpperCamelCase__  :Union[str, Any]				   =					ids_tensor([self.batch_size]       ,  self.num_labels				)
												UpperCamelCase__  :Union[str, Any]				   =					ids_tensor([self.batch_size, self.image_size, self.image_size]       ,  self.num_labels				)

							UpperCamelCase__  :Dict				   =					self.get_config()

							return config, pixel_values, labels, pixel_labels




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							return MobileViTConfig(
							    image_size=self.image_size       ,  patch_size=self.patch_size       ,  num_channels=self.num_channels       ,  num_attention_heads=self.num_attention_heads       ,  hidden_act=self.hidden_act       ,  conv_kernel_size=self.conv_kernel_size       ,  output_stride=self.output_stride       ,  hidden_dropout_prob=self.hidden_dropout_prob       ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,  classifier_dropout_prob=self.classifier_dropout_prob       ,  initializer_range=self.initializer_range       ,  )




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							UpperCamelCase__  :List[Any]				   =					MobileViTModel(config=UpperCamelCase_				)
							model.to(UpperCamelCase_				)
							model.eval()
							UpperCamelCase__  :Optional[int]				   =					model(UpperCamelCase_				)
							self.parent.assertEqual(
							    result.last_hidden_state.shape       ,  (
							        self.batch_size,
							        self.last_hidden_size,
							        self.image_size // self.output_stride,
							        self.image_size // self.output_stride,
							    )       ,  )




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							UpperCamelCase__  :Any				   =					self.num_labels
							UpperCamelCase__  :Optional[Any]				   =					MobileViTForImageClassification(UpperCamelCase_				)
							model.to(UpperCamelCase_				)
							model.eval()
							UpperCamelCase__  :Dict				   =					model(UpperCamelCase_       ,  labels=UpperCamelCase_				)
							self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels)				)




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							UpperCamelCase__  :Any				   =					self.num_labels
							UpperCamelCase__  :Union[str, Any]				   =					MobileViTForSemanticSegmentation(UpperCamelCase_				)
							model.to(UpperCamelCase_				)
							model.eval()
							UpperCamelCase__  :List[Any]				   =					model(UpperCamelCase_				)
							self.parent.assertEqual(
							    result.logits.shape       ,  (
							        self.batch_size,
							        self.num_labels,
							        self.image_size // self.output_stride,
							        self.image_size // self.output_stride,
							    )       ,  )
							UpperCamelCase__  :Optional[Any]				   =					model(UpperCamelCase_       ,  labels=UpperCamelCase_				)
							self.parent.assertEqual(
							    result.logits.shape       ,  (
							        self.batch_size,
							        self.num_labels,
							        self.image_size // self.output_stride,
							        self.image_size // self.output_stride,
							    )       ,  )




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


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



@require_torch
class   lowercase      (				A__      ,						A__      ,						unittest.TestCase   ):

		"""simple docstring"""

		_a       					=							(
		    (MobileViTModel, MobileViTForImageClassification, MobileViTForSemanticSegmentation)
		    if is_torch_available()
		    else ()
		)
		_a       					=							(
		    {
		        'feature-extraction': MobileViTModel,
		        'image-classification': MobileViTForImageClassification,
		        'image-segmentation': MobileViTForSemanticSegmentation,
		    }
		    if is_torch_available()
		    else {}
		)

		_a       					=							False
		_a       					=							False
		_a       					=							False
		_a       					=							False




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :int				   =					MobileViTModelTester(self				)
							UpperCamelCase__  :Optional[int]				   =					MobileViTConfigTester(self       ,  config_class=UpperCamelCase_       ,  has_text_modality=UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							self.config_tester.run_common_tests()




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

							'''simple docstring'''


							pass




		@unittest.skip(reason='''MobileViT does not support input and output embeddings'''				)
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							pass




		@unittest.skip(reason='''MobileViT does not output attentions'''				)
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							pass




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__   ,							UpperCamelCase__  :List[str]				   =					self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__  :int				   =					model_class(UpperCamelCase_				)
												UpperCamelCase__  :Dict				   =					inspect.signature(model.forward				)
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												UpperCamelCase__  :Optional[int]				   =					[*signature.parameters.keys()]

												UpperCamelCase__  :Any				   =					['''pixel_values''']
												self.assertListEqual(arg_names[:1]       ,  UpperCamelCase_				)




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

							'''simple docstring'''


							pass




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[Any]				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							def check_hidden_states_output(UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):
												UpperCamelCase__  :List[str]				   =					model_class(UpperCamelCase_				)
												model.to(UpperCamelCase_				)
												model.eval()

												with torch.no_grad():
																	UpperCamelCase__  :Any				   =					model(**self._prepare_for_class(UpperCamelCase_       ,  UpperCamelCase_				)				)

												UpperCamelCase__  :Optional[Any]				   =					outputs.hidden_states

												UpperCamelCase__  :Tuple				   =					5
												self.assertEqual(len(UpperCamelCase_				)       ,  UpperCamelCase_				)

												# MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
												# with the width and height being successively divided by 2.
												UpperCamelCase__  :Union[str, Any]				   =					2
												for i in range(len(UpperCamelCase_				)				):
																	self.assertListEqual(
																	    list(hidden_states[i].shape[-2:]				)       ,  [self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]       ,  )
																	divisor *= 2

												self.assertEqual(self.model_tester.output_stride       ,  divisor // 2				)

							UpperCamelCase__   ,							UpperCamelCase__  :Dict				   =					self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__  :Dict				   =					True
												check_hidden_states_output(UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				)

												# check that output_hidden_states also work using config
												del inputs_dict["output_hidden_states"]
												UpperCamelCase__  :Dict				   =					True

												check_hidden_states_output(UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :List[str]				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*UpperCamelCase_				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :List[Any]				   =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_semantic_segmentation(*UpperCamelCase_				)




		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							for model_name in MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCamelCase__  :List[str]				   =					MobileViTModel.from_pretrained(UpperCamelCase_				)
												self.assertIsNotNone(UpperCamelCase_				)



def      a (     )    ->      List[str]:



					'''simple docstring'''






					UpperCamelCase__  :Optional[Any]				   =					Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  )
					return image







@require_torch
@require_vision
class   lowercase      (				unittest.TestCase   ):

		"""simple docstring"""

		@cached_property
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							return MobileViTImageProcessor.from_pretrained('''apple/mobilevit-xx-small'''				) if is_vision_available() else None




		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :List[Any]				   =					MobileViTForImageClassification.from_pretrained('''apple/mobilevit-xx-small'''				).to(UpperCamelCase_				)

							UpperCamelCase__  :Tuple				   =					self.default_image_processor
							UpperCamelCase__  :Any				   =					prepare_img()
							UpperCamelCase__  :Any				   =					image_processor(images=UpperCamelCase_       ,  return_tensors='''pt'''				).to(UpperCamelCase_				)

							# forward pass
							with torch.no_grad():
												UpperCamelCase__  :List[str]				   =					model(**UpperCamelCase_				)

							# verify the logits
							UpperCamelCase__  :Any				   =					torch.Size((1, 1000)				)
							self.assertEqual(outputs.logits.shape       ,  UpperCamelCase_				)

							UpperCamelCase__  :str				   =					torch.tensor([-1.9364, -1.2327, -0.4653]				).to(UpperCamelCase_				)

							self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,  UpperCamelCase_       ,  atol=1e-4				)				)




		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Any				   =					MobileViTForSemanticSegmentation.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''				)
							UpperCamelCase__  :Union[str, Any]				   =					model.to(UpperCamelCase_				)

							UpperCamelCase__  :str				   =					MobileViTImageProcessor.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''				)

							UpperCamelCase__  :Optional[Any]				   =					prepare_img()
							UpperCamelCase__  :List[str]				   =					image_processor(images=UpperCamelCase_       ,  return_tensors='''pt'''				).to(UpperCamelCase_				)

							# forward pass
							with torch.no_grad():
												UpperCamelCase__  :Optional[int]				   =					model(**UpperCamelCase_				)
							UpperCamelCase__  :List[Any]				   =					outputs.logits

							# verify the logits
							UpperCamelCase__  :int				   =					torch.Size((1, 21, 32, 32)				)
							self.assertEqual(logits.shape       ,  UpperCamelCase_				)

							UpperCamelCase__  :Tuple				   =					torch.tensor(
							    [
							        [[6.9713, 6.9786, 7.2422], [7.2893, 7.2825, 7.4446], [7.6580, 7.8797, 7.9420]],
							        [[-10.6869, -10.3250, -10.3471], [-10.4228, -9.9868, -9.7132], [-11.0405, -11.0221, -10.7318]],
							        [[-3.3089, -2.8539, -2.6740], [-3.2706, -2.5621, -2.5108], [-3.2534, -2.6615, -2.6651]],
							    ]       ,  device=UpperCamelCase_       ,  )

							self.assertTrue(torch.allclose(logits[0, :3, :3, :3]       ,  UpperCamelCase_       ,  atol=1e-4				)				)




		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Dict				   =					MobileViTForSemanticSegmentation.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''				)
							UpperCamelCase__  :List[Any]				   =					model.to(UpperCamelCase_				)

							UpperCamelCase__  :Optional[Any]				   =					MobileViTImageProcessor.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''				)

							UpperCamelCase__  :Dict				   =					prepare_img()
							UpperCamelCase__  :str				   =					image_processor(images=UpperCamelCase_       ,  return_tensors='''pt'''				).to(UpperCamelCase_				)

							# forward pass
							with torch.no_grad():
												UpperCamelCase__  :List[Any]				   =					model(**UpperCamelCase_				)

							UpperCamelCase__  :str				   =					outputs.logits.detach().cpu()

							UpperCamelCase__  :Any				   =					image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase_       ,  target_sizes=[(50, 60)]				)
							UpperCamelCase__  :int				   =					torch.Size((50, 60)				)
							self.assertEqual(segmentation[0].shape       ,  UpperCamelCase_				)

							UpperCamelCase__  :str				   =					image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase_				)
							UpperCamelCase__  :int				   =					torch.Size((32, 32)				)
							self.assertEqual(segmentation[0].shape       ,  UpperCamelCase_				)



'''simple docstring'''
import requests
from bsa import BeautifulSoup


def      a (     __a = "AAPL"  )    ->      str:



					'''simple docstring'''






					UpperCamelCase__  :str				   =					f'''https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'''
					UpperCamelCase__  :Tuple				   =					BeautifulSoup(requests.get(__a  ).text					,   '''html.parser'''  )
					UpperCamelCase__  :Tuple				   =					'''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}""")