




import subprocess
from argparse import ArgumentParser
from typing import List, Union

from huggingface_hub.hf_api import HfFolder, create_repo, whoami
from requests.exceptions import HTTPError

from . import BaseTransformersCLICommand




class 	UpperCamelCase__			(__lowerCamelCase  ):

    '''simple docstring'''



    @staticmethod
    def 					_lowercase  (					UpperCamelCase__  )  ->   Union[str, Any]:
           lowerCamelCase     :   Union[str, Any]    				=      parser.add_parser("login"  ,						help="Log in using the same credentials as on huggingface.co"  )
           login_parser.set_defaults(func=lambda UpperCamelCase__  : LoginCommand(UpperCamelCase__  )  )
           lowerCamelCase     :   Union[str, Any]    				=      parser.add_parser("whoami"  ,						help="Find out which huggingface.co account you are logged in as."  )
           whoami_parser.set_defaults(func=lambda UpperCamelCase__  : WhoamiCommand(UpperCamelCase__  )  )
           lowerCamelCase     :   Tuple    				=      parser.add_parser("logout"  ,						help="Log out"  )
           logout_parser.set_defaults(func=lambda UpperCamelCase__  : LogoutCommand(UpperCamelCase__  )  )

           # new system: git-based repo system
           lowerCamelCase     :   List[str]    				=      parser.add_parser(
               "repo"  ,						help="Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos."  ,						)
           lowerCamelCase     :   Any    				=      repo_parser.add_subparsers(
               help="Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands"  )
           lowerCamelCase     :   Dict    				=      repo_subparsers.add_parser(
               "create"  ,						help="Deprecated: use `huggingface-cli` instead. Create a new repo on huggingface.co"  )
           repo_create_parser.add_argument(
               "name"  ,						type=UpperCamelCase__  ,						help="Name for your model\'s repo. Will be namespaced under your username to build the model id."  ,						)
           repo_create_parser.add_argument("--organization"  ,						type=UpperCamelCase__  ,						help="Optional: organization namespace."  )
           repo_create_parser.add_argument("-y"  ,						"--yes"  ,						action="store_true"  ,						help="Optional: answer Yes to the prompt"  )
           repo_create_parser.set_defaults(func=lambda UpperCamelCase__  : RepoCreateCommand(UpperCamelCase__  )  )




class 	UpperCamelCase__			:

    '''simple docstring'''



    lowerCamelCase_   :			List[str]			  =   '\u001b[1m'
    lowerCamelCase_   :			Union[str, Any]			  =   '\u001b[31m'
    lowerCamelCase_   :			Any			  =   '\u001b[90m'
    lowerCamelCase_   :			List[str]			  =   '\u001b[0m'







    @classmethod
    def 					_lowercase  (					cls  ,						UpperCamelCase__  )  ->   List[str]:
           return F'''{cls._bold}{s}{cls._reset}'''







    @classmethod
    def 					_lowercase  (					cls  ,						UpperCamelCase__  )  ->   Tuple:
           return F'''{cls._bold}{cls._red}{s}{cls._reset}'''







    @classmethod
    def 					_lowercase  (					cls  ,						UpperCamelCase__  )  ->   List[Any]:
           return F'''{cls._gray}{s}{cls._reset}'''




def   A   (   _SCREAMING_SNAKE_CASE				,_SCREAMING_SNAKE_CASE					)			->				str:
       lowerCamelCase     :   Union[str, Any]    				=      [max(len(str(_SCREAMING_SNAKE_CASE					)					) for x in col					) for col in zip(*_SCREAMING_SNAKE_CASE				,_SCREAMING_SNAKE_CASE					)]
       lowerCamelCase     :   Optional[int]    				=      ("{{:{}}} " * len(_SCREAMING_SNAKE_CASE					)).format(*_SCREAMING_SNAKE_CASE					)
       lowerCamelCase     :   List[str]    				=      []
       lines.append(row_format.format(*_SCREAMING_SNAKE_CASE					)					)
       lines.append(row_format.format(*["-" * w for w in col_widths]					)					)
       for row in rows:
              lines.append(row_format.format(*_SCREAMING_SNAKE_CASE					)					)
       return "\n".join(_SCREAMING_SNAKE_CASE					)




