





'''simple docstring'''







from __future__ import annotations

from collections import deque


class 					__a      :

							def __init__(							self							:     List[Any]       ,     __magic_name__							:     list[str]   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      list[dict]     						=  []
													self.adlist.append(
													    {'''value''': '''''', '''next_states''': [], '''fail_state''': 0, '''output''': []}   )

													for keyword in keywords:
																			self.add_keyword(__magic_name__   )
													self.set_fail_transitions()

							def     UpperCAmelCase__	(							self							:     str       ,     __magic_name__							:     int       ,     __magic_name__							:     str   )					->       int | None:







													"""simple docstring"""
													for state in self.adlist[current_state]["next_states"]:
																			if char == self.adlist[state]["value"]:
																									return state
													return None

							def     UpperCAmelCase__	(							self							:     Optional[int]       ,     __magic_name__							:     str   )					->       None:







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  0
													for character in keyword:
																			UpperCAmelCase_			:      List[Any]     						=  self.find_next_state(__magic_name__       ,     __magic_name__   )
																			if next_state is None:
																									self.adlist.append(
																									    {
																									        '''value''': character,
																									        '''next_states''': [],
																									        '''fail_state''': 0,
																									        '''output''': [],
																									    }   )
																									self.adlist[current_state]["next_states"].append(len(self.adlist   ) - 1   )
																									UpperCAmelCase_			:      Optional[Any]     						=  len(self.adlist   ) - 1
																			else:
																									UpperCAmelCase_			:      Optional[Any]     						=  next_state
													self.adlist[current_state]["output"].append(__magic_name__   )

							def     UpperCAmelCase__	(							self							:     str   )					->       None:







													"""simple docstring"""
													UpperCAmelCase_			:      deque     						=  deque()
													for node in self.adlist[0]["next_states"]:
																			q.append(__magic_name__   )
																			UpperCAmelCase_			:      Any     						=  0
													while q:
																			UpperCAmelCase_			:      str     						=  q.popleft()
																			for child in self.adlist[r]["next_states"]:
																									q.append(__magic_name__   )
																									UpperCAmelCase_			:      str     						=  self.adlist[r]['''fail_state''']
																									while (
																									    self.find_next_state(__magic_name__       ,     self.adlist[child]['''value''']   ) is None
																									    and state != 0
																									):
																															UpperCAmelCase_			:      Tuple     						=  self.adlist[state]['''fail_state''']
																									UpperCAmelCase_			:      Union[str, Any]     						=  self.find_next_state(
																									    __magic_name__       ,     self.adlist[child]['''value''']   )
																									if self.adlist[child]["fail_state"] is None:
																															UpperCAmelCase_			:      List[Any]     						=  0
																									UpperCAmelCase_			:      Optional[Any]     						=  (
																									    self.adlist[child]['''output''']
																									    + self.adlist[self.adlist[child]['''fail_state''']]['''output''']
																									)



							def     UpperCAmelCase__	(							self							:     Optional[int]       ,     __magic_name__							:     str   )					->       dict[str, list[int]]:







													"""simple docstring"""
													UpperCAmelCase_			:      dict     						=  {}  # returns a dict with keywords and list of its occurrences
													UpperCAmelCase_			:      Optional[Any]     						=  0
													for i in range(len(__magic_name__   )   ):
																			while (
																			    self.find_next_state(__magic_name__       ,     string[i]   ) is None
																			    and current_state != 0
																			):
																									UpperCAmelCase_			:      Tuple     						=  self.adlist[current_state]['''fail_state''']
																			UpperCAmelCase_			:      List[Any]     						=  self.find_next_state(__magic_name__       ,     string[i]   )
																			if next_state is None:
																									UpperCAmelCase_			:      List[Any]     						=  0
																			else:
																									UpperCAmelCase_			:      Optional[int]     						=  next_state
																									for key in self.adlist[current_state]["output"]:
																															if key not in result:
																																					UpperCAmelCase_			:      Any     						=  []
																															result[key].append(i - len(__magic_name__   ) + 1   )
													return result


if __name__ == "__main__":
					import doctest

					doctest.testmod()












'''simple docstring'''







# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool


class 					__a      (lowerCamelCase     ):
							__a					:   List[Any]									=       "openai/whisper-base"
							__a					:   Optional[Any]									=       (
							    "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the "
							    "transcribed text."
							)
							__a					:   Any									=       "transcriber"
							__a					:   str									=       WhisperProcessor
							__a					:   List[Any]									=       WhisperForConditionalGeneration

							__a					:   int									=       ["audio"]
							__a					:   Optional[Any]									=       ["text"]

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







													"""simple docstring"""
													return self.pre_processor(__magic_name__       ,     return_tensors='''pt'''   ).input_features

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     Dict   )					->       Tuple:







													"""simple docstring"""
													return self.model.generate(inputs=__magic_name__   )



							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Dict   )					->       str:







													"""simple docstring"""
													return self.pre_processor.batch_decode(__magic_name__       ,     skip_special_tokens=__magic_name__   )[0]





