





import argparse
import os
from pathlib import Path

import torch
from bark.generation import _load_model as _bark_load_model
from huggingface_hub import hf_hub_download

from transformers import EncodecConfig, EncodecModel, set_seed
from transformers.models.bark.configuration_bark import (
    BarkCoarseConfig,
    BarkConfig,
    BarkFineConfig,
    BarkSemanticConfig,
)
from transformers.models.bark.generation_configuration_bark import (
    BarkCoarseGenerationConfig,
    BarkFineGenerationConfig,
    BarkGenerationConfig,
    BarkSemanticGenerationConfig,
)
from transformers.models.bark.modeling_bark import BarkCoarseModel, BarkFineModel, BarkModel, BarkSemanticModel
from transformers.utils import logging


logging.set_verbosity_info()
_UpperCamelCase							=			logging.get_logger(__name__)

set_seed(770)


_UpperCamelCase							=			{
    "c_attn": "att_proj",
    "c_proj": "out_proj",
    "c_fc": "in_proj",
    "transformer.": "",
    "h.": "layers.",
    "ln_1": "layernorm_1",
    "ln_2": "layernorm_2",
    "ln_f": "layernorm_final",
    "wpe": "position_embeds_layer",
    "wte": "input_embeds_layer",
}


_UpperCamelCase							=			{
    "text_small": {
        "repo_id": "suno/bark",
        "file_name": "text.pt",
    },
    "coarse_small": {
        "repo_id": "suno/bark",
        "file_name": "coarse.pt",
    },
    "fine_small": {
        "repo_id": "suno/bark",
        "file_name": "fine.pt",
    },
    "text": {
        "repo_id": "suno/bark",
        "file_name": "text_2.pt",
    },
    "coarse": {
        "repo_id": "suno/bark",
        "file_name": "coarse_2.pt",
    },
    "fine": {
        "repo_id": "suno/bark",
        "file_name": "fine_2.pt",
    },
}

_UpperCamelCase							=			os.path.dirname(os.path.abspath(__file__))
_UpperCamelCase							=			os.path.join(os.path.expanduser('''~'''), '''.cache''')
_UpperCamelCase							=			os.path.join(os.getenv('''XDG_CACHE_HOME''', default_cache_dir), '''suno''', '''bark_v0''')







def    lowerCAmelCase__(						lowercase							:     Dict ,  lowercase							:     List[Any]=False					)			->     Any:
  __snake_case :					str          =							model_type
  if use_small:
    key += "_small"
  return os.path.join(_lowerCamelCase ,  REMOTE_MODEL_PATHS[key]["file_name"]					)







def    lowerCAmelCase__(						lowercase							:     Optional[Any] ,  lowercase							:     int					)			->     Dict:
  os.makedirs(_lowerCamelCase ,  exist_ok=_lowerCamelCase					)
  hf_hub_download(repo_id=_lowerCamelCase ,  filename=_lowerCamelCase ,  local_dir=_lowerCamelCase					)