class 	UpperCamelCase__			:

    '''simple docstring'''



    def __init__(					self  ,						UpperCamelCase__  )  ->   Union[str, Any]:
           lowerCamelCase     :   Any    				=      args




class 	UpperCamelCase__			(__lowerCamelCase  ):

    '''simple docstring'''



    def 					_lowercase  (					self  )  ->   Optional[Any]:
           print(
               ANSI.red(
                   "ERROR! `huggingface-cli login` uses an outdated login mechanism "
                   "that is not compatible with the Hugging Face Hub backend anymore. "
                   "Please use `huggingface-cli login instead."  )  )




class 	UpperCamelCase__			(__lowerCamelCase  ):

    '''simple docstring'''



    def 					_lowercase  (					self  )  ->   Any:
           print(
               ANSI.red(
                   "WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use "
                   "`huggingface-cli whoami` instead."  )  )
           lowerCamelCase     :   Any    				=      HfFolder.get_token()
           if token is None:
                  print("Not logged in"  )
                  exit()
           try:
                  lowerCamelCase				,   lowerCamelCase     :   List[Any]    				=      whoami(UpperCamelCase__  )
                  print(UpperCamelCase__  )
                  if orgs:
                         print(ANSI.bold("orgs: "  )  ,						",".join(UpperCamelCase__  )  )
           except HTTPError as e:
                  print(UpperCamelCase__  )
                  print(ANSI.red(e.response.text  )  )
                  exit(1  )




class 	UpperCamelCase__			(__lowerCamelCase  ):

    '''simple docstring'''



    def 					_lowercase  (					self  )  ->   Union[str, Any]:
           print(
               ANSI.red(
                   "ERROR! `transformers-cli logout` uses an outdated logout mechanism "
                   "that is not compatible with the Hugging Face Hub backend anymore. "
                   "Please use `huggingface-cli logout instead."  )  )




class 	UpperCamelCase__			(__lowerCamelCase  ):

    '''simple docstring'''



    def 					_lowercase  (					self  )  ->   Optional[Any]:
           print(
               ANSI.red(
                   "WARNING! Managing repositories through transformers-cli is deprecated. "
                   "Please use `huggingface-cli` instead."  )  )
           lowerCamelCase     :   Optional[Any]    				=      HfFolder.get_token()
           if token is None:
                  print("Not logged in"  )
                  exit(1  )
           try:
                  lowerCamelCase     :   Optional[Any]    				=      subprocess.check_output(["git", "--version"]  ).decode("utf-8"  )
                  print(ANSI.gray(stdout.strip()  )  )
           except FileNotFoundError:
                  print("Looks like you do not have git installed, please install."  )

           try:
                  lowerCamelCase     :   List[Any]    				=      subprocess.check_output(["git-lfs", "--version"]  ).decode("utf-8"  )
                  print(ANSI.gray(stdout.strip()  )  )
           except FileNotFoundError:
                  print(
                      ANSI.red(
                          "Looks like you do not have git-lfs installed, please install."
                          " You can install from https://git-lfs.github.com/."
                          " Then run `git lfs install` (you only have to do this once)."  )  )
           print(""  )

           lowerCamelCase				,   lowerCamelCase     :   Tuple    				=      whoami(UpperCamelCase__  )
           lowerCamelCase     :   List[Any]    				=      self.args.organization if self.args.organization is not None else user
           lowerCamelCase     :   List[Any]    				=      F'''{namespace}/{self.args.name}'''
           print(F'''You are about to create {ANSI.bold(UpperCamelCase__  )}'''  )

           if not self.args.yes:
                  lowerCamelCase     :   Tuple    				=      input("Proceed? [Y/n] "  ).lower()
                  if not (choice == "" or choice == "y" or choice == "yes"):
                         print("Abort"  )
                         exit()
           try:
                  lowerCamelCase     :   List[Any]    				=      create_repo(UpperCamelCase__  ,						name=self.args.name  ,						organization=self.args.organization  )
           except HTTPError as e:
                  print(UpperCamelCase__  )
                  print(ANSI.red(e.response.text  )  )
                  exit(1  )
           print("\nYour repo now lives at:"  )
           print(F'''  {ANSI.bold(UpperCamelCase__  )}'''  )
           print("\nYou can clone it locally with the command below, and commit/push as usual."  )
           print(F'''\n  git clone {url}'''  )
           print(""  )












