
from queue import Queue
from typing import TYPE_CHECKING, Optional


if TYPE_CHECKING:
	from ..models.auto import AutoTokenizer







class        A_   :




	'''simple docstring'''


	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case       ):
		raise NotImplementedError()





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		raise NotImplementedError()







class        A_   (			__a   ):




	'''simple docstring'''


	def __init__(       self		,    snake_case		,    snake_case = False		,    **snake_case       ):
		lowercase       =    tokenizer
		lowercase       =    skip_prompt
		lowercase       =    decode_kwargs

		# variables used in the streaming process
		lowercase       =    []
		lowercase       =    0
		lowercase       =    True





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case       ):
		if len(value.shape       ) > 1 and value.shape[0] > 1:
			raise ValueError('TextStreamer only supports batch size 1'       )
		elif len(value.shape       ) > 1:
			lowercase       =    value[0]

		if self.skip_prompt and self.next_tokens_are_prompt:
			lowercase       =    False
			return

		# Add the new token to the cache and decodes the entire thing.
		self.token_cache.extend(value.tolist()       )
		lowercase       =    self.tokenizer.decode(self.token_cache		,    **self.decode_kwargs       )

		# After the symbol for a new line, we flush the cache.
		if text.endswith('\n'       ):
			lowercase       =    text[self.print_len :]
			lowercase       =    []
			lowercase       =    0
		# If the last token is a CJK character, we print the characters.
		elif len(_UpperCamelCase       ) > 0 and self._is_chinese_char(ord(text[-1]       )       ):
			lowercase       =    text[self.print_len :]
			self.print_len += len(_UpperCamelCase       )
		# Otherwise, prints until the last space char (simple heuristic to avoid printing incomplete words,
		# which may change with the subsequent token -- there are probably smarter ways to do this!)
		else:
			lowercase       =    text[self.print_len : text.rfind(' '       ) + 1]
			self.print_len += len(_UpperCamelCase       )

		self.on_finalized_text(_UpperCamelCase       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		# Flush the cache, if it exists
		if len(self.token_cache       ) > 0:
			lowercase       =    self.tokenizer.decode(self.token_cache		,    **self.decode_kwargs       )
			lowercase       =    text[self.print_len :]
			lowercase       =    []
			lowercase       =    0
		else:
			lowercase       =    ''

		lowercase       =    True
		self.on_finalized_text(_UpperCamelCase		,    stream_end=_UpperCamelCase       )





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case = False       ):
		print(_UpperCamelCase		,    flush=_UpperCamelCase		,    end='' if not stream_end else None       )





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case       ):
		# This defines a "chinese character" as anything in the CJK Unicode block:
		#   https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)
		#
		# Note that the CJK Unicode block is NOT all Japanese and Korean characters,
		# despite its name. The modern Korean Hangul alphabet is a different block,
		# as is Japanese Hiragana and Katakana. Those alphabets are used to write
		# space-separated words, so they are not treated specially and handled
		# like the all of the other languages.
		if (
		    (cp >= 0X4_e_0_0 and cp <= 0X9_f_f_f)
		    or (cp >= 0X3_4_0_0 and cp <= 0X4_d_b_f)  #
		    or (cp >= 0X2_0_0_0_0 and cp <= 0X2_a_6_d_f)  #
		    or (cp >= 0X2_a_7_0_0 and cp <= 0X2_b_7_3_f)  #
		    or (cp >= 0X2_b_7_4_0 and cp <= 0X2_b_8_1_f)  #
		    or (cp >= 0X2_b_8_2_0 and cp <= 0X2_c_e_a_f)  #
		    or (cp >= 0Xf_9_0_0 and cp <= 0Xf_a_f_f)
		    or (cp >= 0X2_f_8_0_0 and cp <= 0X2_f_a_1_f)  #
		):  #
			return True

		return False







class        A_   (			__a   ):




	'''simple docstring'''


	def __init__(       self		,    snake_case		,    snake_case = False		,    snake_case = None		,    **snake_case       ):
		super().__init__(_UpperCamelCase		,    _UpperCamelCase		,    **_UpperCamelCase       )
		lowercase       =    Queue()
		lowercase       =    None
		lowercase       =    timeout





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case		,    snake_case = False       ):
		self.text_queue.put(_UpperCamelCase		,    timeout=self.timeout       )
		if stream_end:
			self.text_queue.put(self.stop_signal		,    timeout=self.timeout       )





	def __iter__(       self       ):
		return self





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.text_queue.get(timeout=self.timeout       )
		if value == self.stop_signal:
			raise StopIteration()
		else:
			return value



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_tf_available,
    is_torch_available,
)


_A   =     {
    "configuration_speech_to_text": ["SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP", "Speech2TextConfig"],
    "processing_speech_to_text": ["Speech2TextProcessor"],
}

try:
			if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     ["Speech2TextTokenizer"]

try:
			if not is_speech_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     ["Speech2TextFeatureExtractor"]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     [
			    "TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "TFSpeech2TextForConditionalGeneration",
			    "TFSpeech2TextModel",
			    "TFSpeech2TextPreTrainedModel",
			]

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     [
			    "SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "Speech2TextForConditionalGeneration",
			    "Speech2TextModel",
			    "Speech2TextPreTrainedModel",
			]


if TYPE_CHECKING:
			from .configuration_speech_to_text import SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextConfig
			from .processing_speech_to_text import SpeechaTextProcessor

			try:
						if not is_sentencepiece_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_speech_to_text import SpeechaTextTokenizer

			try:
						if not is_speech_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .feature_extraction_speech_to_text import SpeechaTextFeatureExtractor

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_speech_to_text import (
						    TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFSpeechaTextForConditionalGeneration,
						    TFSpeechaTextModel,
						    TFSpeechaTextPreTrainedModel,
						)

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_speech_to_text import (
						    SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    SpeechaTextForConditionalGeneration,
						    SpeechaTextModel,
						    SpeechaTextPreTrainedModel,
						)

else:
			import sys

			_A   =     _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



