






import gc
import unittest

import numpy as np
import torch

from diffusers import (
    AudioDiffusionPipeline,
    AutoencoderKL,
    DDIMScheduler,
    DDPMScheduler,
    DiffusionPipeline,
    Mel,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






class _UpperCamelCase							(							unittest.TestCase   ):
			'''simple docstring'''







			def 							__UpperCamelCase (			self							: str	)							->       Optional[int]:

				"""simple docstring"""

				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()
			@property
			def 							__UpperCamelCase (			self							: Optional[int]	)							->       Tuple:

				"""simple docstring"""

				torch.manual_seed(0	)
				SCREAMING_SNAKE_CASE   :      Tuple				     =       UNetaDModel(
				    sample_size=(32, 64)      ,      in_channels=1      ,      out_channels=1      ,      layers_per_block=2      ,      block_out_channels=(128, 128)      ,      down_block_types=("AttnDownBlock2D", "DownBlock2D")      ,      up_block_types=("UpBlock2D", "AttnUpBlock2D")      ,      )
				return model
			@property
			def 							__UpperCamelCase (			self							: Union[str, Any]	)							->       str:

				"""simple docstring"""

				torch.manual_seed(0	)
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       UNetaDConditionModel(
				    sample_size=(64, 32)      ,      in_channels=1      ,      out_channels=1      ,      layers_per_block=2      ,      block_out_channels=(128, 128)      ,      down_block_types=("CrossAttnDownBlock2D", "DownBlock2D")      ,      up_block_types=("UpBlock2D", "CrossAttnUpBlock2D")      ,      cross_attention_dim=10      ,      )
				return model
			@property
			def 							__UpperCamelCase (			self							: Union[str, Any]	)							->       Union[str, Any]:

				"""simple docstring"""

				torch.manual_seed(0	)
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       AutoencoderKL(
				    sample_size=(128, 64)      ,      in_channels=1      ,      out_channels=1      ,      latent_channels=1      ,      layers_per_block=2      ,      block_out_channels=(128, 128)      ,      down_block_types=("DownEncoderBlock2D", "DownEncoderBlock2D")      ,      up_block_types=("UpDecoderBlock2D", "UpDecoderBlock2D")      ,      )
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       UNetaDModel(
				    sample_size=(64, 32)      ,      in_channels=1      ,      out_channels=1      ,      layers_per_block=2      ,      block_out_channels=(128, 128)      ,      down_block_types=("AttnDownBlock2D", "DownBlock2D")      ,      up_block_types=("UpBlock2D", "AttnUpBlock2D")      ,      )
				return vqvae, unet






			@slow
			def 							__UpperCamelCase (			self							: str	)							->       Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      Tuple				     =       "cpu"  # ensure determinism for the device-dependent torch.Generator
				SCREAMING_SNAKE_CASE   :      Tuple				     =       Mel(
				    x_res=self.dummy_unet.config.sample_size[1]      ,      y_res=self.dummy_unet.config.sample_size[0]      ,      )

				SCREAMING_SNAKE_CASE   :      int				     =       DDPMScheduler()
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       AudioDiffusionPipeline(vqvae=a      ,      unet=self.dummy_unet      ,      mel=a      ,      scheduler=a	)
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       pipe.to(a	)
				pipe.set_progress_bar_config(disable=a	)

				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       torch.Generator(device=a	).manual_seed(42	)
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       pipe(generator=a      ,      steps=4	)
				SCREAMING_SNAKE_CASE   :      Tuple				     =       output.audios[0]
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       output.images[0]

				SCREAMING_SNAKE_CASE   :      Tuple				     =       torch.Generator(device=a	).manual_seed(42	)
				SCREAMING_SNAKE_CASE   :      Any				     =       pipe(generator=a      ,      steps=4      ,      return_dict=a	)
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       output[0][0]

				assert audio.shape == (1, (self.dummy_unet.config.sample_size[1] - 1) * mel.hop_length)
				assert (
				    image.height == self.dummy_unet.config.sample_size[0]
				    and image.width == self.dummy_unet.config.sample_size[1]
				)
				SCREAMING_SNAKE_CASE   :      Tuple				     =       np.frombuffer(image.tobytes()      ,      dtype="uint8"	)[:10]
				SCREAMING_SNAKE_CASE   :      Any				     =       np.frombuffer(image_from_tuple.tobytes()      ,      dtype="uint8"	)[:10]
				SCREAMING_SNAKE_CASE   :      Any				     =       np.array([69, 255, 255, 255, 0, 0, 77, 181, 12, 127]	)

				assert np.abs(image_slice.flatten() - expected_slice	).max() == 0
				assert np.abs(image_from_tuple_slice.flatten() - expected_slice	).max() == 0

				SCREAMING_SNAKE_CASE   :      Dict				     =       Mel(
				    x_res=self.dummy_vqvae_and_unet[0].config.sample_size[1]      ,      y_res=self.dummy_vqvae_and_unet[0].config.sample_size[0]      ,      )

				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       DDIMScheduler()
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       self.dummy_vqvae_and_unet
				SCREAMING_SNAKE_CASE   :      Dict				     =       AudioDiffusionPipeline(
				    vqvae=self.dummy_vqvae_and_unet[0]      ,      unet=dummy_vqvae_and_unet[1]      ,      mel=a      ,      scheduler=a	)
				SCREAMING_SNAKE_CASE   :      Any				     =       pipe.to(a	)
				pipe.set_progress_bar_config(disable=a	)

				np.random.seed(0	)
				SCREAMING_SNAKE_CASE   :      Tuple				     =       np.random.uniform(-1      ,      1      ,      ((dummy_vqvae_and_unet[0].config.sample_size[1] - 1) * mel.hop_length,)	)
				SCREAMING_SNAKE_CASE   :      Dict				     =       torch.Generator(device=a	).manual_seed(42	)
				SCREAMING_SNAKE_CASE   :      Any				     =       pipe(raw_audio=a      ,      generator=a      ,      start_step=5      ,      steps=10	)
				SCREAMING_SNAKE_CASE   :      List[str]				     =       output.images[0]

				assert (
				    image.height == self.dummy_vqvae_and_unet[0].config.sample_size[0]
				    and image.width == self.dummy_vqvae_and_unet[0].config.sample_size[1]
				)
				SCREAMING_SNAKE_CASE   :      List[str]				     =       np.frombuffer(image.tobytes()      ,      dtype="uint8"	)[:10]
				SCREAMING_SNAKE_CASE   :      Dict				     =       np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]	)

				assert np.abs(image_slice.flatten() - expected_slice	).max() == 0

				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       self.dummy_unet_condition
				SCREAMING_SNAKE_CASE   :      Dict				     =       AudioDiffusionPipeline(
				    vqvae=self.dummy_vqvae_and_unet[0]      ,      unet=a      ,      mel=a      ,      scheduler=a	)
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       pipe.to(a	)
				pipe.set_progress_bar_config(disable=a	)

				np.random.seed(0	)
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       torch.rand((1, 1, 10)	)
				SCREAMING_SNAKE_CASE   :      Tuple				     =       pipe(generator=a      ,      encoding=a	)
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       output.images[0]
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       np.frombuffer(image.tobytes()      ,      dtype="uint8"	)[:10]
				SCREAMING_SNAKE_CASE   :      Any				     =       np.array([107, 103, 120, 127, 142, 122, 113, 122, 97, 111]	)

				assert np.abs(image_slice.flatten() - expected_slice	).max() == 0






