




'''simple docstring'''


import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
				from PIL import Image

				from transformers import AutoProcessor, BlipaProcessor, BlipImageProcessor, GPTaTokenizer, PreTrainedTokenizerFast

@require_vision
class     A					(	unittest.TestCase					):







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


														"""simple docstring"""


														_a			  =       tempfile.mkdtemp()

														_a			  =       BlipImageProcessor()
														_a			  =       GPTaTokenizer.from_pretrained('''hf-internal-testing/tiny-random-GPT2Model'''      )

														_a			  =       BlipaProcessor(lowerCAmelCase_							,    lowerCAmelCase_      )

														processor.save_pretrained(self.tmpdirname      )







							def      __lowerCAmelCase    (						self :						Dict							,    **lowerCAmelCase_ :						int      )    ->							Any:


														"""simple docstring"""


														return AutoProcessor.from_pretrained(self.tmpdirname							,    **lowerCAmelCase_      ).tokenizer







							def      __lowerCAmelCase    (						self :						List[str]							,    **lowerCAmelCase_ :						Tuple      )    ->							Union[str, Any]:


														"""simple docstring"""


														return AutoProcessor.from_pretrained(self.tmpdirname							,    **lowerCAmelCase_      ).image_processor







							def      __lowerCAmelCase    (						self :						Optional[int]      )    ->							Optional[Any]:


														"""simple docstring"""


														shutil.rmtree(self.tmpdirname      )







							def      __lowerCAmelCase    (						self :						Any      )    ->							Union[str, Any]:


														"""simple docstring"""


														_a			  =       [np.random.randint(2_55							,    size=(3, 30, 4_00)							,    dtype=np.uinta      )]

														_a			  =       [Image.fromarray(np.moveaxis(lowerCAmelCase_							,    0							,    -1      )      ) for x in image_inputs]

														return image_inputs







							def      __lowerCAmelCase    (						self :						Dict      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       BlipaProcessor(tokenizer=self.get_tokenizer()							,    image_processor=self.get_image_processor()      )
														processor.save_pretrained(self.tmpdirname      )

														_a			  =       self.get_tokenizer(bos_token='''(BOS)'''							,    eos_token='''(EOS)'''      )
														_a			  =       self.get_image_processor(do_normalize=lowerCAmelCase_							,    padding_value=1.0      )

														_a			  =       BlipaProcessor.from_pretrained(
														    self.tmpdirname							,    bos_token='''(BOS)'''							,    eos_token='''(EOS)'''							,    do_normalize=lowerCAmelCase_							,    padding_value=1.0      )

														self.assertEqual(processor.tokenizer.get_vocab()							,    tokenizer_add_kwargs.get_vocab()      )
														self.assertIsInstance(processor.tokenizer							,    lowerCAmelCase_      )

														self.assertEqual(processor.image_processor.to_json_string()							,    image_processor_add_kwargs.to_json_string()      )
														self.assertIsInstance(processor.image_processor							,    lowerCAmelCase_      )







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


														"""simple docstring"""


														_a			  =       self.get_image_processor()
														_a			  =       self.get_tokenizer()

														_a			  =       BlipaProcessor(tokenizer=lowerCAmelCase_							,    image_processor=lowerCAmelCase_      )

														_a			  =       self.prepare_image_inputs()

														_a			  =       image_processor(lowerCAmelCase_							,    return_tensors='''np'''      )
														_a			  =       processor(images=lowerCAmelCase_							,    return_tensors='''np'''      )

														for key in input_feat_extract.keys():
																					self.assertAlmostEqual(input_feat_extract[key].sum()							,    input_processor[key].sum()							,    delta=1e-2      )







							def      __lowerCAmelCase    (						self :						Optional[Any]      )    ->							Dict:


														"""simple docstring"""


														_a			  =       self.get_image_processor()
														_a			  =       self.get_tokenizer()

														_a			  =       BlipaProcessor(tokenizer=lowerCAmelCase_							,    image_processor=lowerCAmelCase_      )

														_a			  =       '''lower newer'''

														_a			  =       processor(text=lowerCAmelCase_      )

														_a			  =       tokenizer(lowerCAmelCase_							,    return_token_type_ids=lowerCAmelCase_      )

														for key in encoded_tok.keys():
																					self.assertListEqual(encoded_tok[key]							,    encoded_processor[key]      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							List[str]:


														"""simple docstring"""


														_a			  =       self.get_image_processor()
														_a			  =       self.get_tokenizer()

														_a			  =       BlipaProcessor(tokenizer=lowerCAmelCase_							,    image_processor=lowerCAmelCase_      )

														_a			  =       '''lower newer'''
														_a			  =       self.prepare_image_inputs()

														_a			  =       processor(text=lowerCAmelCase_							,    images=lowerCAmelCase_      )

														self.assertListEqual(list(inputs.keys()      )							,    ['''pixel_values''', '''input_ids''', '''attention_mask''']      )

														# test if it raises when no input is passed
														with pytest.raises(lowerCAmelCase_      ):
																					processor()







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       self.get_image_processor()
														_a			  =       self.get_tokenizer()

														_a			  =       BlipaProcessor(tokenizer=lowerCAmelCase_							,    image_processor=lowerCAmelCase_      )

														_a			  =       [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

														_a			  =       processor.batch_decode(lowerCAmelCase_      )
														_a			  =       tokenizer.batch_decode(lowerCAmelCase_      )

														self.assertListEqual(lowerCAmelCase_							,    lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						Dict      )    ->							Optional[int]:


														"""simple docstring"""


														_a			  =       self.get_image_processor()
														_a			  =       self.get_tokenizer()

														_a			  =       BlipaProcessor(tokenizer=lowerCAmelCase_							,    image_processor=lowerCAmelCase_      )

														_a			  =       '''lower newer'''
														_a			  =       self.prepare_image_inputs()

														_a			  =       processor(text=lowerCAmelCase_							,    images=lowerCAmelCase_      )

														# For now the processor supports only ['pixel_values', 'input_ids', 'attention_mask']
														self.assertListEqual(list(inputs.keys()      )							,    ['''pixel_values''', '''input_ids''', '''attention_mask''']      )







'''simple docstring'''


import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


_snake_case   :   str     							=	'\nHugging 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.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn 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]\n'

class     A					(	unittest.TestCase  ,_a					):







							def      __lowerCAmelCase    (						self :						Any      )    ->							Dict:


														"""simple docstring"""


														_a			  =       load_tool('''text-question-answering'''      )
														self.tool.setup()
														_a			  =       load_tool('''text-question-answering'''							,    remote=lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							Optional[int]:


														"""simple docstring"""


														_a			  =       self.tool(lowerCAmelCase_							,    '''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						Union[str, Any]      )    ->							Dict:


														"""simple docstring"""


														_a			  =       self.remote_tool(lowerCAmelCase_							,    '''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							List[str]:


														"""simple docstring"""


														_a			  =       self.tool(text=lowerCAmelCase_							,    question='''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						int      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       self.remote_tool(text=lowerCAmelCase_							,    question='''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )

