



import unittest

import numpy as np
from datasets import load_dataset

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import BeitImageProcessor


class 	lowerCamelCase__	(       unittest.TestCase):



 """simple docstring"""

 def __init__(    self					:					Union[str, Any]			,						__lowerCAmelCase					:					Dict			,						__lowerCAmelCase					:					List[str]=7			,						__lowerCAmelCase					:					int=3			,						__lowerCAmelCase					:					int=18			,						__lowerCAmelCase					:					Tuple=30			,						__lowerCAmelCase					:					List[str]=4_00			,						__lowerCAmelCase					:					List[Any]=True			,						__lowerCAmelCase					:					List[str]=None			,						__lowerCAmelCase					:					Optional[Any]=True			,						__lowerCAmelCase					:					Tuple=None			,						__lowerCAmelCase					:					Dict=True			,						__lowerCAmelCase					:					Dict=[0.5, 0.5, 0.5]			,						__lowerCAmelCase					:					Optional[Any]=[0.5, 0.5, 0.5]			,						__lowerCAmelCase					:					Tuple=False			,						)   ->	List[str]:
    _A      =       size if size is not None else {'''height''': 20, '''width''': 20}
    _A      =       crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
    _A      =       parent
    _A      =       batch_size
    _A      =       num_channels
    _A      =       image_size
    _A      =       min_resolution
    _A      =       max_resolution
    _A      =       do_resize
    _A      =       size
    _A      =       do_center_crop
    _A      =       crop_size
    _A      =       do_normalize
    _A      =       image_mean
    _A      =       image_std
    _A      =       do_reduce_labels

 def     snake_case_      (    self					:					Optional[int]      )   ->	Tuple:
    return {
        "do_resize": self.do_resize,
        "size": self.size,
        "do_center_crop": self.do_center_crop,
        "crop_size": self.crop_size,
        "do_normalize": self.do_normalize,
        "image_mean": self.image_mean,
        "image_std": self.image_std,
        "do_reduce_labels": self.do_reduce_labels,
    }

def 	SCREAMING_SNAKE_CASE_							(	)  ->     Tuple:
   _A      =       load_dataset('''hf-internal-testing/fixtures_ade20k'''	,   split='''test'''				)

   _A      =       Image.open(dataset[0]['''file''']				)
   _A      =       Image.open(dataset[1]['''file''']				)

   return image, map

def 	SCREAMING_SNAKE_CASE_							(	)  ->     Union[str, Any]:
   _A      =       load_dataset('''hf-internal-testing/fixtures_ade20k'''	,   split='''test'''				)

   _A      =       Image.open(ds[0]['''file''']				)
   _A      =       Image.open(ds[1]['''file''']				)
   _A      =       Image.open(ds[2]['''file''']				)
   _A      =       Image.open(ds[3]['''file''']				)

   return [imagea, imagea], [mapa, mapa]


