


'''simple docstring'''
from typing import List, Optional, Union

import numpy as np
import torch
import torchaudio.compliance.kaldi as ta_kaldi

from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


UpperCamelCase__          = logging.get_logger(__name__)




class      lowerCamelCase_  (      __a ):
      lowerCAmelCase__							=	['input_features', 'attention_mask']






      def __init__(   self							:       Any		,		_A							:       Tuple=80		,		_A							:       Optional[int]=16_000		,		_A							:       Optional[Any]=80		,		_A							:       List[Any]=0.0		,		_A							:       List[Any]=True		,		_A							:       List[str]=True		,		_A							:       Any=True		,		**_A							:       Tuple		,		):


          '''simple docstring'''


          super().__init__(feature_size=_A		,		sampling_rate=_A		,		padding_value=_A		,		**_A					)
          UpperCAmelCase__     :						int						=							num_mel_bins
          UpperCAmelCase__     :						Optional[Any]						=							do_ceptral_normalize
          UpperCAmelCase__     :						List[str]						=							normalize_means
          UpperCAmelCase__     :						Optional[Any]						=							normalize_vars
          UpperCAmelCase__     :						int						=							True






      def lowercase_				(   self							:       int		,		_A							:       np.ndarray		,		):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[int]						=							waveform * (2**15)  # Kaldi compliance: 16-bit signed integers
          UpperCAmelCase__     :						Optional[int]						=							torch.from_numpy(_A					).unsqueeze(0					)
          UpperCAmelCase__     :						Union[str, Any]						=							ta_kaldi.fbank(_A		,		num_mel_bins=self.num_mel_bins		,		sample_frequency=self.sampling_rate					)
          return features.numpy()






      @staticmethod
      def lowercase_				(   _A							:       np.ndarray		,		_A							:       int		,		_A							:       Optional[bool] = True		,		_A							:       Optional[bool] = True		,		_A							:       float = 0.0		,		):


          '''simple docstring'''


          if normalize_means:
              UpperCAmelCase__     :						Optional[Any]						=							x[:input_length].mean(axis=0					)
              UpperCAmelCase__     :						Dict						=							np.subtract(_A		,		_A					)
          if normalize_vars:
              UpperCAmelCase__     :						Union[str, Any]						=							x[:input_length].std(axis=0					)
              UpperCAmelCase__     :						str						=							np.divide(_A		,		_A					)

          if input_length < x.shape[0]:
              UpperCAmelCase__     :						str						=							padding_value

          # make sure array is in float32
          UpperCAmelCase__     :						int						=							x.astype(np.floataa					)

          return x






      def lowercase_				(   self							:       str		,		_A							:       List[np.ndarray]		,		_A							:       Optional[np.ndarray] = None					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[Any]						=							attention_mask.sum(-1					) if attention_mask is not None else [x.shape[0] for x in input_features]
          return [
              self.utterance_cmvn(_A		,		_A		,		self.normalize_means		,		self.normalize_vars		,		self.padding_value					)
              for x, n in zip(_A		,		_A					)
          ]






      def __call__(   self							:       Optional[int]		,		_A							:       Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]		,		_A							:       Union[bool, str, PaddingStrategy] = False		,		_A							:       Optional[int] = None		,		_A							:       bool = False		,		_A							:       Optional[int] = None		,		_A							:       Optional[Union[str, TensorType]] = None		,		_A							:       Optional[int] = None		,		_A							:       Optional[bool] = None		,		**_A							:       Any		,		):


          '''simple docstring'''


          if sampling_rate is not None:
              if sampling_rate != self.sampling_rate:
                  raise ValueError(
                      f"""The model corresponding to this feature extractor: {self} was trained using a sampling rate of"""
                      f""" {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with"""
                      f""" {self.sampling_rate} and not {sampling_rate}."""					)
          else:
              logger.warning(
                  '''It is strongly recommended to pass the `sampling_rate` argument to this function. '''
                  '''Failing to do so can result in silent errors that might be hard to debug.'''					)

          UpperCAmelCase__     :						Any						=							isinstance(_A		,		np.ndarray					) and len(raw_speech.shape					) > 1
          if is_batched_numpy and len(raw_speech.shape					) > 2:
              raise ValueError(f"""Only mono-channel audio is supported for input to {self}"""					)
          UpperCAmelCase__     :						Tuple						=							is_batched_numpy or (
              isinstance(_A		,		(list, tuple)					) and (isinstance(raw_speech[0]		,		(np.ndarray, tuple, list)					))
          )

          if is_batched:
              UpperCAmelCase__     :						Any						=							[np.asarray(_A		,		dtype=np.floataa					) for speech in raw_speech]
          elif not is_batched and not isinstance(_A		,		np.ndarray					):
              UpperCAmelCase__     :						Any						=							np.asarray(_A		,		dtype=np.floataa					)
          elif isinstance(_A		,		np.ndarray					) and raw_speech.dtype is np.dtype(np.floataa					):
              UpperCAmelCase__     :						List[str]						=							raw_speech.astype(np.floataa					)

          # always return batch
          if not is_batched:
              UpperCAmelCase__     :						Optional[Any]						=							[raw_speech]

          # extract fbank features
          UpperCAmelCase__     :						Optional[Any]						=							[self._extract_fbank_features(_A					) for waveform in raw_speech]

          # convert into correct format for padding
          UpperCAmelCase__     :						List[Any]						=							BatchFeature({'''input_features''': features}					)

          UpperCAmelCase__     :						int						=							self.pad(
              _A		,		padding=_A		,		max_length=_A		,		truncation=_A		,		pad_to_multiple_of=_A		,		return_attention_mask=_A		,		**_A		,		)

          # make sure list is in array format
          UpperCAmelCase__     :						List[Any]						=							padded_inputs.get('''input_features'''					)
          if isinstance(input_features[0]		,		_A					):
              UpperCAmelCase__     :						Optional[int]						=							[np.asarray(_A		,		dtype=np.floataa					) for feature in input_features]

          UpperCAmelCase__     :						List[Any]						=							padded_inputs.get('''attention_mask'''					)
          if attention_mask is not None:
              UpperCAmelCase__     :						Dict						=							[np.asarray(_A		,		dtype=np.intaa					) for array in attention_mask]

          # Utterance-level cepstral mean and variance normalization
          if self.do_ceptral_normalize:
              UpperCAmelCase__     :						List[str]						=							(
                  np.array(_A		,		dtype=np.intaa					)
                  if self._get_padding_strategies(_A		,		max_length=_A					) is not PaddingStrategy.DO_NOT_PAD
                  else None
              )
              UpperCAmelCase__     :						str						=							self.normalize(
                  padded_inputs['''input_features''']		,		attention_mask=_A					)

          if return_tensors is not None:
              UpperCAmelCase__     :						Optional[Any]						=							padded_inputs.convert_to_tensors(_A					)

          return padded_inputs




import requests
from bsa import BeautifulSoup





def 						_lowerCAmelCase							(     _lowerCAmelCase = "AAPL"			)    ->						str:


						'''simple docstring'''






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