@slow
@require_torch_gpu
class _UpperCamelCase							(							unittest.TestCase   ):
			'''simple docstring'''







			def 							__UpperCamelCase (			self							: Dict	)							->       str:

				"""simple docstring"""

				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()






			def 							__UpperCamelCase (			self							: Dict	)							->       int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      Tuple				     =       torch_device

				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       DiffusionPipeline.from_pretrained("teticio/audio-diffusion-ddim-256"	)
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       pipe.to(a	)
				pipe.set_progress_bar_config(disable=a	)

				SCREAMING_SNAKE_CASE   :      Tuple				     =       torch.Generator(device=a	).manual_seed(42	)
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       pipe(generator=a	)
				SCREAMING_SNAKE_CASE   :      Tuple				     =       output.audios[0]
				SCREAMING_SNAKE_CASE   :      Tuple				     =       output.images[0]

				assert audio.shape == (1, (pipe.unet.config.sample_size[1] - 1) * pipe.mel.hop_length)
				assert image.height == pipe.unet.config.sample_size[0] and image.width == pipe.unet.config.sample_size[1]
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       np.frombuffer(image.tobytes()      ,      dtype="uint8"	)[:10]
				SCREAMING_SNAKE_CASE   :      int				     =       np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]	)

				assert np.abs(image_slice.flatten() - expected_slice	).max() == 0


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							:
						'''simple docstring'''







						@staticmethod
						def 							__UpperCamelCase (			*a							: Any      ,      **a							: Optional[int]	)							->       Optional[Any]:

							"""simple docstring"""

							pass

			def  lowerCamelCase__ (					_a):
				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.
