

"""simple docstring"""





import html

from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...utils import is_bsa_available, logging, requires_backends


if is_bsa_available():
							import bsa
							from bsa import BeautifulSoup


__UpperCamelCase  :      int							      =		logging.get_logger(__name__)







class 				SCREAMING_SNAKE_CASE					(		a_       ):






					"""simple docstring"""



					def __init__(       self			:				List[str]   ,**lowercase_			:				str		):
						requires_backends(self   ,['''bs4''']		)
						super().__init__(**lowercase_		)







					def        __lowerCAmelCase (       self			:				Tuple   ,lowercase_			:				Optional[Any]		):
						lowerCAmelCase__	:						Optional[int]  				=	[]
						lowerCAmelCase__	:						str  				=	[]
						lowerCAmelCase__	:						Optional[int]  				=	element if element.name else element.parent
						for parent in child.parents:  # type: bs4.element.Tag
							lowerCAmelCase__	:						Union[str, Any]  				=	parent.find_all(child.name   ,recursive=lowercase_		)
							xpath_tags.append(child.name		)
							xpath_subscripts.append(
							    0 if 1 == len(lowercase_		) else next(i for i, s in enumerate(lowercase_   ,1		) if s is child		)		)
							lowerCAmelCase__	:						Tuple  				=	parent
						xpath_tags.reverse()
						xpath_subscripts.reverse()
						return xpath_tags, xpath_subscripts







					def        __lowerCAmelCase (       self			:				List[str]   ,lowercase_			:				int		):
						lowerCAmelCase__	:						str  				=	BeautifulSoup(lowercase_   ,'''html.parser'''		)

						lowerCAmelCase__	:						List[str]  				=	[]
						lowerCAmelCase__	:						Union[str, Any]  				=	[]
						lowerCAmelCase__	:						Optional[int]  				=	[]

						for element in html_code.descendants:
							if type(lowercase_		) == bsa.element.NavigableString:
								if type(element.parent		) != bsa.element.Tag:
									continue

								lowerCAmelCase__	:						str  				=	html.unescape(lowercase_		).strip()
								if not text_in_this_tag:
									continue

								all_doc_strings.append(lowercase_		)

								lowerCAmelCase__				,lowerCAmelCase__	:						List[Any]  				=	self.xpath_soup(lowercase_		)
								stringaxtag_seq.append(lowercase_		)
								stringaxsubs_seq.append(lowercase_		)

						if len(lowercase_		) != len(lowercase_		):
							raise ValueError('''Number of doc strings and xtags does not correspond'''		)
						if len(lowercase_		) != len(lowercase_		):
							raise ValueError('''Number of doc strings and xsubs does not correspond'''		)

						return all_doc_strings, stringaxtag_seq, stringaxsubs_seq







					def        __lowerCAmelCase (       self			:				Tuple   ,lowercase_			:				int   ,lowercase_			:				Any		):
						lowerCAmelCase__	:						List[Any]  				=	''''''
						for tagname, subs in zip(lowercase_   ,lowercase_		):
							xpath += F'/{tagname}'
							if subs != 0:
								xpath += F'[{subs}]'
						return xpath







					def __call__(       self			:				int   ,lowercase_			:				Optional[int]		):
						lowerCAmelCase__	:						Optional[int]  				=	False

						# Check that strings has a valid type
						if isinstance(lowercase_   ,lowercase_		):
							lowerCAmelCase__	:						Dict  				=	True
						elif isinstance(lowercase_   ,(list, tuple)		):
							if len(lowercase_		) == 0 or isinstance(html_strings[0]   ,lowercase_		):
								lowerCAmelCase__	:						Optional[int]  				=	True

						if not valid_strings:
							raise ValueError(
							    '''HTML strings must of type `str`, `List[str]` (batch of examples), '''
							    F'but is of type {type(lowercase_		)}.'		)

						lowerCAmelCase__	:						Dict  				=	bool(isinstance(lowercase_   ,(list, tuple)		) and (isinstance(html_strings[0]   ,lowercase_		))		)

						if not is_batched:
							lowerCAmelCase__	:						Dict  				=	[html_strings]

						# Get nodes + xpaths
						lowerCAmelCase__	:						Optional[int]  				=	[]
						lowerCAmelCase__	:						Union[str, Any]  				=	[]
						for html_string in html_strings:
							lowerCAmelCase__				,lowerCAmelCase__				,lowerCAmelCase__	:						str  				=	self.get_three_from_single(lowercase_		)
							nodes.append(lowercase_		)
							lowerCAmelCase__	:						List[str]  				=	[]
							for node, tag_list, sub_list in zip(lowercase_   ,lowercase_   ,lowercase_		):
								lowerCAmelCase__	:						str  				=	self.construct_xpath(lowercase_   ,lowercase_		)
								xpath_strings.append(lowercase_		)
							xpaths.append(lowercase_		)

						# return as Dict
						lowerCAmelCase__	:						str  				=	{'''nodes''': nodes, '''xpaths''': xpaths}
						lowerCAmelCase__	:						Dict  				=	BatchFeature(data=lowercase_   ,tensor_type=lowercase_		)

						return encoded_inputs










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCamelCase				:		Optional[Any]     =   {
    "configuration_whisper": ["WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP", "WhisperConfig", "WhisperOnnxConfig"],
    "feature_extraction_whisper": ["WhisperFeatureExtractor"],
    "processing_whisper": ["WhisperProcessor"],
    "tokenization_whisper": ["WhisperTokenizer"],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase				:		Tuple     =   ["WhisperTokenizerFast"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase				:		str     =   [
     "WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST",
     "WhisperForConditionalGeneration",
     "WhisperModel",
     "WhisperPreTrainedModel",
     "WhisperForAudioClassification",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase				:		List[str]     =   [
     "TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST",
     "TFWhisperForConditionalGeneration",
     "TFWhisperModel",
     "TFWhisperPreTrainedModel",
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase				:		str     =   [
     "FlaxWhisperForConditionalGeneration",
     "FlaxWhisperModel",
     "FlaxWhisperPreTrainedModel",
     "FlaxWhisperForAudioClassification",
 ]


if TYPE_CHECKING:
 from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
 from .feature_extraction_whisper import WhisperFeatureExtractor
 from .processing_whisper import WhisperProcessor
 from .tokenization_whisper import WhisperTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_whisper_fast import WhisperTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_whisper import (
      WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
      WhisperForAudioClassification,
      WhisperForConditionalGeneration,
      WhisperModel,
      WhisperPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_whisper import (
      TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFWhisperForConditionalGeneration,
      TFWhisperModel,
      TFWhisperPreTrainedModel,
  )

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_whisper import (
      FlaxWhisperForAudioClassification,
      FlaxWhisperForConditionalGeneration,
      FlaxWhisperModel,
      FlaxWhisperPreTrainedModel,
  )

else:
 import sys

 lowerCamelCase				:		Tuple     =   _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



