



'''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.auto import AutoModelForSeqaSeqLM, AutoTokenizer
from .base import PipelineTool


lowercase_			=  "Here is a text containing a lot of information: '''{text}'''.\n\nCan you answer this question about the text: '{question}'"






class __A      (  A						):



 '''simple docstring'''







 __lowerCamelCase   :	Dict										=	'google/flan-t5-base'
 __lowerCamelCase   :	Optional[int]										=	(
     'This is a tool that answers questions related to a text. It takes two arguments named `text`, which is the '
     'text where to find the answer, and `question`, which is the question, and returns the answer to the question.'
 )
 __lowerCamelCase   :	Union[str, Any]										=	'text_qa'
 __lowerCamelCase   :	List[str]										=	AutoTokenizer
 __lowerCamelCase   :	List[str]										=	AutoModelForSeqaSeqLM

 __lowerCamelCase   :	List[Any]										=	['text', 'text']
 __lowerCamelCase   :	int										=	['text']



 def  a__  (self			,       A			,       A	)   ->					List[str]:


      """simple docstring"""



      _a     =  QA_PROMPT.format(text=A			,       question=A	)
      return self.pre_processor(A			,       return_tensors='''pt'''	)



 def  a__  (self			,       A	)   ->					List[Any]:


      """simple docstring"""



      _a     =  self.model.generate(**A	)

      _a  ,   _a     =  inputs['''input_ids'''].shape
      _a     =  output_ids.shape[0]

      return output_ids.reshape(A			,       out_b // in_b			,       *output_ids.shape[1:]	)[0][0]



 def  a__  (self			,       A	)   ->					Optional[int]:


      """simple docstring"""



      return self.pre_processor.decode(A			,       skip_special_tokens=A			,       clean_up_tokenization_spaces=A	)








'''simple docstring'''





import importlib.metadata
import sys

from transformers.testing_utils import TestCasePlus
from transformers.utils.versions import require_version, require_version_core


lowercase_			=  importlib.metadata.version("numpy")
lowercase_			=  ".".join([str(x) for x in sys.version_info[:3]])






class __A      (  A						):



 '''simple docstring'''







 def  a__  (self	)   ->					Any:


      """simple docstring"""



      require_version_core('''numpy<1000.4.5'''	)
      require_version_core('''numpy<1000.4'''	)
      require_version_core('''numpy<1000'''	)

      # le
      require_version_core('''numpy<=1000.4.5'''	)
      require_version_core(f'''numpy<={numpy_ver}'''	)

      # eq
      require_version_core(f'''numpy=={numpy_ver}'''	)

      # ne
      require_version_core('''numpy!=1000.4.5'''	)

      # ge
      require_version_core('''numpy>=1.0'''	)
      require_version_core('''numpy>=1.0.0'''	)
      require_version_core(f'''numpy>={numpy_ver}'''	)

      # gt
      require_version_core('''numpy>1.0.0'''	)

      # mix
      require_version_core('''numpy>1.0.0,<1000'''	)

      # requirement w/o version
      require_version_core('''numpy'''	)

      # unmet requirements due to version conflict
      for req in ["numpy==1.0.0", "numpy>=1000.0.0", f'''numpy<{numpy_ver}''']:
           try:
                require_version_core(A	)
           except ImportError as e:
                self.assertIn(f'''{req} is required'''			,       str(A	)	)
                self.assertIn('''but found'''			,       str(A	)	)

        # unmet requirements due to missing module
      for req in ["numpipypie>1", "numpipypie2"]:
           try:
                require_version_core(A	)
           except importlib.metadata.PackageNotFoundError as e:
                self.assertIn(f'''The \'{req}\' distribution was not found and is required by this application'''			,       str(A	)	)
                self.assertIn('''Try: pip install transformers -U'''			,       str(A	)	)

        # bogus requirements formats:
        # 1. whole thing
      for req in ["numpy??1.0.0", "numpy1.0.0"]:
           try:
                require_version_core(A	)
           except ValueError as e:
                self.assertIn('''requirement needs to be in the pip package format'''			,       str(A	)	)
        # 2. only operators
      for req in ["numpy=1.0.0", "numpy == 1.00", "numpy<>1.0.0", "numpy><1.00", "numpy>>1.0.0"]:
           try:
                require_version_core(A	)
           except ValueError as e:
                self.assertIn('''need one of '''			,       str(A	)	)



 def  a__  (self	)   ->					int:


      """simple docstring"""



      require_version('''python>=3.6.0'''	)

      # not matching requirements
      for req in ["python>9.9.9", "python<3.0.0"]:
           try:
                require_version_core(A	)
           except ImportError as e:
                self.assertIn(f'''{req} is required'''			,       str(A	)	)
                self.assertIn(f'''but found python=={python_ver}'''			,       str(A	)	)