def    lowerCAmelCase__(						lowercase							:     Tuple ,  lowercase							:     Dict ,  lowercase							:     Dict=False ,  lowercase							:     List[Any]="text"					)			->     Any:
  if model_type == "text":
    __snake_case :					Dict          =							BarkSemanticModel
    __snake_case :					Union[str, Any]          =							BarkSemanticConfig
    __snake_case :					Union[str, Any]          =							BarkSemanticGenerationConfig
  elif model_type == "coarse":
    __snake_case :					Optional[int]          =							BarkCoarseModel
    __snake_case :					Union[str, Any]          =							BarkCoarseConfig
    __snake_case :					int          =							BarkCoarseGenerationConfig
  elif model_type == "fine":
    __snake_case :					Dict          =							BarkFineModel
    __snake_case :					str          =							BarkFineConfig
    __snake_case :					Union[str, Any]          =							BarkFineGenerationConfig
  else:
    raise NotImplementedError()
  __snake_case :					str          =							f"""{model_type}_small""" if use_small else model_type
  __snake_case :					Union[str, Any]          =							REMOTE_MODEL_PATHS[model_key]
  if not os.path.exists(_lowerCamelCase					):
    logger.info(f"""{model_type} model not found, downloading into `{CACHE_DIR}`."""					)
    _download(model_info["repo_id"] ,  model_info["file_name"]					)
  __snake_case :					int          =							torch.load(_lowerCamelCase ,  map_location=_lowerCamelCase					)
  # this is a hack
  __snake_case :					int          =							checkpoint["model_args"]
  if "input_vocab_size" not in model_args:
    __snake_case :					Any          =							model_args["vocab_size"]
    __snake_case :					int          =							model_args["vocab_size"]
    del model_args["vocab_size"]

  # convert Bark model arguments to HF Bark model arguments
  __snake_case :					str          =							model_args.pop("n_head"					)
  __snake_case :					Optional[int]          =							model_args.pop("n_embd"					)
  __snake_case :					int          =							model_args.pop("n_layer"					)

  __snake_case :					Any          =							ConfigClass(**checkpoint["model_args"]					)
  __snake_case :					Optional[int]          =							ModelClass(config=_lowerCamelCase					)
  __snake_case :					List[Any]          =							GenerationConfigClass()

  __snake_case :					Union[str, Any]          =							model_generation_config
  __snake_case :					str          =							checkpoint["model"]
  # fixup checkpoint
  __snake_case :					Any          =							"_orig_mod."
  for k, v in list(state_dict.items()					):
    if k.startswith(_lowerCamelCase					):
      # replace part of the key with corresponding layer name in HF implementation
      __snake_case :					str          =							k[len(_lowerCamelCase					) :]
      for old_layer_name in new_layer_name_dict:
        __snake_case :					Tuple          =							new_k.replace(_lowerCamelCase ,  new_layer_name_dict[old_layer_name]					)

      __snake_case :					List[str]          =							state_dict.pop(_lowerCamelCase					)

  __snake_case :					Any          =							set(state_dict.keys()					) - set(model.state_dict().keys()					)
  __snake_case :					str          =							{k for k in extra_keys if not k.endswith(".attn.bias"					)}
  __snake_case :					List[Any]          =							set(model.state_dict().keys()					) - set(state_dict.keys()					)
  __snake_case :					Union[str, Any]          =							{k for k in missing_keys if not k.endswith(".attn.bias"					)}
  if len(_lowerCamelCase					) != 0:
    raise ValueError(f"""extra keys found: {extra_keys}"""					)
  if len(_lowerCamelCase					) != 0:
    raise ValueError(f"""missing keys: {missing_keys}"""					)
  model.load_state_dict(_lowerCamelCase ,  strict=_lowerCamelCase					)
  __snake_case :					str          =							model.num_parameters(exclude_embeddings=_lowerCamelCase					)
  __snake_case :					List[str]          =							checkpoint["best_val_loss"].item()
  logger.info(f"""model loaded: {round(n_params/1E6 ,  1					)}M params, {round(_lowerCamelCase ,  3					)} loss"""					)
  model.eval()
  model.to(_lowerCamelCase					)
  del checkpoint, state_dict

  return model