import collections
import types

import numpy as np

from ..utils import (
    add_end_docstrings,
    is_tensorflow_probability_available,
    is_tf_available,
    is_torch_available,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, Dataset, Pipeline, PipelineException


if is_torch_available():
       import torch

       from ..models.auto.modeling_auto import (
           MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
           MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
       )

if is_tf_available() and is_tensorflow_probability_available():
       import tensorflow as tf
       import tensorflow_probability as tfp

       from ..models.auto.modeling_tf_auto import (
           TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
           TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
       )




class 	UpperCamelCase__			(lowerCAmelCase__  ):

    '''simple docstring'''



    def __call__(					self  ,						UpperCamelCase__=None  ,						UpperCamelCase__=None  ,						**UpperCamelCase__  )  ->   List[Any]:
           # Returns tqa_pipeline_inputs of shape:
           # [
           #   {"table": pd.DataFrame, "query": List[str]},
           #   ...,
           #   {"table": pd.DataFrame, "query" : List[str]}
           # ]
           requires_backends(self  ,						"pandas"  )
           import pandas as pd

           if table is None:
                  raise ValueError("Keyword argument `table` cannot be None."  )
           elif query is None:
                  if isinstance(UpperCamelCase__  ,						UpperCamelCase__  ) and table.get("query"  ) is not None and table.get("table"  ) is not None:
                         lowerCamelCase     :   Optional[int]    				=      [table]
                  elif isinstance(UpperCamelCase__  ,						UpperCamelCase__  ) and len(UpperCamelCase__  ) > 0:
                         if not all(isinstance(UpperCamelCase__  ,						UpperCamelCase__  ) for d in table  ):
                                raise ValueError(
                                    F'''Keyword argument `table` should be a list of dict, but is {(type(UpperCamelCase__  ) for d in table)}'''  )

                         if table[0].get("query"  ) is not None and table[0].get("table"  ) is not None:
                                lowerCamelCase     :   int    				=      table
                         else:
                                raise ValueError(
                                    "If keyword argument `table` is a list of dictionaries, each dictionary should have a `table`"
                                    F''' and `query` key, but only dictionary has keys {table[0].keys()} `table` and `query` keys.'''  )
                  elif Dataset is not None and isinstance(UpperCamelCase__  ,						UpperCamelCase__  ) or isinstance(UpperCamelCase__  ,						types.GeneratorType  ):
                         return table
                  else:
                         raise ValueError(
                             "Invalid input. Keyword argument `table` should be either of type `dict` or `list`, but "
                             F'''is {type(UpperCamelCase__  )})'''  )
           else:
                  lowerCamelCase     :   Tuple    				=      [{"table": table, "query": query}]

           for tqa_pipeline_input in tqa_pipeline_inputs:
                  if not isinstance(tqa_pipeline_input["table"]  ,						pd.DataFrame  ):
                         if tqa_pipeline_input["table"] is None:
                                raise ValueError("Table cannot be None."  )

                         lowerCamelCase     :   Optional[Any]    				=      pd.DataFrame(tqa_pipeline_input["table"]  )

           return tqa_pipeline_inputs




@add_end_docstrings(lowerCAmelCase__  )
class 	UpperCamelCase__			(lowerCAmelCase__  ):

    '''simple docstring'''



    lowerCamelCase_   :			Optional[Any]			  =   """table,query"""







    def __init__(					self  ,						UpperCamelCase__=TableQuestionAnsweringArgumentHandler()  ,						*UpperCamelCase__  ,						**UpperCamelCase__  )  ->   Dict:
           super().__init__(*UpperCamelCase__  ,						**UpperCamelCase__  )
           lowerCamelCase     :   Any    				=      args_parser

           self.check_model_type(
               dict(
                   TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items()
                   + TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()  )
               if self.framework == "tf"
               else dict(
                   MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items() + MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()  )  )

           lowerCamelCase     :   Any    				=      bool(getattr(self.model.config  ,						"aggregation_labels"  ,						UpperCamelCase__  )  ) and bool(
               getattr(self.model.config  ,						"num_aggregation_labels"  ,						UpperCamelCase__  )  )
           lowerCamelCase     :   List[Any]    				=      "tapas" if hasattr(self.model.config  ,						"aggregation_labels"  ) else None







    def 					_lowercase  (					self  ,						**UpperCamelCase__  )  ->   int:
           return self.model(**UpperCamelCase__  )







    def 					_lowercase  (					self  ,						**UpperCamelCase__  )  ->   Union[str, Any]:
           if self.framework == "pt":
                  lowerCamelCase     :   List[str]    				=      []
                  lowerCamelCase     :   List[Any]    				=      []
                  lowerCamelCase     :   List[Any]    				=      None
                  lowerCamelCase     :   List[str]    				=      inputs["input_ids"].shape[0]

                  lowerCamelCase     :   Optional[int]    				=      inputs["input_ids"].to(self.device  )
                  lowerCamelCase     :   List[str]    				=      inputs["attention_mask"].to(self.device  )
                  lowerCamelCase     :   str    				=      inputs["token_type_ids"].to(self.device  )
                  lowerCamelCase     :   str    				=      None

                  for index in range(UpperCamelCase__  ):
                         # If sequences have already been processed, the token type IDs will be created according to the previous
                         # answer.
                         if prev_answers is not None:
                                lowerCamelCase     :   List[Any]    				=      token_type_ids_example[:, 3]  # shape (seq_len,)
                                lowerCamelCase     :   Optional[int]    				=      np.zeros_like(prev_labels_example.cpu().numpy()  )  # shape (seq_len,)

                                lowerCamelCase     :   Optional[Any]    				=      token_type_ids[index]  # shape (seq_len, 7)
                                for i in range(model_labels.shape[0]  ):
                                       lowerCamelCase     :   Tuple    				=      token_type_ids_example[:, 0].tolist()[i]
                                       lowerCamelCase     :   Union[str, Any]    				=      token_type_ids_example[:, 1].tolist()[i] - 1
                                       lowerCamelCase     :   Optional[int]    				=      token_type_ids_example[:, 2].tolist()[i] - 1

                                       if row_id >= 0 and col_id >= 0 and segment_id == 1:
                                              lowerCamelCase     :   Dict    				=      int(prev_answers[(col_id, row_id)]  )

                                lowerCamelCase     :   Dict    				=      torch.from_numpy(UpperCamelCase__  ).type(torch.long  ).to(self.device  )

                         lowerCamelCase     :   int    				=      input_ids[index]
                         lowerCamelCase     :   Union[str, Any]    				=      attention_mask[index]  # shape (seq_len,)
                         lowerCamelCase     :   Dict    				=      token_type_ids[index]  # shape (seq_len, 7)
                         lowerCamelCase     :   Dict    				=      self.model(
                             input_ids=input_ids_example.unsqueeze(0  )  ,						attention_mask=attention_mask_example.unsqueeze(0  )  ,						token_type_ids=token_type_ids_example.unsqueeze(0  )  ,						)
                         lowerCamelCase     :   str    				=      outputs.logits

                         if self.aggregate:
                                all_aggregations.append(outputs.logits_aggregation  )

                         all_logits.append(UpperCamelCase__  )

                         lowerCamelCase     :   int    				=      torch.distributions.Bernoulli(logits=UpperCamelCase__  )
                         lowerCamelCase     :   List[Any]    				=      dist_per_token.probs * attention_mask_example.type(torch.floataa  ).to(
                             dist_per_token.probs.device  )

                         lowerCamelCase     :   Optional[int]    				=      collections.defaultdict(UpperCamelCase__  )
                         for i, p in enumerate(probabilities.squeeze().tolist()  ):
                                lowerCamelCase     :   Optional[int]    				=      token_type_ids_example[:, 0].tolist()[i]
                                lowerCamelCase     :   List[Any]    				=      token_type_ids_example[:, 1].tolist()[i] - 1
                                lowerCamelCase     :   str    				=      token_type_ids_example[:, 2].tolist()[i] - 1
                                if col >= 0 and row >= 0 and segment_id == 1:
                                       coords_to_probs[(col, row)].append(UpperCamelCase__  )

                         lowerCamelCase     :   Optional[int]    				=      {key: np.array(coords_to_probs[key]  ).mean() > 0.5 for key in coords_to_probs}

                  lowerCamelCase     :   Optional[Any]    				=      torch.cat(tuple(UpperCamelCase__  )  ,						0  )

                  return (logits_batch,) if not self.aggregate else (logits_batch, torch.cat(tuple(UpperCamelCase__  )  ,						0  ))
           else:
                  lowerCamelCase     :   Optional[Any]    				=      []
                  lowerCamelCase     :   List[Any]    				=      []
                  lowerCamelCase     :   Union[str, Any]    				=      None
                  lowerCamelCase     :   int    				=      inputs["input_ids"].shape[0]

                  lowerCamelCase     :   Dict    				=      inputs["input_ids"]
                  lowerCamelCase     :   Tuple    				=      inputs["attention_mask"]
                  lowerCamelCase     :   Optional[int]    				=      inputs["token_type_ids"].numpy()
                  lowerCamelCase     :   Union[str, Any]    				=      None

                  for index in range(UpperCamelCase__  ):
                         # If sequences have already been processed, the token type IDs will be created according to the previous
                         # answer.
                         if prev_answers is not None:
                                lowerCamelCase     :   Tuple    				=      token_type_ids_example[:, 3]  # shape (seq_len,)
                                lowerCamelCase     :   Optional[Any]    				=      np.zeros_like(UpperCamelCase__  ,						dtype=np.intaa  )  # shape (seq_len,)

                                lowerCamelCase     :   Optional[Any]    				=      token_type_ids[index]  # shape (seq_len, 7)
                                for i in range(model_labels.shape[0]  ):
                                       lowerCamelCase     :   Any    				=      token_type_ids_example[:, 0].tolist()[i]
                                       lowerCamelCase     :   int    				=      token_type_ids_example[:, 1].tolist()[i] - 1
                                       lowerCamelCase     :   Union[str, Any]    				=      token_type_ids_example[:, 2].tolist()[i] - 1

                                       if row_id >= 0 and col_id >= 0 and segment_id == 1:
                                              lowerCamelCase     :   Tuple    				=      int(prev_answers[(col_id, row_id)]  )

                                lowerCamelCase     :   Any    				=      model_labels

                         lowerCamelCase     :   Optional[int]    				=      input_ids[index]
                         lowerCamelCase     :   Optional[Any]    				=      attention_mask[index]  # shape (seq_len,)
                         lowerCamelCase     :   Optional[int]    				=      token_type_ids[index]  # shape (seq_len, 7)
                         lowerCamelCase     :   Union[str, Any]    				=      self.model(
                             input_ids=np.expand_dims(UpperCamelCase__  ,						axis=0  )  ,						attention_mask=np.expand_dims(UpperCamelCase__  ,						axis=0  )  ,						token_type_ids=np.expand_dims(UpperCamelCase__  ,						axis=0  )  ,						)
                         lowerCamelCase     :   Dict    				=      outputs.logits

                         if self.aggregate:
                                all_aggregations.append(outputs.logits_aggregation  )

                         all_logits.append(UpperCamelCase__  )

                         lowerCamelCase     :   Optional[int]    				=      tfp.distributions.Bernoulli(logits=UpperCamelCase__  )
                         lowerCamelCase     :   Any    				=      dist_per_token.probs_parameter() * tf.cast(UpperCamelCase__  ,						tf.floataa  )

                         lowerCamelCase     :   List[Any]    				=      collections.defaultdict(UpperCamelCase__  )
                         lowerCamelCase     :   Optional[int]    				=      token_type_ids_example
                         for i, p in enumerate(tf.squeeze(UpperCamelCase__  ).numpy().tolist()  ):
                                lowerCamelCase     :   Union[str, Any]    				=      token_type_ids_example[:, 0].tolist()[i]
                                lowerCamelCase     :   Any    				=      token_type_ids_example[:, 1].tolist()[i] - 1
                                lowerCamelCase     :   List[str]    				=      token_type_ids_example[:, 2].tolist()[i] - 1
                                if col >= 0 and row >= 0 and segment_id == 1:
                                       coords_to_probs[(col, row)].append(UpperCamelCase__  )

                         lowerCamelCase     :   Optional[Any]    				=      {key: np.array(coords_to_probs[key]  ).mean() > 0.5 for key in coords_to_probs}

                  lowerCamelCase     :   int    				=      tf.concat(tuple(UpperCamelCase__  )  ,						0  )

                  return (logits_batch,) if not self.aggregate else (logits_batch, tf.concat(tuple(UpperCamelCase__  )  ,						0  ))







    def __call__(					self  ,						*UpperCamelCase__  ,						**UpperCamelCase__  )  ->   int:
           lowerCamelCase     :   Union[str, Any]    				=      self._args_parser(*UpperCamelCase__  ,						**UpperCamelCase__  )

           lowerCamelCase     :   Optional[int]    				=      super().__call__(UpperCamelCase__  ,						**UpperCamelCase__  )
           if len(UpperCamelCase__  ) == 1:
                  return results[0]
           return results







    def 					_lowercase  (					self  ,						UpperCamelCase__=None  ,						UpperCamelCase__=None  ,						UpperCamelCase__=None  ,						**UpperCamelCase__  )  ->   Optional[int]:
           lowerCamelCase     :   int    				=      {}
           if padding is not None:
                  lowerCamelCase     :   Dict    				=      padding
           if truncation is not None:
                  lowerCamelCase     :   Tuple    				=      truncation

           lowerCamelCase     :   List[str]    				=      {}
           if sequential is not None:
                  lowerCamelCase     :   Any    				=      sequential
           return preprocess_params, forward_params, {}







    def 					_lowercase  (					self  ,						UpperCamelCase__  ,						UpperCamelCase__=None  ,						UpperCamelCase__=True  ,						UpperCamelCase__=None  )  ->   str:
           if truncation is None:
                  if self.type == "tapas":
                         lowerCamelCase     :   Optional[Any]    				=      "drop_rows_to_fit"
                  else:
                         lowerCamelCase     :   str    				=      "do_not_truncate"

           lowerCamelCase				,   lowerCamelCase     :   Tuple    				=      pipeline_input["table"], pipeline_input["query"]
           if table.empty:
                  raise ValueError("table is empty"  )
           if query is None or query == "":
                  raise ValueError("query is empty"  )
           lowerCamelCase     :   Any    				=      self.tokenizer(UpperCamelCase__  ,						UpperCamelCase__  ,						return_tensors=self.framework  ,						truncation=UpperCamelCase__  ,						padding=UpperCamelCase__  )
           lowerCamelCase     :   str    				=      table
           return inputs







    def 					_lowercase  (					self  ,						UpperCamelCase__  ,						UpperCamelCase__=False  )  ->   Dict:
           lowerCamelCase     :   Union[str, Any]    				=      model_inputs.pop("table"  )

           if self.type == "tapas":
                  if sequential:
                         lowerCamelCase     :   int    				=      self.sequential_inference(**UpperCamelCase__  )
                  else:
                         lowerCamelCase     :   List[Any]    				=      self.batch_inference(**UpperCamelCase__  )
           else:
                  lowerCamelCase     :   int    				=      self.model.generate(**UpperCamelCase__  )
           lowerCamelCase     :   int    				=      {"model_inputs": model_inputs, "table": table, "outputs": outputs}
           return model_outputs







    def 					_lowercase  (					self  ,						UpperCamelCase__  )  ->   List[str]:
           lowerCamelCase     :   List[Any]    				=      model_outputs["model_inputs"]
           lowerCamelCase     :   Tuple    				=      model_outputs["table"]
           lowerCamelCase     :   Optional[Any]    				=      model_outputs["outputs"]
           if self.type == "tapas":
                  if self.aggregate:
                         lowerCamelCase				,   lowerCamelCase     :   Tuple    				=      outputs[:2]
                         lowerCamelCase     :   Union[str, Any]    				=      self.tokenizer.convert_logits_to_predictions(UpperCamelCase__  ,						UpperCamelCase__  ,						UpperCamelCase__  )
                         lowerCamelCase				,   lowerCamelCase     :   Dict    				=      predictions
                         lowerCamelCase     :   int    				=      {i: self.model.config.aggregation_labels[pred] for i, pred in enumerate(UpperCamelCase__  )}

                         lowerCamelCase     :   Tuple    				=      self.model.config.no_aggregation_label_index
                         lowerCamelCase     :   int    				=      {
                             i: aggregators[i] + " > " for i, pred in enumerate(UpperCamelCase__  ) if pred != no_agg_label_index
                         }
                  else:
                         lowerCamelCase     :   Optional[int]    				=      outputs[0]
                         lowerCamelCase     :   Tuple    				=      self.tokenizer.convert_logits_to_predictions(UpperCamelCase__  ,						UpperCamelCase__  )
                         lowerCamelCase     :   Optional[Any]    				=      predictions[0]
                         lowerCamelCase     :   Dict    				=      {}
                         lowerCamelCase     :   str    				=      {}
                  lowerCamelCase     :   Optional[int]    				=      []
                  for index, coordinates in enumerate(UpperCamelCase__  ):
                         lowerCamelCase     :   Optional[Any]    				=      [table.iat[coordinate] for coordinate in coordinates]
                         lowerCamelCase     :   Union[str, Any]    				=      aggregators.get(UpperCamelCase__  ,						""  )
                         lowerCamelCase     :   str    				=      aggregators_prefix.get(UpperCamelCase__  ,						""  )
                         lowerCamelCase     :   Tuple    				=      {
                             "answer": aggregator_prefix + ", ".join(UpperCamelCase__  ),
                             "coordinates": coordinates,
                             "cells": [table.iat[coordinate] for coordinate in coordinates],
                         }
                         if aggregator:
                                lowerCamelCase     :   str    				=      aggregator

                         answers.append(UpperCamelCase__  )
                  if len(UpperCamelCase__  ) == 0:
                         raise PipelineException("Empty answer"  )
           else:
                  lowerCamelCase     :   Optional[Any]    				=      [{"answer": answer} for answer in self.tokenizer.batch_decode(UpperCamelCase__  ,						skip_special_tokens=UpperCamelCase__  )]

           return answers if len(UpperCamelCase__  ) > 1 else answers[0]






