





import unittest

from transformers import LiltConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          LiltForQuestionAnswering,
          LiltForSequenceClassification,
          LiltForTokenClassification,
          LiltModel,
      )
      from transformers.models.lilt.modeling_lilt import LILT_PRETRAINED_MODEL_ARCHIVE_LIST






class   snake_case_							:






  def __init__(				self					:	Union[str, Any]  ,    _snake_case					:	Optional[int]  ,    _snake_case					:	Optional[Any]=13  ,    _snake_case					:	int=7  ,    _snake_case					:	Any=True  ,    _snake_case					:	Tuple=True  ,    _snake_case					:	Dict=True  ,    _snake_case					:	Optional[Any]=True  ,    _snake_case					:	Tuple=99  ,    _snake_case					:	Any=24  ,    _snake_case					:	Tuple=2  ,    _snake_case					:	str=6  ,    _snake_case					:	Optional[Any]=37  ,    _snake_case					:	Optional[Any]="gelu"  ,    _snake_case					:	int=0.1  ,    _snake_case					:	Tuple=0.1  ,    _snake_case					:	int=512  ,    _snake_case					:	List[Any]=16  ,    _snake_case					:	Any=2  ,    _snake_case					:	List[Any]=0.02  ,    _snake_case					:	Optional[Any]=3  ,    _snake_case					:	Dict=None  ,    _snake_case					:	Any=1000  ,    )->Tuple:






   '''simple docstring'''

   __lowerCAmelCase	:			str         =  parent
   __lowerCAmelCase	:			str         =  batch_size
   __lowerCAmelCase	:			Union[str, Any]         =  seq_length
   __lowerCAmelCase	:			List[str]         =  is_training
   __lowerCAmelCase	:			Union[str, Any]         =  use_input_mask
   __lowerCAmelCase	:			List[str]         =  use_token_type_ids
   __lowerCAmelCase	:			Tuple         =  use_labels
   __lowerCAmelCase	:			Any         =  vocab_size
   __lowerCAmelCase	:			List[str]         =  hidden_size
   __lowerCAmelCase	:			str         =  num_hidden_layers
   __lowerCAmelCase	:			List[str]         =  num_attention_heads
   __lowerCAmelCase	:			Any         =  intermediate_size
   __lowerCAmelCase	:			str         =  hidden_act
   __lowerCAmelCase	:			Dict         =  hidden_dropout_prob
   __lowerCAmelCase	:			List[str]         =  attention_probs_dropout_prob
   __lowerCAmelCase	:			Optional[Any]         =  max_position_embeddings
   __lowerCAmelCase	:			int         =  type_vocab_size
   __lowerCAmelCase	:			Any         =  type_sequence_label_size
   __lowerCAmelCase	:			Union[str, Any]         =  initializer_range
   __lowerCAmelCase	:			List[Any]         =  num_labels
   __lowerCAmelCase	:			Optional[Any]         =  scope
   __lowerCAmelCase	:			int         =  range_bbox






  def  UpperCAmelCase__		(				self					:	int     )->str:






   '''simple docstring'''

   __lowerCAmelCase	:			Tuple         =  ids_tensor([self.batch_size, self.seq_length]  ,    self.vocab_size     )

   __lowerCAmelCase	:			int         =  ids_tensor([self.batch_size, self.seq_length, 4]  ,    self.range_bbox     )
   # Ensure that bbox is legal
   for i in range(bbox.shape[0]     ):
    for j in range(bbox.shape[1]     ):
     if bbox[i, j, 3] < bbox[i, j, 1]:
      __lowerCAmelCase	:			Optional[int]         =  bbox[i, j, 3]
      __lowerCAmelCase	:			Optional[int]         =  bbox[i, j, 1]
      __lowerCAmelCase	:			List[Any]         =  t
     if bbox[i, j, 2] < bbox[i, j, 0]:
      __lowerCAmelCase	:			Tuple         =  bbox[i, j, 2]
      __lowerCAmelCase	:			int         =  bbox[i, j, 0]
      __lowerCAmelCase	:			Optional[Any]         =  t

   __lowerCAmelCase	:			Tuple         =  None
   if self.use_input_mask:
    __lowerCAmelCase	:			List[str]         =  ids_tensor([self.batch_size, self.seq_length]  ,    vocab_size=2     )

   __lowerCAmelCase	:			Optional[Any]         =  None
   if self.use_token_type_ids:
    __lowerCAmelCase	:			int         =  ids_tensor([self.batch_size, self.seq_length]  ,    self.type_vocab_size     )

   __lowerCAmelCase	:			List[str]         =  None
   __lowerCAmelCase	:			Tuple         =  None
   if self.use_labels:
    __lowerCAmelCase	:			int         =  ids_tensor([self.batch_size]  ,    self.type_sequence_label_size     )
    __lowerCAmelCase	:			Dict         =  ids_tensor([self.batch_size, self.seq_length]  ,    self.num_labels     )

   __lowerCAmelCase	:			List[Any]         =  self.get_config()

   return config, input_ids, bbox, token_type_ids, input_mask, sequence_labels, token_labels






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






   '''simple docstring'''

   return LiltConfig(
       vocab_size=self.vocab_size  ,    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  ,    max_position_embeddings=self.max_position_embeddings  ,    type_vocab_size=self.type_vocab_size  ,    initializer_range=self.initializer_range  ,    )






  def  UpperCAmelCase__		(				self					:	Tuple  ,    _snake_case					:	Dict  ,    _snake_case					:	str  ,    _snake_case					:	str  ,    _snake_case					:	Any  ,    _snake_case					:	int  ,    _snake_case					:	Optional[Any]  ,    _snake_case					:	List[str]  ,    )->Dict:






   '''simple docstring'''

   __lowerCAmelCase	:			str         =  LiltModel(config=__lowerCAmelCase     )
   model.to(__lowerCAmelCase     )
   model.eval()
   __lowerCAmelCase	:			Union[str, Any]         =  model(__lowerCAmelCase  ,    bbox=__lowerCAmelCase  ,    attention_mask=__lowerCAmelCase  ,    token_type_ids=__lowerCAmelCase     )
   __lowerCAmelCase	:			List[str]         =  model(__lowerCAmelCase  ,    bbox=__lowerCAmelCase  ,    token_type_ids=__lowerCAmelCase     )
   __lowerCAmelCase	:			int         =  model(__lowerCAmelCase  ,    bbox=__lowerCAmelCase     )

   self.parent.assertEqual(result.last_hidden_state.shape  ,    (self.batch_size, self.seq_length, self.hidden_size)     )
   self.parent.assertEqual(result.pooler_output.shape  ,    (self.batch_size, self.hidden_size)     )






  def  UpperCAmelCase__		(				self					:	Optional[Any]  ,    _snake_case					:	str  ,    _snake_case					:	List[Any]  ,    _snake_case					:	Dict  ,    _snake_case					:	Tuple  ,    _snake_case					:	List[str]  ,    _snake_case					:	str  ,    _snake_case					:	str  ,    )->Tuple:






   '''simple docstring'''

   __lowerCAmelCase	:			str         =  self.num_labels
   __lowerCAmelCase	:			Dict         =  LiltForTokenClassification(config=__lowerCAmelCase     )
   model.to(__lowerCAmelCase     )
   model.eval()
   __lowerCAmelCase	:			Tuple         =  model(
       __lowerCAmelCase  ,    bbox=__lowerCAmelCase  ,    attention_mask=__lowerCAmelCase  ,    token_type_ids=__lowerCAmelCase  ,    labels=__lowerCAmelCase     )
   self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length, self.num_labels)     )






  def  UpperCAmelCase__		(				self					:	Any  ,    _snake_case					:	Union[str, Any]  ,    _snake_case					:	Any  ,    _snake_case					:	Tuple  ,    _snake_case					:	List[Any]  ,    _snake_case					:	List[str]  ,    _snake_case					:	List[str]  ,    _snake_case					:	Optional[Any]  ,    )->int:






   '''simple docstring'''

   __lowerCAmelCase	:			List[Any]         =  LiltForQuestionAnswering(config=__lowerCAmelCase     )
   model.to(__lowerCAmelCase     )
   model.eval()
   __lowerCAmelCase	:			Dict         =  model(
       __lowerCAmelCase  ,    bbox=__lowerCAmelCase  ,    attention_mask=__lowerCAmelCase  ,    token_type_ids=__lowerCAmelCase  ,    start_positions=__lowerCAmelCase  ,    end_positions=__lowerCAmelCase  ,    )
   self.parent.assertEqual(result.start_logits.shape  ,    (self.batch_size, self.seq_length)     )
   self.parent.assertEqual(result.end_logits.shape  ,    (self.batch_size, self.seq_length)     )






  def  UpperCAmelCase__		(				self					:	Dict     )->Dict:






   '''simple docstring'''

   __lowerCAmelCase	:			str         =  self.prepare_config_and_inputs()
   (
       (
       __lowerCAmelCase    
   )   ,	(
       __lowerCAmelCase    
   )   ,	(
       __lowerCAmelCase    
   )   ,	(
       __lowerCAmelCase    
   )   ,	(
       __lowerCAmelCase    
   )   ,	(
       __lowerCAmelCase    
   )   ,	(
       __lowerCAmelCase    
   )   ,	    
   )	:			Tuple         =  config_and_inputs
   __lowerCAmelCase	:			Union[str, Any]         =  {
       """input_ids""": input_ids,
       """bbox""": bbox,
       """token_type_ids""": token_type_ids,
       """attention_mask""": input_mask,
   }
   return config, inputs_dict






