


# 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 typing import TYPE_CHECKING

from ..utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__SCREAMING_SNAKE_CASE	:							List[Any]           =  {
    "agents": ["Agent", "AzureOpenAiAgent", "HfAgent", "LocalAgent", "OpenAiAgent"],
    "base": ["PipelineTool", "RemoteTool", "Tool", "launch_gradio_demo", "load_tool"],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__SCREAMING_SNAKE_CASE	:							Dict           =  ["DocumentQuestionAnsweringTool"]
		__SCREAMING_SNAKE_CASE	:							Union[str, Any]           =  ["ImageCaptioningTool"]
		__SCREAMING_SNAKE_CASE	:							Optional[int]           =  ["ImageQuestionAnsweringTool"]
		__SCREAMING_SNAKE_CASE	:							int           =  ["ImageSegmentationTool"]
		__SCREAMING_SNAKE_CASE	:							Any           =  ["SpeechToTextTool"]
		__SCREAMING_SNAKE_CASE	:							Tuple           =  ["TextClassificationTool"]
		__SCREAMING_SNAKE_CASE	:							List[str]           =  ["TextQuestionAnsweringTool"]
		__SCREAMING_SNAKE_CASE	:							Tuple           =  ["TextSummarizationTool"]
		__SCREAMING_SNAKE_CASE	:							Tuple           =  ["TextToSpeechTool"]
		__SCREAMING_SNAKE_CASE	:							int           =  ["TranslationTool"]

if TYPE_CHECKING:
		from .agents import Agent, AzureOpenAiAgent, HfAgent, LocalAgent, OpenAiAgent
		from .base import PipelineTool, RemoteTool, Tool, launch_gradio_demo, load_tool

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .document_question_answering import DocumentQuestionAnsweringTool
				from .image_captioning import ImageCaptioningTool
				from .image_question_answering import ImageQuestionAnsweringTool
				from .image_segmentation import ImageSegmentationTool
				from .speech_to_text import SpeechToTextTool
				from .text_classification import TextClassificationTool
				from .text_question_answering import TextQuestionAnsweringTool
				from .text_summarization import TextSummarizationTool
				from .text_to_speech import TextToSpeechTool
				from .translation import TranslationTool
else:
		import sys

		__SCREAMING_SNAKE_CASE	:							Optional[Any]           =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


_UpperCAmelCase   :					str    =			100_000_000_000
_UpperCAmelCase   :					Optional[int]    =			10_000

_UpperCAmelCase  ,_UpperCAmelCase   :					Optional[int]    =			os.path.split(__file__)
_UpperCAmelCase   :					Optional[int]    =			os.path.join(RESULTS_BASEPATH, "results", RESULTS_FILENAME.replace(".py", ".json"))


def  A			(   lowercase       ,			lowercase					)  ->    datasets.Dataset:
		'''simple docstring'''

		UpperCamelCase            =	pa.Table.from_pydict({'col': [0] * chunk_size}					)
		UpperCamelCase            =	pa.concat_tables([table] * (num_examples // chunk_size)					)
		return datasets.Dataset(lowercase       ,			fingerprint='table_100B'					)


@dataclass
class 							lowercase   :
		__lowercase			:			int
		__lowercase			:			int
		__lowercase			:			int
		__lowercase			:			int



		def __UpperCamelCase					(					self			)    ->   Optional[int]:
				"""simple docstring"""
				UpperCamelCase            =	np.random.default_rng(self.seed			)
				UpperCamelCase            =	rng.integers(low=self.low							, high=self.high							, size=self.size			).tolist()



		def __iter__(					self			)    ->   List[str]:
				"""simple docstring"""
				return iter(self._sampled_values			)



		def __len__(					self			)    ->   int:
				"""simple docstring"""
				return self.size






@get_duration
def  A			(   lowercase					)  ->    List[Any]:
		'''simple docstring'''

		UpperCamelCase            =	dataset[0]


@get_duration
def  A			(   lowercase					)  ->    Any:
		'''simple docstring'''

		UpperCamelCase            =	dataset[-1]


@get_duration
def  A			(   lowercase					)  ->    List[Any]:
		'''simple docstring'''

		UpperCamelCase            =	dataset[range(len(lowercase					) // 2       ,			len(lowercase					) // 2 + 1_024					)]


@get_duration
def  A			(   lowercase					)  ->    Any:
		'''simple docstring'''

		UpperCamelCase            =	dataset[RandIter(0       ,			len(lowercase					)       ,			1_024       ,			seed=42					)]


def  A			(   )  ->    List[Any]:
		'''simple docstring'''

		UpperCamelCase            =	{'num examples': SPEED_TEST_N_EXAMPLES}
		UpperCamelCase            =	(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
		print('generating dataset'					)
		UpperCamelCase            =	generate_100B_dataset(num_examples=lowercase       ,			chunk_size=lowercase					)
		print('Functions'					)
		for func in functions:
				print(func.__name__					)
				UpperCamelCase            =	func(lowercase					)

		with open(lowercase       ,			'wb'					) as f:
				f.write(json.dumps(lowercase					).encode('utf-8'					)					)


if __name__ == "__main__":  # useful to run the profiler
					benchmark_table_100B()
