"""simple docstring"""






import re
import string

import numpy as np

import datasets


__lowerCAmelCase    :       List[str]					     ="\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n"

__lowerCAmelCase    :       List[str]					     ="\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results[\"exact_match\"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results[\"exact_match\"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results[\"exact_match\"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results[\"exact_match\"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"The cat sat on the mat.\", \"Theaters are great.\", \"It's like comparing oranges and apples.\"]\n    >>> preds = [\"The cat sat on the mat?\", \"Theaters are great.\", \"It's like comparing apples and oranges.\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results[\"exact_match\"], 1))\n    33.3\n\n"

__lowerCAmelCase    :       Optional[Any]					     ="\n"





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION  ,    _KWARGS_DESCRIPTION	)
class  _A						(       datasets.Metric	):

      def 				A__       (						self						):







            """simple docstring"""



            return datasets.MetricInfo(
                description=_DESCRIPTION		,       citation=_CITATION		,       inputs_description=_KWARGS_DESCRIPTION		,       features=datasets.Features(
                    {
                        """predictions""": datasets.Value("""string"""		,       id="""sequence"""						),
                        """references""": datasets.Value("""string"""		,       id="""sequence"""						),
                    }						)		,       reference_urls=[]		,       )







      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase=None		,       __lowerCAmelCase=False		,       __lowerCAmelCase=False		,       __lowerCAmelCase=False		,       ):







            """simple docstring"""



            if regexes_to_ignore is not None:
                  for s in regexes_to_ignore:
                        lowercase														=	np.array([re.sub(__lowerCAmelCase		,       """"""		,       __lowerCAmelCase						) for x in predictions]						)
                        lowercase														=	np.array([re.sub(__lowerCAmelCase		,       """"""		,       __lowerCAmelCase						) for x in references]						)
            else:
                  lowercase														=	np.asarray(__lowerCAmelCase						)
                  lowercase														=	np.asarray(__lowerCAmelCase						)

            if ignore_case:
                  lowercase														=	np.char.lower(__lowerCAmelCase						)
                  lowercase														=	np.char.lower(__lowerCAmelCase						)

            if ignore_punctuation:
                  lowercase														=	string.punctuation.maketrans(""""""		,       """"""		,       string.punctuation						)
                  lowercase														=	np.char.translate(__lowerCAmelCase		,       table=__lowerCAmelCase						)
                  lowercase														=	np.char.translate(__lowerCAmelCase		,       table=__lowerCAmelCase						)

            if ignore_numbers:
                  lowercase														=	string.digits.maketrans(""""""		,       """"""		,       string.digits						)
                  lowercase														=	np.char.translate(__lowerCAmelCase		,       table=__lowerCAmelCase						)
                  lowercase														=	np.char.translate(__lowerCAmelCase		,       table=__lowerCAmelCase						)

            lowercase														=	predictions == references

            return {"exact_match": np.mean(__lowerCAmelCase						) * 100}








"""simple docstring"""






from pathlib import Path
from typing import List

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import get_tests_dir, is_tool_test
from transformers.tools.agent_types import AGENT_TYPE_MAPPING, AgentAudio, AgentImage, AgentText


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image


_lowercase : Union[str, Any]      						=						["text", "image", "audio"]






def      snake_case__   (		__lowerCamelCase				:    List[str]	):
			"""simple docstring"""
			lowerCamelCase__		:		Union[str, Any]			=[]

			for input_type in input_types:
						if input_type == "text":
									inputs.append('''Text input'''	)
						elif input_type == "image":
									inputs.append(
									    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''	)	) / '''000000039769.png'''	).resize((512, 512)	)	)
						elif input_type == "audio":
									inputs.append(torch.ones(3000	)	)
						elif isinstance(__lowerCamelCase							,		__lowerCamelCase	):
									inputs.append(create_inputs(__lowerCamelCase	)	)
						else:
									raise ValueError(f'''Invalid type requested: {input_type}'''	)

			return inputs






