





'''simple docstring'''







import time
from contextlib import contextmanager
from pathlib import Path

import pytest
import requests
from huggingface_hub.hf_api import HfApi, HfFolder


snake_case_     :       str						=  "__DUMMY_TRANSFORMERS_USER__"
snake_case_     :       Optional[Any]						=  "Dummy User"
snake_case_     :       Optional[int]						=  "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"

snake_case_     :       Any						=  "https://hub-ci.huggingface.co"
snake_case_     :       List[str]						=  CI_HUB_ENDPOINT + "/datasets/{repo_id}/resolve/{revision}/{path}"
snake_case_     :       Tuple						=  CI_HUB_ENDPOINT + "/{repo_id}/resolve/{revision}/{filename}"
snake_case_     :       List[str]						=  Path("~/.huggingface/hub_ci_token").expanduser()





@pytest.fixture
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Optional[Any]   ) ->	List[str]:
						monkeypatch.setattr(
						    '''huggingface_hub.file_download.HUGGINGFACE_CO_URL_TEMPLATE''',			SCREAMING_SNAKE_CASE__   )





@pytest.fixture
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Optional[int]   ) ->	Dict:
						monkeypatch.setattr('''datasets.config.HF_ENDPOINT''',			SCREAMING_SNAKE_CASE__   )
						monkeypatch.setattr('''datasets.config.HUB_DATASETS_URL''',			SCREAMING_SNAKE_CASE__   )





@pytest.fixture
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Dict   ) ->	Optional[Any]:
						monkeypatch.setattr('''huggingface_hub.hf_api.HfFolder.path_token''',			SCREAMING_SNAKE_CASE__   )





@pytest.fixture
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			str,			SCREAMING_SNAKE_CASE__      :			List[str]   ) ->	Dict:
						HfFolder.save_token(SCREAMING_SNAKE_CASE__   )
						yield
						HfFolder.delete_token()





@pytest.fixture(scope='''session'''   )
def        lowerCamelCase_      (  ) ->	Dict:
						return HfApi(endpoint=SCREAMING_SNAKE_CASE__   )





@pytest.fixture(scope='''session'''   )
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			HfApi   ) ->	List[str]:
						UpperCAmelCase_			:      Dict     						=  HfFolder.get_token()
						HfFolder.save_token(SCREAMING_SNAKE_CASE__   )
						yield CI_HUB_USER_TOKEN
						if previous_token is not None:
												HfFolder.save_token(SCREAMING_SNAKE_CASE__   )





@pytest.fixture
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			List[str]   ) ->	Dict:
						def _cleanup_repo(SCREAMING_SNAKE_CASE__      :			Optional[Any]   ):
												hf_api.delete_repo(SCREAMING_SNAKE_CASE__,			token=SCREAMING_SNAKE_CASE__,			repo_type='''dataset'''   )

						return _cleanup_repo





@pytest.fixture
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			List[Any]   ) ->	Optional[Any]:
						@contextmanager
						def _temporary_repo(SCREAMING_SNAKE_CASE__      :			List[str]   ):
												try:
																		yield repo_id
												finally:
																		cleanup_repo(SCREAMING_SNAKE_CASE__   )

						return _temporary_repo





@pytest.fixture(scope='''session'''   )
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			HfApi,			SCREAMING_SNAKE_CASE__      :			Dict,			SCREAMING_SNAKE_CASE__      :			List[str]   ) ->	Any:
						UpperCAmelCase_			:      Optional[Any]     						=  F"""repo_txt_data-{int(time.time() * 10E3   )}"""
						UpperCAmelCase_			:      Tuple     						=  F"""{CI_HUB_USER}/{repo_name}"""
						hf_api.create_repo(SCREAMING_SNAKE_CASE__,			token=SCREAMING_SNAKE_CASE__,			repo_type='''dataset''',			private=SCREAMING_SNAKE_CASE__   )
						hf_api.upload_file(
						    token=SCREAMING_SNAKE_CASE__,			path_or_fileobj=str(SCREAMING_SNAKE_CASE__   ),			path_in_repo='''data/text_data.txt''',			repo_id=SCREAMING_SNAKE_CASE__,			repo_type='''dataset''',			)
						yield repo_id
						try:
												hf_api.delete_repo(SCREAMING_SNAKE_CASE__,			token=SCREAMING_SNAKE_CASE__,			repo_type='''dataset'''   )
						except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
												pass





@pytest.fixture()
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			List[str],			SCREAMING_SNAKE_CASE__      :			Dict,			SCREAMING_SNAKE_CASE__      :			str   ) ->	Dict:
						return hf_private_dataset_repo_txt_data_





@pytest.fixture(scope='''session'''   )
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			HfApi,			SCREAMING_SNAKE_CASE__      :			Dict,			SCREAMING_SNAKE_CASE__      :			List[str]   ) ->	Union[str, Any]:
						UpperCAmelCase_			:      Dict     						=  F"""repo_zipped_txt_data-{int(time.time() * 10E3   )}"""
						UpperCAmelCase_			:      str     						=  F"""{CI_HUB_USER}/{repo_name}"""
						hf_api.create_repo(SCREAMING_SNAKE_CASE__,			token=SCREAMING_SNAKE_CASE__,			repo_type='''dataset''',			private=SCREAMING_SNAKE_CASE__   )
						hf_api.upload_file(
						    token=SCREAMING_SNAKE_CASE__,			path_or_fileobj=str(SCREAMING_SNAKE_CASE__   ),			path_in_repo='''data.zip''',			repo_id=SCREAMING_SNAKE_CASE__,			repo_type='''dataset''',			)
						yield repo_id
						try:
												hf_api.delete_repo(SCREAMING_SNAKE_CASE__,			token=SCREAMING_SNAKE_CASE__,			repo_type='''dataset'''   )
						except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
												pass





@pytest.fixture()
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Optional[Any],			SCREAMING_SNAKE_CASE__      :			Optional[Any],			SCREAMING_SNAKE_CASE__      :			str   ) ->	Optional[Any]:
						return hf_private_dataset_repo_zipped_txt_data_





@pytest.fixture(scope='''session'''   )
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			HfApi,			SCREAMING_SNAKE_CASE__      :			Dict,			SCREAMING_SNAKE_CASE__      :			Any   ) ->	Tuple:
						UpperCAmelCase_			:      str     						=  F"""repo_zipped_img_data-{int(time.time() * 10E3   )}"""
						UpperCAmelCase_			:      Dict     						=  F"""{CI_HUB_USER}/{repo_name}"""
						hf_api.create_repo(SCREAMING_SNAKE_CASE__,			token=SCREAMING_SNAKE_CASE__,			repo_type='''dataset''',			private=SCREAMING_SNAKE_CASE__   )
						hf_api.upload_file(
						    token=SCREAMING_SNAKE_CASE__,			path_or_fileobj=str(SCREAMING_SNAKE_CASE__   ),			path_in_repo='''data.zip''',			repo_id=SCREAMING_SNAKE_CASE__,			repo_type='''dataset''',			)
						yield repo_id
						try:
												hf_api.delete_repo(SCREAMING_SNAKE_CASE__,			token=SCREAMING_SNAKE_CASE__,			repo_type='''dataset'''   )
						except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
												pass





@pytest.fixture()
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Any,			SCREAMING_SNAKE_CASE__      :			Dict,			SCREAMING_SNAKE_CASE__      :			List[str]   ) ->	Any:
						return hf_private_dataset_repo_zipped_img_data_












'''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]