a_						     =    (
    'https://huggingface.co/spaces/impira/docquery/resolve/2f6c96314dc84dfda62d40de9da55f2f5165d403/invoice.png'
)






@is_pipeline_test
@require_torch
@require_vision
class _UpperCamelCase							(							unittest.TestCase   ):
			'''simple docstring'''







			lowerCamelCase__           =MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING
			@require_pytesseract
			@require_vision
			def 							__UpperCamelCase (			self							: Tuple      ,      a							: Union[str, Any]      ,      a							: Any      ,      a							: Optional[Any]	)							->       List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      int				     =       pipeline(
				    "document-question-answering"      ,      model=a      ,      tokenizer=a      ,      image_processor=a	)

				SCREAMING_SNAKE_CASE   :      Dict				     =       INVOICE_URL
				SCREAMING_SNAKE_CASE   :      int				     =       list(zip(*apply_tesseract(load_image(a	)      ,      a      ,      ""	)	)	)
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       "What is the placebo?"
				SCREAMING_SNAKE_CASE   :      List[str]				     =       [
				    {
				        "image": load_image(a	),
				        "question": question,
				    },
				    {
				        "image": image,
				        "question": question,
				    },
				    {
				        "image": image,
				        "question": question,
				        "word_boxes": word_boxes,
				    },
				]
				return dqa_pipeline, examples
			def 							__UpperCamelCase (			self							: List[str]      ,      a							: List[Any]      ,      a							: Any	)							->       Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       dqa_pipeline(a      ,      top_k=2	)
				self.assertEqual(
				    a      ,      [
				        [
				            {"score": ANY(a	), "answer": ANY(a	), "start": ANY(a	), "end": ANY(a	)},
				            {"score": ANY(a	), "answer": ANY(a	), "start": ANY(a	), "end": ANY(a	)},
				        ]
				    ]
				    * 3      ,      )
			@require_torch
			@require_detectrona
			@require_pytesseract
			def 							__UpperCamelCase (			self							: Optional[int]	)							->       Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      List[Any]				     =       pipeline("document-question-answering"      ,      model="hf-internal-testing/tiny-random-layoutlmv2"	)
				SCREAMING_SNAKE_CASE   :      int				     =       INVOICE_URL
				SCREAMING_SNAKE_CASE   :      int				     =       "How many cats are there?"

				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       [
				    {"score": 0.0001, "answer": "oy 2312/2019", "start": 38, "end": 39},
				    {"score": 0.0001, "answer": "oy 2312/2019 DUE", "start": 38, "end": 40},
				]
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       dqa_pipeline(image=a      ,      question=a      ,      top_k=2	)
				self.assertEqual(nested_simplify(a      ,      decimals=4	)      ,      a	)

				SCREAMING_SNAKE_CASE   :      Any				     =       dqa_pipeline({"image": image, "question": question}      ,      top_k=2	)
				self.assertEqual(nested_simplify(a      ,      decimals=4	)      ,      a	)

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

				# We can optionnally pass directly the words and bounding boxes
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       "./tests/fixtures/tests_samples/COCO/000000039769.png"
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       []
				SCREAMING_SNAKE_CASE   :      int				     =       []
				SCREAMING_SNAKE_CASE   :      str				     =       dqa_pipeline(image=a      ,      question=a      ,      words=a      ,      boxes=a      ,      top_k=2	)
				self.assertEqual(a      ,      []	)
			@slow
			@require_torch
			@require_detectrona
			@require_pytesseract
			def 							__UpperCamelCase (			self							: Optional[int]	)							->       Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      List[Any]				     =       pipeline(
				    "document-question-answering"      ,      model="tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"      ,      revision="9977165"      ,      )
				SCREAMING_SNAKE_CASE   :      Any				     =       INVOICE_URL
				SCREAMING_SNAKE_CASE   :      Any				     =       "What is the invoice number?"

				SCREAMING_SNAKE_CASE   :      Dict				     =       dqa_pipeline(image=a      ,      question=a      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.9944, "answer": "us-001", "start": 16, "end": 16},
				        {"score": 0.0009, "answer": "us-001", "start": 16, "end": 16},
				    ]      ,      )

				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       dqa_pipeline({"image": image, "question": question}      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.9944, "answer": "us-001", "start": 16, "end": 16},
				        {"score": 0.0009, "answer": "us-001", "start": 16, "end": 16},
				    ]      ,      )

				SCREAMING_SNAKE_CASE   :      Any				     =       dqa_pipeline(
				    [{"image": image, "question": question}, {"image": image, "question": question}]      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        [
				            {"score": 0.9944, "answer": "us-001", "start": 16, "end": 16},
				            {"score": 0.0009, "answer": "us-001", "start": 16, "end": 16},
				        ],
				    ]
				    * 2      ,      )
			@slow
			@require_torch
			@require_detectrona
			@require_pytesseract
			def 							__UpperCamelCase (			self							: Tuple	)							->       Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       pipeline(
				    "document-question-answering"      ,      model="tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"      ,      revision="9977165"      ,      max_seq_len=50      ,      )
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       INVOICE_URL
				SCREAMING_SNAKE_CASE   :      int				     =       "What is the invoice number?"

				SCREAMING_SNAKE_CASE   :      Any				     =       dqa_pipeline(image=a      ,      question=a      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.9974, "answer": "1110212019", "start": 23, "end": 23},
				        {"score": 0.9948, "answer": "us-001", "start": 16, "end": 16},
				    ]      ,      )

				SCREAMING_SNAKE_CASE   :      Tuple				     =       dqa_pipeline({"image": image, "question": question}      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.9974, "answer": "1110212019", "start": 23, "end": 23},
				        {"score": 0.9948, "answer": "us-001", "start": 16, "end": 16},
				    ]      ,      )

				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       dqa_pipeline(
				    [{"image": image, "question": question}, {"image": image, "question": question}]      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        [
				            {"score": 0.9974, "answer": "1110212019", "start": 23, "end": 23},
				            {"score": 0.9948, "answer": "us-001", "start": 16, "end": 16},
				        ]
				    ]
				    * 2      ,      )
			@slow
			@require_torch
			@require_pytesseract
			@require_vision
			def 							__UpperCamelCase (			self							: Union[str, Any]	)							->       Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       AutoTokenizer.from_pretrained(
				    "impira/layoutlm-document-qa"      ,      revision="3dc6de3"      ,      add_prefix_space=a	)
				SCREAMING_SNAKE_CASE   :      List[str]				     =       pipeline(
				    "document-question-answering"      ,      model="impira/layoutlm-document-qa"      ,      tokenizer=a      ,      revision="3dc6de3"      ,      )
				SCREAMING_SNAKE_CASE   :      List[str]				     =       INVOICE_URL
				SCREAMING_SNAKE_CASE   :      int				     =       "What is the invoice number?"

				SCREAMING_SNAKE_CASE   :      str				     =       dqa_pipeline(image=a      ,      question=a      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.4251, "answer": "us-001", "start": 16, "end": 16},
				        {"score": 0.0819, "answer": "1110212019", "start": 23, "end": 23},
				    ]      ,      )

				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       dqa_pipeline({"image": image, "question": question}      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.4251, "answer": "us-001", "start": 16, "end": 16},
				        {"score": 0.0819, "answer": "1110212019", "start": 23, "end": 23},
				    ]      ,      )

				SCREAMING_SNAKE_CASE   :      Dict				     =       dqa_pipeline(
				    [{"image": image, "question": question}, {"image": image, "question": question}]      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        [
				            {"score": 0.4251, "answer": "us-001", "start": 16, "end": 16},
				            {"score": 0.0819, "answer": "1110212019", "start": 23, "end": 23},
				        ]
				    ]
				    * 2      ,      )

				SCREAMING_SNAKE_CASE   :      int				     =       list(zip(*apply_tesseract(load_image(a	)      ,      a      ,      ""	)	)	)

				# This model should also work if `image` is set to None
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       dqa_pipeline({"image": None, "word_boxes": word_boxes, "question": question}      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.4251, "answer": "us-001", "start": 16, "end": 16},
				        {"score": 0.0819, "answer": "1110212019", "start": 23, "end": 23},
				    ]      ,      )
			@slow
			@require_torch
			@require_pytesseract
			@require_vision
			def 							__UpperCamelCase (			self							: Tuple	)							->       List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      int				     =       AutoTokenizer.from_pretrained(
				    "impira/layoutlm-document-qa"      ,      revision="3dc6de3"      ,      add_prefix_space=a	)
				SCREAMING_SNAKE_CASE   :      Dict				     =       pipeline(
				    "document-question-answering"      ,      model="impira/layoutlm-document-qa"      ,      tokenizer=a      ,      revision="3dc6de3"      ,      max_seq_len=50      ,      )
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       INVOICE_URL
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       "What is the invoice number?"

				SCREAMING_SNAKE_CASE   :      Dict				     =       dqa_pipeline(image=a      ,      question=a      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.9999, "answer": "us-001", "start": 16, "end": 16},
				        {"score": 0.9998, "answer": "us-001", "start": 16, "end": 16},
				    ]      ,      )

				SCREAMING_SNAKE_CASE   :      int				     =       dqa_pipeline(
				    [{"image": image, "question": question}, {"image": image, "question": question}]      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        [
				            {"score": 0.9999, "answer": "us-001", "start": 16, "end": 16},
				            {"score": 0.9998, "answer": "us-001", "start": 16, "end": 16},
				        ]
				    ]
				    * 2      ,      )

				SCREAMING_SNAKE_CASE   :      int				     =       list(zip(*apply_tesseract(load_image(a	)      ,      a      ,      ""	)	)	)

				# This model should also work if `image` is set to None
				SCREAMING_SNAKE_CASE   :      Any				     =       dqa_pipeline({"image": None, "word_boxes": word_boxes, "question": question}      ,      top_k=2	)
				self.assertEqual(
				    nested_simplify(a      ,      decimals=4	)      ,      [
				        {"score": 0.9999, "answer": "us-001", "start": 16, "end": 16},
				        {"score": 0.9998, "answer": "us-001", "start": 16, "end": 16},
				    ]      ,      )
			@slow
			@require_torch
			def 							__UpperCamelCase (			self							: str	)							->       int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      List[str]				     =       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"      ,      )

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






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

				"""simple docstring"""

				pass