@require_torch
@require_vision
class 	lowerCamelCase__	(       _A							,  unittest.TestCase):



 """simple docstring"""

 a__					: List[Any] =  BeitImageProcessor if is_vision_available() else None

 def     snake_case_      (    self					:					Optional[Any]      )   ->	Optional[Any]:
    _A      =       BeitImageProcessingTester(self      )

 @property
 def     snake_case_      (    self					:					Dict      )   ->	Optional[int]:
    return self.image_processor_tester.prepare_image_processor_dict()

 def     snake_case_      (    self					:					int      )   ->	List[str]:
    _A      =       self.image_processing_class(**self.image_processor_dict      )
    self.assertTrue(hasattr(__lowerCAmelCase			,						'''do_resize'''      )      )
    self.assertTrue(hasattr(__lowerCAmelCase			,						'''size'''      )      )
    self.assertTrue(hasattr(__lowerCAmelCase			,						'''do_center_crop'''      )      )
    self.assertTrue(hasattr(__lowerCAmelCase			,						'''center_crop'''      )      )
    self.assertTrue(hasattr(__lowerCAmelCase			,						'''do_normalize'''      )      )
    self.assertTrue(hasattr(__lowerCAmelCase			,						'''image_mean'''      )      )
    self.assertTrue(hasattr(__lowerCAmelCase			,						'''image_std'''      )      )

 def     snake_case_      (    self					:					int      )   ->	List[str]:
    _A      =       self.image_processing_class.from_dict(self.image_processor_dict      )
    self.assertEqual(image_processor.size			,						{'''height''': 20, '''width''': 20}      )
    self.assertEqual(image_processor.crop_size			,						{'''height''': 18, '''width''': 18}      )
    self.assertEqual(image_processor.do_reduce_labels			,						__lowerCAmelCase      )

    _A      =       self.image_processing_class.from_dict(
        self.image_processor_dict			,						size=42			,						crop_size=84			,						reduce_labels=__lowerCAmelCase      )
    self.assertEqual(image_processor.size			,						{'''height''': 42, '''width''': 42}      )
    self.assertEqual(image_processor.crop_size			,						{'''height''': 84, '''width''': 84}      )
    self.assertEqual(image_processor.do_reduce_labels			,						__lowerCAmelCase      )

 def     snake_case_      (    self					:					Union[str, Any]      )   ->	Optional[Any]:
    pass

 def     snake_case_      (    self					:					Union[str, Any]      )   ->	int:
    # Initialize image_processing
    _A      =       self.image_processing_class(**self.image_processor_dict      )
    # create random PIL images
    _A      =       prepare_image_inputs(self.image_processor_tester			,						equal_resolution=__lowerCAmelCase      )
    for image in image_inputs:
       self.assertIsInstance(__lowerCAmelCase			,						Image.Image      )

    # Test not batched input
    _A      =       image_processing(image_inputs[0]			,						return_tensors='''pt'''      ).pixel_values
    self.assertEqual(
        encoded_images.shape			,						(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)

    # Test batched
    _A      =       image_processing(__lowerCAmelCase			,						return_tensors='''pt'''      ).pixel_values
    self.assertEqual(
        encoded_images.shape			,						(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)

 def     snake_case_      (    self					:					Optional[Any]      )   ->	Any:
    # Initialize image_processing
    _A      =       self.image_processing_class(**self.image_processor_dict      )
    # create random numpy tensors
    _A      =       prepare_image_inputs(self.image_processor_tester			,						equal_resolution=__lowerCAmelCase			,						numpify=__lowerCAmelCase      )
    for image in image_inputs:
       self.assertIsInstance(__lowerCAmelCase			,						np.ndarray      )

    # Test not batched input
    _A      =       image_processing(image_inputs[0]			,						return_tensors='''pt'''      ).pixel_values
    self.assertEqual(
        encoded_images.shape			,						(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)

    # Test batched
    _A      =       image_processing(__lowerCAmelCase			,						return_tensors='''pt'''      ).pixel_values
    self.assertEqual(
        encoded_images.shape			,						(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)

 def     snake_case_      (    self					:					List[Any]      )   ->	Union[str, Any]:
    # Initialize image_processing
    _A      =       self.image_processing_class(**self.image_processor_dict      )
    # create random PyTorch tensors
    _A      =       prepare_image_inputs(self.image_processor_tester			,						equal_resolution=__lowerCAmelCase			,						torchify=__lowerCAmelCase      )
    for image in image_inputs:
       self.assertIsInstance(__lowerCAmelCase			,						torch.Tensor      )

    # Test not batched input
    _A      =       image_processing(image_inputs[0]			,						return_tensors='''pt'''      ).pixel_values
    self.assertEqual(
        encoded_images.shape			,						(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)

    # Test batched
    _A      =       image_processing(__lowerCAmelCase			,						return_tensors='''pt'''      ).pixel_values
    self.assertEqual(
        encoded_images.shape			,						(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)

 def     snake_case_      (    self					:					int      )   ->	str:
    # Initialize image_processing
    _A      =       self.image_processing_class(**self.image_processor_dict      )
    # create random PyTorch tensors
    _A      =       prepare_image_inputs(self.image_processor_tester			,						equal_resolution=__lowerCAmelCase			,						torchify=__lowerCAmelCase      )
    _A      =       []
    for image in image_inputs:
       self.assertIsInstance(__lowerCAmelCase			,						torch.Tensor      )
       maps.append(torch.zeros(image.shape[-2:]      ).long()      )

    # Test not batched input
    _A      =       image_processing(image_inputs[0]			,						maps[0]			,						return_tensors='''pt'''      )
    self.assertEqual(
        encoding['''pixel_values'''].shape			,						(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(
        encoding['''labels'''].shape			,						(
            1,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(encoding['''labels'''].dtype			,						torch.long      )
    self.assertTrue(encoding['''labels'''].min().item() >= 0      )
    self.assertTrue(encoding['''labels'''].max().item() <= 2_55      )

    # Test batched
    _A      =       image_processing(__lowerCAmelCase			,						__lowerCAmelCase			,						return_tensors='''pt'''      )
    self.assertEqual(
        encoding['''pixel_values'''].shape			,						(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(
        encoding['''labels'''].shape			,						(
            self.image_processor_tester.batch_size,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(encoding['''labels'''].dtype			,						torch.long      )
    self.assertTrue(encoding['''labels'''].min().item() >= 0      )
    self.assertTrue(encoding['''labels'''].max().item() <= 2_55      )

    # Test not batched input (PIL images)
    _A  ,    _A      =       prepare_semantic_single_inputs()

    _A      =       image_processing(__lowerCAmelCase			,						__lowerCAmelCase			,						return_tensors='''pt'''      )
    self.assertEqual(
        encoding['''pixel_values'''].shape			,						(
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(
        encoding['''labels'''].shape			,						(
            1,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(encoding['''labels'''].dtype			,						torch.long      )
    self.assertTrue(encoding['''labels'''].min().item() >= 0      )
    self.assertTrue(encoding['''labels'''].max().item() <= 2_55      )

    # Test batched input (PIL images)
    _A  ,    _A      =       prepare_semantic_batch_inputs()

    _A      =       image_processing(__lowerCAmelCase			,						__lowerCAmelCase			,						return_tensors='''pt'''      )
    self.assertEqual(
        encoding['''pixel_values'''].shape			,						(
            2,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(
        encoding['''labels'''].shape			,						(
            2,
            self.image_processor_tester.crop_size['''height'''],
            self.image_processor_tester.crop_size['''width'''],
        )			,						)
    self.assertEqual(encoding['''labels'''].dtype			,						torch.long      )
    self.assertTrue(encoding['''labels'''].min().item() >= 0      )
    self.assertTrue(encoding['''labels'''].max().item() <= 2_55      )

 def     snake_case_      (    self					:					List[str]      )   ->	Dict:
    # Initialize image_processing
    _A      =       self.image_processing_class(**self.image_processor_dict      )

    # ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
    _A  ,    _A      =       prepare_semantic_single_inputs()
    _A      =       image_processing(__lowerCAmelCase			,						__lowerCAmelCase			,						return_tensors='''pt'''      )
    self.assertTrue(encoding['''labels'''].min().item() >= 0      )
    self.assertTrue(encoding['''labels'''].max().item() <= 1_50      )

    _A      =       True
    _A      =       image_processing(__lowerCAmelCase			,						__lowerCAmelCase			,						return_tensors='''pt'''      )
    self.assertTrue(encoding['''labels'''].min().item() >= 0      )
    self.assertTrue(encoding['''labels'''].max().item() <= 2_55      )








import requests
from bsa import BeautifulSoup

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



