






# 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


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


class  __lowercase (		lowercase_					):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE				  =			"google/flan-t5-base"
     SCREAMING_SNAKE_CASE				  =			(
         "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."
     )
     SCREAMING_SNAKE_CASE				  =			"text_qa"
     SCREAMING_SNAKE_CASE				  =			AutoTokenizer
     SCREAMING_SNAKE_CASE				  =			AutoModelForSeqaSeqLM

     SCREAMING_SNAKE_CASE				  =			["text", "text"]
     SCREAMING_SNAKE_CASE				  =			["text"]




     def 						lowerCAmelCase_       (			self    :     Union[str, Any]	,		UpperCamelCase_    :     str	,		UpperCamelCase_    :     str			):


         """simple docstring"""



         __A             =		QA_PROMPT.format(text=UpperCamelCase_	,		question=UpperCamelCase_			)
         return self.pre_processor(UpperCamelCase_	,		return_tensors="""pt"""			)




     def 						lowerCAmelCase_       (			self    :     str	,		UpperCamelCase_    :     int			):


         """simple docstring"""



         __A             =		self.model.generate(**UpperCamelCase_			)

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

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





     def 						lowerCAmelCase_       (			self    :     List[str]	,		UpperCamelCase_    :     str			):


         """simple docstring"""



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












import copy

from transformers.configuration_utils import PretrainedConfig
from transformers.utils import logging


__a :    Tuple								=				logging.get_logger(__name__)


class  __lowercase (		lowercase_					):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE				  =			"hybrid-clip"
     SCREAMING_SNAKE_CASE				  =			True




     def __init__(			self    :     Optional[Any]	,		UpperCamelCase_    :     Optional[Any]=512	,		**UpperCamelCase_    :     List[Any]			):


         """simple docstring"""



         super().__init__(**UpperCamelCase_			)

         if "text_config" not in kwargs:
             raise ValueError("""`text_config` can not be `None`."""			)

         if "vision_config" not in kwargs:
             raise ValueError("""`vision_config` can not be `None`."""			)

         __A             =		kwargs.pop("""text_config"""			)
         __A             =		kwargs.pop("""vision_config"""			)

         __A             =		text_config.pop("""model_type"""			)
         __A             =		vision_config.pop("""model_type"""			)

         from transformers import AutoConfig

         __A             =		AutoConfig.for_model(UpperCamelCase_	,		**UpperCamelCase_			)

         if vision_model_type == "clip":
             __A             =		AutoConfig.for_model(UpperCamelCase_	,		**UpperCamelCase_			).vision_config
         elif vision_model_type == "clip_vision_model":
             from transformers import CLIPVisionConfig

             __A             =		CLIPVisionConfig(**UpperCamelCase_			)
         else:
             __A             =		AutoConfig.for_model(UpperCamelCase_	,		**UpperCamelCase_			)

         __A             =		projection_dim
         __A             =		1.0




     @classmethod
     def 						lowerCAmelCase_       (			cls    :     int	,		UpperCamelCase_    :     PretrainedConfig	,		UpperCamelCase_    :     PretrainedConfig	,		**UpperCamelCase_    :     Union[str, Any]			):


         """simple docstring"""



         return cls(text_config=text_config.to_dict()	,		vision_config=vision_config.to_dict()	,		**UpperCamelCase_			)





     def 						lowerCAmelCase_       (			self    :     Tuple			):


         """simple docstring"""



         __A             =		copy.deepcopy(self.__dict__			)
         __A             =		self.text_config.to_dict()
         __A             =		self.vision_config.to_dict()
         __A             =		self.__class__.model_type
         return output