def    lowerCAmelCase__(						lowercase							:     Optional[Any] ,  lowercase							:     Dict=False ,  lowercase							:     List[Any]="text"					)			->     Union[str, Any]:
  if model_type not in ("text", "coarse", "fine"):
    raise NotImplementedError()

  __snake_case :					Optional[Any]          =							"cpu"  # do conversion on cpu

  __snake_case :					List[str]          =							_get_ckpt_path(_lowerCamelCase ,  use_small=_lowerCamelCase					)
  __snake_case :					Optional[int]          =							_load_model(_lowerCamelCase ,  _lowerCamelCase ,  model_type=_lowerCamelCase ,  use_small=_lowerCamelCase					)

  # load bark initial model
  __snake_case :					Union[str, Any]          =							_bark_load_model(_lowerCamelCase ,  "cpu" ,  model_type=_lowerCamelCase ,  use_small=_lowerCamelCase					)

  if model_type == "text":
    __snake_case :					Any          =							bark_model["model"]

  if model.num_parameters(exclude_embeddings=_lowerCamelCase					) != bark_model.get_num_params():
    raise ValueError("initial and new models don't have the same number of parameters"					)

  # check if same output as the bark model
  __snake_case :					Union[str, Any]          =							5
  __snake_case :					int          =							10

  if model_type in ["text", "coarse"]:
    __snake_case :					List[Any]          =							torch.randint(256 ,  (batch_size, sequence_length) ,  dtype=torch.int					)
    __snake_case :					Any          =							bark_model(_lowerCamelCase					)[0]

    __snake_case :					List[Any]          =							model(_lowerCamelCase					)

    # take last logits
    __snake_case :					List[str]          =							output_new_model_total.logits[:, [-1], :]

  else:
    __snake_case :					str          =							3
    __snake_case :					Union[str, Any]          =							8
    __snake_case :					Tuple          =							torch.randint(256 ,  (batch_size, sequence_length, n_codes_total) ,  dtype=torch.int					)

    __snake_case :					str          =							model(_lowerCamelCase ,  _lowerCamelCase					)
    __snake_case :					Optional[Any]          =							bark_model(_lowerCamelCase ,  _lowerCamelCase					)

    __snake_case :					Dict          =							output_new_model_total.logits

  # output difference should come from the difference of self-attention implementation design
  if output_new_model.shape != output_old_model.shape:
    raise ValueError("initial and new outputs don't have the same shape"					)
  if (output_new_model - output_old_model).abs().max().item() > 1E-3:
    raise ValueError("initial and new outputs are not equal"					)

  Path(_lowerCamelCase					).mkdir(exist_ok=_lowerCamelCase					)
  model.save_pretrained(_lowerCamelCase					)







def    lowerCAmelCase__(						lowercase							:     Dict ,  lowercase							:     Dict ,  lowercase							:     Tuple ,  lowercase							:     Any ,  lowercase							:     Any ,  lowercase							:     Tuple ,  )			->     List[Any]:
  __snake_case :					List[str]          =							os.path.join(_lowerCamelCase ,  _lowerCamelCase					)

  __snake_case :					Optional[int]          =							BarkSemanticConfig.from_pretrained(os.path.join(_lowerCamelCase ,  "config.json"					)					)
  __snake_case :					Optional[Any]          =							BarkCoarseConfig.from_pretrained(os.path.join(_lowerCamelCase ,  "config.json"					)					)
  __snake_case :					Tuple          =							BarkFineConfig.from_pretrained(os.path.join(_lowerCamelCase ,  "config.json"					)					)
  __snake_case :					Union[str, Any]          =							EncodecConfig.from_pretrained("facebook/encodec_24khz"					)

  __snake_case :					Any          =							BarkSemanticModel.from_pretrained(_lowerCamelCase					)
  __snake_case :					List[str]          =							BarkCoarseModel.from_pretrained(_lowerCamelCase					)
  __snake_case :					Union[str, Any]          =							BarkFineModel.from_pretrained(_lowerCamelCase					)
  __snake_case :					Union[str, Any]          =							EncodecModel.from_pretrained("facebook/encodec_24khz"					)

  __snake_case :					List[Any]          =							BarkConfig.from_sub_model_configs(
      _lowerCamelCase ,  _lowerCamelCase ,  _lowerCamelCase ,  _lowerCamelCase					)

  __snake_case :					Dict          =							BarkGenerationConfig.from_sub_model_configs(
      semantic.generation_config ,  coarseAcoustic.generation_config ,  fineAcoustic.generation_config					)

  __snake_case :					str          =							BarkModel(_lowerCamelCase					)

  __snake_case :					List[Any]          =							semantic
  __snake_case :					List[Any]          =							coarseAcoustic
  __snake_case :					Any          =							fineAcoustic
  __snake_case :					Tuple          =							codec

  __snake_case :					str          =							bark_generation_config

  Path(_lowerCamelCase					).mkdir(exist_ok=_lowerCamelCase					)
  bark.save_pretrained(_lowerCamelCase ,  repo_id=_lowerCamelCase ,  push_to_hub=_lowerCamelCase					)


