



"""simple docstring"""
import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import FEATURE_EXTRACTOR_NAME, is_vision_available


if is_vision_available():
   from PIL import Image

   from transformers import ChineseCLIPImageProcessor, ChineseCLIPProcessor



@require_vision
class    SCREAMING_SNAKE_CASE__						(      unittest.TestCase				):

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[int]			=			tempfile.mkdtemp()

    UpperCAmelCase			:      Any			=			[
        """[UNK]""",
        """[CLS]""",
        """[SEP]""",
        """[PAD]""",
        """[MASK]""",
        """的""",
        """价""",
        """格""",
        """是""",
        """15""",
        """便""",
        """alex""",
        """##andra""",
        """，""",
        """。""",
        """-""",
        """t""",
        """shirt""",
    ]
    UpperCAmelCase			:      Any			=			os.path.join(self.tmpdirname   ,  VOCAB_FILES_NAMES["""vocab_file"""]		)
    with open(self.vocab_file   ,  """w"""   ,  encoding="""utf-8"""		) as vocab_writer:
     vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]		)		)

    UpperCAmelCase			:      int			=			{
        """do_resize""": True,
        """size""": {"""height""": 224, """width""": 224},
        """do_center_crop""": True,
        """crop_size""": {"""height""": 18, """width""": 18},
        """do_normalize""": True,
        """image_mean""": [0.4814_5466, 0.457_8275, 0.4082_1073],
        """image_std""": [0.2686_2954, 0.2613_0258, 0.2757_7711],
        """do_convert_rgb""": True,
    }
    UpperCAmelCase			:      Union[str, Any]			=			os.path.join(self.tmpdirname   ,  _SCREAMING_SNAKE_CASE		)
    with open(self.image_processor_file   ,  """w"""   ,  encoding="""utf-8"""		) as fp:
     json.dump(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self   ,  **_SCREAMING_SNAKE_CASE		)						->   List[Any]:





    '''simple docstring'''




    return BertTokenizer.from_pretrained(self.tmpdirname   ,  **_SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self   ,  **_SCREAMING_SNAKE_CASE		)						->   Tuple:





    '''simple docstring'''




    return BertTokenizerFast.from_pretrained(self.tmpdirname   ,  **_SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self   ,  **_SCREAMING_SNAKE_CASE		)						->   Optional[Any]:





    '''simple docstring'''




    return ChineseCLIPImageProcessor.from_pretrained(self.tmpdirname   ,  **_SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





    '''simple docstring'''




    shutil.rmtree(self.tmpdirname		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    UpperCAmelCase			:      List[str]			=			[np.random.randint(255   ,  size=(3, 30, 400)   ,  dtype=np.uinta		)]

    UpperCAmelCase			:      Dict			=			[Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE   ,  0   ,  -1		)		) for x in image_inputs]

    return image_inputs

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Dict:





    '''simple docstring'''




    UpperCAmelCase			:      Dict			=			self.get_tokenizer()
    UpperCAmelCase			:      str			=			self.get_rust_tokenizer()
    UpperCAmelCase			:      Dict			=			self.get_image_processor()

    UpperCAmelCase			:      int			=			ChineseCLIPProcessor(tokenizer=_SCREAMING_SNAKE_CASE   ,  image_processor=_SCREAMING_SNAKE_CASE		)
    processor_slow.save_pretrained(self.tmpdirname		)
    UpperCAmelCase			:      List[Any]			=			ChineseCLIPProcessor.from_pretrained(self.tmpdirname   ,  use_fast=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      List[str]			=			ChineseCLIPProcessor(tokenizer=_SCREAMING_SNAKE_CASE   ,  image_processor=_SCREAMING_SNAKE_CASE		)
    processor_fast.save_pretrained(self.tmpdirname		)
    UpperCAmelCase			:      Dict			=			ChineseCLIPProcessor.from_pretrained(self.tmpdirname		)

    self.assertEqual(processor_slow.tokenizer.get_vocab()   ,  tokenizer_slow.get_vocab()		)
    self.assertEqual(processor_fast.tokenizer.get_vocab()   ,  tokenizer_fast.get_vocab()		)
    self.assertEqual(tokenizer_slow.get_vocab()   ,  tokenizer_fast.get_vocab()		)
    self.assertIsInstance(processor_slow.tokenizer   ,  _SCREAMING_SNAKE_CASE		)
    self.assertIsInstance(processor_fast.tokenizer   ,  _SCREAMING_SNAKE_CASE		)

    self.assertEqual(processor_slow.image_processor.to_json_string()   ,  image_processor.to_json_string()		)
    self.assertEqual(processor_fast.image_processor.to_json_string()   ,  image_processor.to_json_string()		)
    self.assertIsInstance(processor_slow.image_processor   ,  _SCREAMING_SNAKE_CASE		)
    self.assertIsInstance(processor_fast.image_processor   ,  _SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      List[Any]			=			ChineseCLIPProcessor(tokenizer=self.get_tokenizer()   ,  image_processor=self.get_image_processor()		)
    processor.save_pretrained(self.tmpdirname		)

    UpperCAmelCase			:      List[Any]			=			self.get_tokenizer(cls_token="""(CLS)"""   ,  sep_token="""(SEP)"""		)
    UpperCAmelCase			:      int			=			self.get_image_processor(do_normalize=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      int			=			ChineseCLIPProcessor.from_pretrained(
        self.tmpdirname   ,  cls_token="""(CLS)"""   ,  sep_token="""(SEP)"""   ,  do_normalize=_SCREAMING_SNAKE_CASE		)

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

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

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Dict:





    '''simple docstring'''




    UpperCAmelCase			:      List[str]			=			self.get_image_processor()
    UpperCAmelCase			:      Optional[int]			=			self.get_tokenizer()

    UpperCAmelCase			:      Optional[Any]			=			ChineseCLIPProcessor(tokenizer=_SCREAMING_SNAKE_CASE   ,  image_processor=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Union[str, Any]			=			self.prepare_image_inputs()

    UpperCAmelCase			:      Any			=			image_processor(_SCREAMING_SNAKE_CASE   ,  return_tensors="""np"""		)
    UpperCAmelCase			:      List[Any]			=			processor(images=_SCREAMING_SNAKE_CASE   ,  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 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[int]			=			self.get_image_processor()
    UpperCAmelCase			:      List[str]			=			self.get_tokenizer()

    UpperCAmelCase			:      List[str]			=			ChineseCLIPProcessor(tokenizer=_SCREAMING_SNAKE_CASE   ,  image_processor=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      str			=			"""Alexandra，T-shirt的价格是15便士。"""

    UpperCAmelCase			:      Dict			=			processor(text=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Tuple			=			tokenizer(_SCREAMING_SNAKE_CASE		)

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

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Union[str, Any]:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[int]			=			self.get_image_processor()
    UpperCAmelCase			:      int			=			self.get_tokenizer()

    UpperCAmelCase			:      Optional[Any]			=			ChineseCLIPProcessor(tokenizer=_SCREAMING_SNAKE_CASE   ,  image_processor=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Dict			=			"""Alexandra，T-shirt的价格是15便士。"""
    UpperCAmelCase			:      List[Any]			=			self.prepare_image_inputs()

    UpperCAmelCase			:      int			=			processor(text=_SCREAMING_SNAKE_CASE   ,  images=_SCREAMING_SNAKE_CASE		)

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

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

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			:      Dict			=			self.get_image_processor()
    UpperCAmelCase			:      Optional[int]			=			self.get_tokenizer()

    UpperCAmelCase			:      str			=			ChineseCLIPProcessor(tokenizer=_SCREAMING_SNAKE_CASE   ,  image_processor=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Any			=			[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

    UpperCAmelCase			:      Optional[int]			=			processor.batch_decode(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      str			=			tokenizer.batch_decode(_SCREAMING_SNAKE_CASE		)

    self.assertListEqual(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[int]:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			self.get_image_processor()
    UpperCAmelCase			:      Tuple			=			self.get_tokenizer()

    UpperCAmelCase			:      List[Any]			=			ChineseCLIPProcessor(tokenizer=_SCREAMING_SNAKE_CASE   ,  image_processor=_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Optional[Any]			=			"""Alexandra，T-shirt的价格是15便士。"""
    UpperCAmelCase			:      List[str]			=			self.prepare_image_inputs()

    UpperCAmelCase			:      Dict			=			processor(text=_SCREAMING_SNAKE_CASE   ,  images=_SCREAMING_SNAKE_CASE		)

    self.assertListEqual(list(inputs.keys()		)   ,  processor.model_input_names		)





"""simple docstring"""
import requests
from bsa import BeautifulSoup

def    _snake_case		(		UpperCamelCase		:	str = "AAPL"		):
 UpperCAmelCase			:      Any			=			F"https://in.finance.yahoo.com/quote/{symbol}?s={symbol}"
 UpperCAmelCase			:      Optional[int]			=			BeautifulSoup(requests.get(UpperCamelCase		).text    ,	"""html.parser"""		)
 UpperCAmelCase			:      int			=			"""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}""")