def      snake_case__   (		__lowerCamelCase				:    List	):
			"""simple docstring"""
			lowerCamelCase__		:		Tuple			=[]

			for output in outputs:
						if isinstance(__lowerCamelCase							,		(str, AgentText)	):
									output_types.append('''text'''	)
						elif isinstance(__lowerCamelCase							,		(Image.Image, AgentImage)	):
									output_types.append('''image'''	)
						elif isinstance(__lowerCamelCase							,		(torch.Tensor, AgentAudio)	):
									output_types.append('''audio'''	)
						else:
									raise ValueError(f'''Invalid output: {output}'''	)

			return output_types

@is_tool_test
class        __SCREAMING_SNAKE_CASE	:


					'''simple docstring'''





					def 		snake_case       (       self							:  Any     )->					Optional[Any]:
								self.assertTrue(hasattr(self.tool,  '''inputs'''     )     )
								self.assertTrue(hasattr(self.tool,  '''outputs'''     )     )

								lowerCamelCase__		:		Tuple			=self.tool.inputs
								for _input in inputs:
											if isinstance(_input,  lowerCamelCase     ):
														for __input in _input:
																	self.assertTrue(__input in authorized_types     )
											else:
														self.assertTrue(_input in authorized_types     )

								lowerCamelCase__		:		Optional[Any]			=self.tool.outputs
								for _output in outputs:
											self.assertTrue(_output in authorized_types     )



					def 		snake_case       (       self							:  Optional[int]     )->					Union[str, Any]:
								lowerCamelCase__		:		Optional[int]			=create_inputs(self.tool.inputs     )
								lowerCamelCase__		:		List[Any]			=self.tool(*lowerCamelCase     )

								# There is a single output
								if len(self.tool.outputs     ) == 1:
											lowerCamelCase__		:		Optional[int]			=[outputs]

								self.assertListEqual(output_types(lowerCamelCase     ),  self.tool.outputs     )



					def 		snake_case       (       self							:  Union[str, Any]     )->					List[str]:
								self.assertTrue(hasattr(self.tool,  '''description'''     )     )
								self.assertTrue(hasattr(self.tool,  '''default_checkpoint'''     )     )
								self.assertTrue(self.tool.description.startswith('''This is a tool that'''     )     )



					def 		snake_case       (       self							:  Union[str, Any]     )->					str:
								lowerCamelCase__		:		List[str]			=create_inputs(self.tool.inputs     )
								lowerCamelCase__		:		Optional[Any]			=self.tool(*lowerCamelCase     )

								if not isinstance(lowerCamelCase,  lowerCamelCase     ):
											lowerCamelCase__		:		Any			=[outputs]

								self.assertEqual(len(lowerCamelCase     ),  len(self.tool.outputs     )     )

								for output, output_type in zip(lowerCamelCase,  self.tool.outputs     ):
											lowerCamelCase__		:		List[Any]			=AGENT_TYPE_MAPPING[output_type]
											self.assertTrue(isinstance(lowerCamelCase,  lowerCamelCase     )     )




					def 		snake_case       (       self							:  Optional[Any]     )->					List[Any]:
								lowerCamelCase__		:		Optional[Any]			=create_inputs(self.tool.inputs     )

								lowerCamelCase__		:		List[str]			=[]

								for _input, input_type in zip(lowerCamelCase,  self.tool.inputs     ):
											if isinstance(lowerCamelCase,  lowerCamelCase     ):
														_inputs.append([AGENT_TYPE_MAPPING[_input_type](_input     ) for _input_type in input_type]     )
											else:
														_inputs.append(AGENT_TYPE_MAPPING[input_type](_input     )     )

        # Should not raise an error
								lowerCamelCase__		:		Any			=self.tool(*lowerCamelCase     )

								if not isinstance(lowerCamelCase,  lowerCamelCase     ):
											lowerCamelCase__		:		Optional[int]			=[outputs]

								self.assertEqual(len(lowerCamelCase     ),  len(self.tool.outputs     )     )




