

from typing import Optional, Union

from ...file_utils import TensorType
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, TruncationStrategy
class     SCREAMING_SNAKE_CASE__     (						__lowerCamelCase		):





       '''simple docstring'''




       UpperCamelCase__ :     Union[str, Any]				    =       '''MarkupLMFeatureExtractor'''
       UpperCamelCase__ :     int				    =       ('''MarkupLMTokenizer''', '''MarkupLMTokenizerFast''')
       UpperCamelCase__ :     Union[str, Any]				    =       True

       def __call__(						self       :						str    ,		lowerCAmelCase__       :						Optional[int]=None    ,		lowerCAmelCase__       :						Any=None    ,		lowerCAmelCase__       :						str=None    ,		lowerCAmelCase__       :						Tuple=None    ,		lowerCAmelCase__       :						List[str]=None    ,		lowerCAmelCase__       :						Optional[int] = True    ,		lowerCAmelCase__       :						Optional[int] = False    ,		lowerCAmelCase__       :						List[str] = None    ,		lowerCAmelCase__       :						int = None    ,		lowerCAmelCase__       :						Dict = 0    ,		lowerCAmelCase__       :						int = None    ,		lowerCAmelCase__       :						List[Any] = None    ,		lowerCAmelCase__       :						Any = None    ,		lowerCAmelCase__       :						Union[str, Any] = False    ,		lowerCAmelCase__       :						Optional[Any] = False    ,		lowerCAmelCase__       :						List[str] = False    ,		lowerCAmelCase__       :						Optional[Any] = False    ,		lowerCAmelCase__       :						int = True    ,		lowerCAmelCase__       :						List[Any] = None    ,		**lowerCAmelCase__       :						Any    ,		)			->    Optional[int]:
             # first, create nodes and xpaths
             if self.parse_html:
                   if html_strings is None:
                         raise ValueError("""Make sure to pass HTML strings in case `parse_html` is set to `True`"""							)

                   if nodes is not None or xpaths is not None or node_labels is not None:
                         raise ValueError(
                             """Please don't pass nodes, xpaths nor node labels in case `parse_html` is set to `True`"""							)

                   snake_case__					=   self.feature_extractor(_lowerCAmelCase							)
                   snake_case__					=   features["""nodes"""]
                   snake_case__					=   features["""xpaths"""]
             else:
                   if html_strings is not None:
                         raise ValueError("""You have passed HTML strings but `parse_html` is set to `False`."""							)
                   if nodes is None or xpaths is None:
                         raise ValueError("""Make sure to pass nodes and xpaths in case `parse_html` is set to `False`"""							)

        # # second, apply the tokenizer
             if questions is not None and self.parse_html:
                   if isinstance(_lowerCAmelCase    ,		_lowerCAmelCase							):
                         snake_case__					=   [questions]  # add batch dimension (as the feature extractor always adds a batch dimension)

             snake_case__					=   self.tokenizer(
                 text=questions if questions is not None else nodes    ,		text_pair=nodes if questions is not None else None    ,		xpaths=_lowerCAmelCase    ,		node_labels=_lowerCAmelCase    ,		add_special_tokens=_lowerCAmelCase    ,		padding=_lowerCAmelCase    ,		truncation=_lowerCAmelCase    ,		max_length=_lowerCAmelCase    ,		stride=_lowerCAmelCase    ,		pad_to_multiple_of=_lowerCAmelCase    ,		return_token_type_ids=_lowerCAmelCase    ,		return_attention_mask=_lowerCAmelCase    ,		return_overflowing_tokens=_lowerCAmelCase    ,		return_special_tokens_mask=_lowerCAmelCase    ,		return_offsets_mapping=_lowerCAmelCase    ,		return_length=_lowerCAmelCase    ,		verbose=_lowerCAmelCase    ,		return_tensors=_lowerCAmelCase    ,		**_lowerCAmelCase    ,		)

             return encoded_inputs

       def UpperCAmelCase_						(						self       :						Union[str, Any]    ,		*lowerCAmelCase__       :						List[Any]    ,		**lowerCAmelCase__       :						Tuple							)			->    List[Any]:
             return self.tokenizer.batch_decode(*_lowerCAmelCase    ,		**_lowerCAmelCase							)

       def UpperCAmelCase_						(						self       :						Tuple    ,		*lowerCAmelCase__       :						int    ,		**lowerCAmelCase__       :						List[Any]							)			->    Optional[int]:
             return self.tokenizer.decode(*_lowerCAmelCase    ,		**_lowerCAmelCase							)

       @property
       def UpperCAmelCase_						(						self       :						Optional[int]							)			->    int:
             snake_case__					=   self.tokenizer.model_input_names
             return tokenizer_input_names









# 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


lowerCAmelCase						:   List[Any]										=    '''Here is a text containing a lot of information: \'\'\'{text}\'\'\'.

Can you answer this question about the text: \'{question}\''''
class     SCREAMING_SNAKE_CASE__     (						__a		):





       '''simple docstring'''




       UpperCamelCase__ :     int				    =       '''google/flan-t5-base'''
       UpperCamelCase__ :     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.'''
       )
       UpperCamelCase__ :     Tuple				    =       '''text_qa'''
       UpperCamelCase__ :     Tuple				    =       AutoTokenizer
       UpperCamelCase__ :     List[Any]				    =       AutoModelForSeqaSeqLM

       UpperCamelCase__ :     Optional[Any]				    =       ['''text''', '''text''']
       UpperCamelCase__ :     Any				    =       ['''text''']

       def UpperCAmelCase_						(						self       :						Tuple    ,		lowerCAmelCase__       :						str    ,		lowerCAmelCase__       :						str							)			->    List[Any]:
             snake_case__					=   QA_PROMPT.format(text=lowerCAmelCase__    ,		question=lowerCAmelCase__							)
             return self.pre_processor(lowerCAmelCase__    ,		return_tensors="""pt"""							)

       def UpperCAmelCase_						(						self       :						Optional[Any]    ,		lowerCAmelCase__       :						Dict							)			->    List[Any]:
             snake_case__					=   self.model.generate(**lowerCAmelCase__							)

             snake_case__	,			snake_case__					=   inputs["""input_ids"""].shape
             snake_case__					=   output_ids.shape[0]

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

       def UpperCAmelCase_						(						self       :						Union[str, Any]    ,		lowerCAmelCase__       :						Dict							)			->    List[Any]:
             return self.pre_processor.decode(lowerCAmelCase__    ,		skip_special_tokens=lowerCAmelCase__    ,		clean_up_tokenization_spaces=lowerCAmelCase__							)