if __name__ == "__main__":
     _UpperCamelCase							=			argparse.ArgumentParser()
     # Required parameters

     parser.add_argument('''model_type''', type=str, help='''text, coarse or fine.''')
     parser.add_argument('''pytorch_dump_folder_path''', default=None, type=str, help='''Path to the output PyTorch model.''')
     parser.add_argument('''--is_small''', action='''store_true''', help='''convert the small version instead of the large.''')

     _UpperCamelCase							=			parser.parse_args()

     load_model(args.pytorch_dump_folder_path, model_type=args.model_type, use_small=args.is_small)








'''simple docstring'''

import unittest

from transformers import MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING, AutoTokenizer, is_vision_available
from transformers.pipelines import pipeline
from transformers.pipelines.document_question_answering import apply_tesseract
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_detectrona,
    require_pytesseract,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
  from PIL import Image

  from transformers.image_utils import load_image
else:






  class   UpperCAmelCase      :
   @staticmethod
   def 	UpperCAmelCase_				(							*lowercase_ :Optional[Any]		,			**lowercase_ :List[Any]				)->				Optional[int]:
       pass





  def 		UpperCamelCase							(				_lowerCamelCase   :   List[Any]			):
      return None


# This is a pinned image from a specific revision of a document question answering space, hosted by HuggingFace,
# so we can expect it to be available.
__lowerCAmelCase				:      int						      =(
    "https://huggingface.co/spaces/impira/docquery/resolve/2f6c96314dc84dfda62d40de9da55f2f5165d403/invoice.png"
)