@require_torch
class   snake_case_							(						_A	,_A	,_A	,unittest.TestCase		):
  A_     				=       (
      (
          LiltModel,
          LiltForSequenceClassification,
          LiltForTokenClassification,
          LiltForQuestionAnswering,
      )
      if is_torch_available()
      else ()
  )
  A_     				=       (
      {
          "feature-extraction": LiltModel,
          "question-answering": LiltForQuestionAnswering,
          "text-classification": LiltForSequenceClassification,
          "token-classification": LiltForTokenClassification,
          "zero-shot": LiltForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  A_     				=       False
  A_     				=       False






  def  UpperCAmelCase__		(				self					:	Any  ,    _snake_case					:	Union[str, Any]  ,    _snake_case					:	Any  ,    _snake_case					:	List[str]  ,    _snake_case					:	str  ,    _snake_case					:	str     )->Optional[int]:






   '''simple docstring'''

   return True






  def  UpperCAmelCase__		(				self					:	Tuple     )->Optional[int]:






   '''simple docstring'''

   __lowerCAmelCase	:			Union[str, Any]         =  LiltModelTester(self     )
   __lowerCAmelCase	:			Tuple         =  ConfigTester(self  ,    config_class=__lowerCAmelCase  ,    hidden_size=37     )






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






   '''simple docstring'''

   self.config_tester.run_common_tests()






  def  UpperCAmelCase__		(				self					:	Optional[Any]     )->Dict:






   '''simple docstring'''

   __lowerCAmelCase	:			Union[str, Any]         =  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*__lowerCAmelCase     )






  def  UpperCAmelCase__		(				self					:	Any     )->Tuple:






   '''simple docstring'''

   __lowerCAmelCase	:			Tuple         =  self.model_tester.prepare_config_and_inputs()
   for type in ["absolute", "relative_key", "relative_key_query"]:
    __lowerCAmelCase	:			Union[str, Any]         =  type
    self.model_tester.create_and_check_model(*__lowerCAmelCase     )






  def  UpperCAmelCase__		(				self					:	Optional[int]     )->Optional[Any]:






   '''simple docstring'''

   __lowerCAmelCase	:			List[Any]         =  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase     )






  def  UpperCAmelCase__		(				self					:	int     )->Any:






   '''simple docstring'''

   __lowerCAmelCase	:			str         =  self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase     )






  @slow
  def  UpperCAmelCase__		(				self					:	Optional[int]     )->List[Any]:






   '''simple docstring'''

   for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
    __lowerCAmelCase	:			Any         =  LiltModel.from_pretrained(__lowerCAmelCase     )
    self.assertIsNotNone(__lowerCAmelCase     )






