






import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType




class 			snake_case__   (							_a):

       '''simple docstring'''
       lowerCamelCase							:				str 				= ["""image_processor""", """tokenizer"""]
       lowerCamelCase							:				List[str] 				= """ViltImageProcessor"""
       lowerCamelCase							:				Union[str, Any] 				= ("""BertTokenizer""", """BertTokenizerFast""")



       def __init__(							self			,						a__=None			,						a__=None			,						**a__    ) ->      Any:






            '''simple docstring'''





            __snake_case			:Union[str, Any]          =						None
            if "feature_extractor" in kwargs:
                 warnings.warn(
                     """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
                     """ instead."""			,						snake_case_			,						)
                 __snake_case			:Union[str, Any]          =						kwargs.pop("""feature_extractor"""    )

            __snake_case			:List[Any]          =						image_processor if image_processor is not None else feature_extractor
            if image_processor is None:
                 raise ValueError("""You need to specify an `image_processor`."""    )
            if tokenizer is None:
                 raise ValueError("""You need to specify a `tokenizer`."""    )

            super().__init__(snake_case_			,						snake_case_    )
            __snake_case			:Any          =						self.image_processor



       def __call__(							self			,						a__			,						a__ = None			,						a__ = True			,						a__ = False			,						a__ = None			,						a__ = None			,						a__ = 0			,						a__ = None			,						a__ = None			,						a__ = None			,						a__ = False			,						a__ = False			,						a__ = False			,						a__ = False			,						a__ = True			,						a__ = None			,						**a__			,						) ->      BatchEncoding:






            '''simple docstring'''





            __snake_case			:Tuple          =						self.tokenizer(
                text=snake_case_			,						add_special_tokens=snake_case_			,						padding=snake_case_			,						truncation=snake_case_			,						max_length=snake_case_			,						stride=snake_case_			,						pad_to_multiple_of=snake_case_			,						return_token_type_ids=snake_case_			,						return_attention_mask=snake_case_			,						return_overflowing_tokens=snake_case_			,						return_special_tokens_mask=snake_case_			,						return_offsets_mapping=snake_case_			,						return_length=snake_case_			,						verbose=snake_case_			,						return_tensors=snake_case_			,						**snake_case_			,						)
            # add pixel_values + pixel_mask
            __snake_case			:Optional[int]          =						self.image_processor(snake_case_			,						return_tensors=snake_case_    )
            encoding.update(snake_case_    )

            return encoding



       def 					__lowercase						(							self			,						*a__			,						**a__    ) ->      Tuple:






            '''simple docstring'''





            return self.tokenizer.batch_decode(*snake_case_			,						**snake_case_    )



       def 					__lowercase						(							self			,						*a__			,						**a__    ) ->      Optional[Any]:






            '''simple docstring'''





            return self.tokenizer.decode(*snake_case_			,						**snake_case_    )



       @property
       def 					__lowercase						(							self    ) ->      List[str]:






            '''simple docstring'''





            __snake_case			:Optional[int]          =						self.tokenizer.model_input_names
            __snake_case			:Optional[int]          =						self.image_processor.model_input_names
            return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names    )    )



       @property
       def 					__lowercase						(							self    ) ->      Tuple:






            '''simple docstring'''





            warnings.warn(
                """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""			,						snake_case_			,						)
            return self.image_processor_class



       @property
       def 					__lowercase						(							self    ) ->      Optional[int]:






            '''simple docstring'''





            warnings.warn(
                """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""			,						snake_case_			,						)
            return self.image_processor










import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


lowerCamelCase__							=     """
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
"""




class 			snake_case__   (							unittest.TestCase	,    lowercase_):

       '''simple docstring'''



       def 					__lowercase						(							self    ) ->      List[str]:






            '''simple docstring'''





            __snake_case			:int          =						load_tool("""text-question-answering"""    )
            self.tool.setup()
            __snake_case			:Tuple          =						load_tool("""text-question-answering"""			,						remote=a__    )



       def 					__lowercase						(							self    ) ->      Any:






            '''simple docstring'''





            __snake_case			:List[str]          =						self.tool(a__			,						"""What did Hugging Face do in April 2021?"""    )
            self.assertEqual(a__			,						"""launched the BigScience Research Workshop"""    )



       def 					__lowercase						(							self    ) ->      Any:






            '''simple docstring'''





            __snake_case			:List[str]          =						self.remote_tool(a__			,						"""What did Hugging Face do in April 2021?"""    )
            self.assertEqual(a__			,						"""launched the BigScience Research Workshop"""    )



       def 					__lowercase						(							self    ) ->      Dict:






            '''simple docstring'''





            __snake_case			:Optional[int]          =						self.tool(text=a__			,						question="""What did Hugging Face do in April 2021?"""    )
            self.assertEqual(a__			,						"""launched the BigScience Research Workshop"""    )



       def 					__lowercase						(							self    ) ->      Tuple:






            '''simple docstring'''





            __snake_case			:List[str]          =						self.remote_tool(text=a__			,						question="""What did Hugging Face do in April 2021?"""    )
            self.assertEqual(a__			,						"""launched the BigScience Research Workshop"""    )