@is_pipeline_test
@require_torch
@require_vision
class   UpperCAmelCase      (			unittest.TestCase							):
 __lowercase  						=							MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING
 @require_pytesseract
 @require_vision
 def 	UpperCAmelCase_				(							self :int		,			lowercase_ :Optional[Any]		,			lowercase_ :Optional[Any]		,			lowercase_ :Dict				)->				int:
     A__							=     pipeline(
         "document-question-answering"		,			model=lowercase_		,			tokenizer=lowercase_		,			image_processor=lowercase_				)

     A__							=     INVOICE_URL
     A__							=     list(zip(*apply_tesseract(load_image(lowercase_				)		,			lowercase_		,			""				)				)				)
     A__							=     "What is the placebo?"
     A__							=     [
         {
             "image": load_image(lowercase_				),
             "question": question,
         },
         {
             "image": image,
             "question": question,
         },
         {
             "image": image,
             "question": question,
             "word_boxes": word_boxes,
         },
     ]
     return dqa_pipeline, examples
 def 	UpperCAmelCase_				(							self :str		,			lowercase_ :List[Any]		,			lowercase_ :List[str]				)->				List[str]:
     A__							=     dqa_pipeline(lowercase_		,			top_k=2				)
     self.assertEqual(
         lowercase_		,			[
             [
                 {"score": ANY(lowercase_				), "answer": ANY(lowercase_				), "start": ANY(lowercase_				), "end": ANY(lowercase_				)},
                 {"score": ANY(lowercase_				), "answer": ANY(lowercase_				), "start": ANY(lowercase_				), "end": ANY(lowercase_				)},
             ]
         ]
         * 3		,			)
 @require_torch
 @require_detectrona
 @require_pytesseract
 def 	UpperCAmelCase_				(							self :Dict				)->				Optional[Any]:
     A__							=     pipeline("document-question-answering"		,			model="hf-internal-testing/tiny-random-layoutlmv2"				)
     A__							=     INVOICE_URL
     A__							=     "How many cats are there?"

     A__							=     [
         {"score": 0.0_0_0_1, "answer": "oy 2312/2019", "start": 38, "end": 39},
         {"score": 0.0_0_0_1, "answer": "oy 2312/2019 DUE", "start": 38, "end": 40},
     ]
     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			top_k=2				)
     self.assertEqual(nested_simplify(lowercase_		,			decimals=4				)		,			lowercase_				)

     A__							=     dqa_pipeline({"image": image, "question": question}		,			top_k=2				)
     self.assertEqual(nested_simplify(lowercase_		,			decimals=4				)		,			lowercase_				)

     # This image does not detect ANY text in it, meaning layoutlmv2 should fail.
     # Empty answer probably
     A__							=     "./tests/fixtures/tests_samples/COCO/000000039769.png"
     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			top_k=2				)
     self.assertEqual(lowercase_		,			[]				)

     # We can optionnally pass directly the words and bounding boxes
     A__							=     "./tests/fixtures/tests_samples/COCO/000000039769.png"
     A__							=     []
     A__							=     []
     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			words=lowercase_		,			boxes=lowercase_		,			top_k=2				)
     self.assertEqual(lowercase_		,			[]				)
 @slow
 @require_torch
 @require_detectrona
 @require_pytesseract
 def 	UpperCAmelCase_				(							self :Optional[Any]				)->				Tuple:
     A__							=     pipeline(
         "document-question-answering"		,			model="tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"		,			revision="9977165"		,			)
     A__							=     INVOICE_URL
     A__							=     "What is the invoice number?"

     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.9_9_4_4, "answer": "us-001", "start": 16, "end": 16},
             {"score": 0.0_0_0_9, "answer": "us-001", "start": 16, "end": 16},
         ]		,			)

     A__							=     dqa_pipeline({"image": image, "question": question}		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.9_9_4_4, "answer": "us-001", "start": 16, "end": 16},
             {"score": 0.0_0_0_9, "answer": "us-001", "start": 16, "end": 16},
         ]		,			)

     A__							=     dqa_pipeline(
         [{"image": image, "question": question}, {"image": image, "question": question}]		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             [
                 {"score": 0.9_9_4_4, "answer": "us-001", "start": 16, "end": 16},
                 {"score": 0.0_0_0_9, "answer": "us-001", "start": 16, "end": 16},
             ],
         ]
         * 2		,			)
 @slow
 @require_torch
 @require_detectrona
 @require_pytesseract
 def 	UpperCAmelCase_				(							self :Tuple				)->				Optional[Any]:
     A__							=     pipeline(
         "document-question-answering"		,			model="tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"		,			revision="9977165"		,			max_seq_len=50		,			)
     A__							=     INVOICE_URL
     A__							=     "What is the invoice number?"

     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.9_9_7_4, "answer": "1110212019", "start": 23, "end": 23},
             {"score": 0.9_9_4_8, "answer": "us-001", "start": 16, "end": 16},
         ]		,			)

     A__							=     dqa_pipeline({"image": image, "question": question}		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.9_9_7_4, "answer": "1110212019", "start": 23, "end": 23},
             {"score": 0.9_9_4_8, "answer": "us-001", "start": 16, "end": 16},
         ]		,			)

     A__							=     dqa_pipeline(
         [{"image": image, "question": question}, {"image": image, "question": question}]		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             [
                 {"score": 0.9_9_7_4, "answer": "1110212019", "start": 23, "end": 23},
                 {"score": 0.9_9_4_8, "answer": "us-001", "start": 16, "end": 16},
             ]
         ]
         * 2		,			)
 @slow
 @require_torch
 @require_pytesseract
 @require_vision
 def 	UpperCAmelCase_				(							self :List[Any]				)->				Any:
     A__							=     AutoTokenizer.from_pretrained(
         "impira/layoutlm-document-qa"		,			revision="3dc6de3"		,			add_prefix_space=lowercase_				)
     A__							=     pipeline(
         "document-question-answering"		,			model="impira/layoutlm-document-qa"		,			tokenizer=lowercase_		,			revision="3dc6de3"		,			)
     A__							=     INVOICE_URL
     A__							=     "What is the invoice number?"

     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.4_2_5_1, "answer": "us-001", "start": 16, "end": 16},
             {"score": 0.0_8_1_9, "answer": "1110212019", "start": 23, "end": 23},
         ]		,			)

     A__							=     dqa_pipeline({"image": image, "question": question}		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.4_2_5_1, "answer": "us-001", "start": 16, "end": 16},
             {"score": 0.0_8_1_9, "answer": "1110212019", "start": 23, "end": 23},
         ]		,			)

     A__							=     dqa_pipeline(
         [{"image": image, "question": question}, {"image": image, "question": question}]		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             [
                 {"score": 0.4_2_5_1, "answer": "us-001", "start": 16, "end": 16},
                 {"score": 0.0_8_1_9, "answer": "1110212019", "start": 23, "end": 23},
             ]
         ]
         * 2		,			)

     A__							=     list(zip(*apply_tesseract(load_image(lowercase_				)		,			lowercase_		,			""				)				)				)

     # This model should also work if `image` is set to None
     A__							=     dqa_pipeline({"image": None, "word_boxes": word_boxes, "question": question}		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.4_2_5_1, "answer": "us-001", "start": 16, "end": 16},
             {"score": 0.0_8_1_9, "answer": "1110212019", "start": 23, "end": 23},
         ]		,			)
 @slow
 @require_torch
 @require_pytesseract
 @require_vision
 def 	UpperCAmelCase_				(							self :Optional[int]				)->				Union[str, Any]:
     A__							=     AutoTokenizer.from_pretrained(
         "impira/layoutlm-document-qa"		,			revision="3dc6de3"		,			add_prefix_space=lowercase_				)
     A__							=     pipeline(
         "document-question-answering"		,			model="impira/layoutlm-document-qa"		,			tokenizer=lowercase_		,			revision="3dc6de3"		,			max_seq_len=50		,			)
     A__							=     INVOICE_URL
     A__							=     "What is the invoice number?"

     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.9_9_9_9, "answer": "us-001", "start": 16, "end": 16},
             {"score": 0.9_9_9_8, "answer": "us-001", "start": 16, "end": 16},
         ]		,			)

     A__							=     dqa_pipeline(
         [{"image": image, "question": question}, {"image": image, "question": question}]		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             [
                 {"score": 0.9_9_9_9, "answer": "us-001", "start": 16, "end": 16},
                 {"score": 0.9_9_9_8, "answer": "us-001", "start": 16, "end": 16},
             ]
         ]
         * 2		,			)

     A__							=     list(zip(*apply_tesseract(load_image(lowercase_				)		,			lowercase_		,			""				)				)				)

     # This model should also work if `image` is set to None
     A__							=     dqa_pipeline({"image": None, "word_boxes": word_boxes, "question": question}		,			top_k=2				)
     self.assertEqual(
         nested_simplify(lowercase_		,			decimals=4				)		,			[
             {"score": 0.9_9_9_9, "answer": "us-001", "start": 16, "end": 16},
             {"score": 0.9_9_9_8, "answer": "us-001", "start": 16, "end": 16},
         ]		,			)
 @slow
 @require_torch
 def 	UpperCAmelCase_				(							self :Optional[int]				)->				Tuple:
     A__							=     pipeline(
         "document-question-answering"		,			model="naver-clova-ix/donut-base-finetuned-docvqa"		,			tokenizer=AutoTokenizer.from_pretrained("naver-clova-ix/donut-base-finetuned-docvqa"				)		,			feature_extractor="naver-clova-ix/donut-base-finetuned-docvqa"		,			)

     A__							=     INVOICE_URL
     A__							=     "What is the invoice number?"
     A__							=     dqa_pipeline(image=lowercase_		,			question=lowercase_		,			top_k=2				)
     self.assertEqual(nested_simplify(lowercase_		,			decimals=4				)		,			[{"answer": "us-001"}]				)



 @require_tf
 @unittest.skip("Document question answering not implemented in TF"				)
 def 	UpperCAmelCase_				(							self :Optional[Any]				)->				List[str]:
     pass