@require_torch
@slow
class   snake_case_							(						unittest.TestCase		):






  def  UpperCAmelCase__		(				self					:	str     )->Tuple:






   '''simple docstring'''

   __lowerCAmelCase	:			str         =  LiltModel.from_pretrained("""SCUT-DLVCLab/lilt-roberta-en-base"""     ).to(__lowerCAmelCase     )

   __lowerCAmelCase	:			Optional[Any]         =  torch.tensor([[1, 2]]  ,    device=__lowerCAmelCase     )
   __lowerCAmelCase	:			Optional[int]         =  torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8]]]  ,    device=__lowerCAmelCase     )

   # forward pass
   with torch.no_grad():
    __lowerCAmelCase	:			str         =  model(input_ids=__lowerCAmelCase  ,    bbox=__lowerCAmelCase     )

   __lowerCAmelCase	:			List[Any]         =  torch.Size([1, 2, 768]     )
   __lowerCAmelCase	:			Tuple         =  torch.tensor(
       [[-0.0_653, 0.0_950, -0.0_061], [-0.0_545, 0.0_926, -0.0_324]]  ,    device=__lowerCAmelCase  ,    )

   self.assertTrue(outputs.last_hidden_state.shape  ,    __lowerCAmelCase     )
   self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :, :3]  ,    __lowerCAmelCase  ,    atol=1E-3     )     )




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}')



