
"""simple docstring"""




import copy
from collections import OrderedDict
from typing import Dict, Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


UpperCAmelCase__   :					Optional[Any]												=				logging.get_logger(__name__)

UpperCAmelCase__   :					str												=				{
    'facebook/detr-resnet-50': 'https://huggingface.co/facebook/detr-resnet-50/resolve/main/config.json',
    # See all DETR models at https://huggingface.co/models?filter=detr
}



class 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				__UpperCamelCase   :		List[Any]       =     '''detr'''
				__UpperCamelCase   :		List[Any]       =     ['''past_key_values''']
				__UpperCamelCase   :		List[Any]       =     {
				    '''hidden_size''': '''d_model''',
				    '''num_attention_heads''': '''encoder_attention_heads''',
				}



				def __init__(self     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=None     , SCREAMING_SNAKE_CASE__=3     , SCREAMING_SNAKE_CASE__=1_00     , SCREAMING_SNAKE_CASE__=6     , SCREAMING_SNAKE_CASE__=20_48     , SCREAMING_SNAKE_CASE__=8     , SCREAMING_SNAKE_CASE__=6     , SCREAMING_SNAKE_CASE__=20_48     , SCREAMING_SNAKE_CASE__=8     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__="relu"     , SCREAMING_SNAKE_CASE__=2_56     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.02     , SCREAMING_SNAKE_CASE__=1.0     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__="sine"     , SCREAMING_SNAKE_CASE__="resnet50"     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=5     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=5     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=0.1     , **SCREAMING_SNAKE_CASE__     , )      ->	Optional[Any]:



											"""simple docstring"""




											if backbone_config is not None and use_timm_backbone:
																		raise ValueError("""You can't specify both `backbone_config` and `use_timm_backbone`."""					)

											if not use_timm_backbone:
																		if backbone_config is None:
																									logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""					)
																									SCREAMING_SNAKE_CASE__		: Any     =     CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]					)
																		elif isinstance(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					):
																									SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     backbone_config.get("""model_type"""					)
																									SCREAMING_SNAKE_CASE__		: int     =     CONFIG_MAPPING[backbone_model_type]
																									SCREAMING_SNAKE_CASE__		: str     =     config_class.from_dict(SCREAMING_SNAKE_CASE__					)
																		# set timm attributes to None
																		SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: List[str]     =     None, None, None

											SCREAMING_SNAKE_CASE__		: Optional[int]     =     use_timm_backbone
											SCREAMING_SNAKE_CASE__		: Tuple     =     backbone_config
											SCREAMING_SNAKE_CASE__		: List[Any]     =     num_channels
											SCREAMING_SNAKE_CASE__		: Tuple     =     num_queries
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     d_model
											SCREAMING_SNAKE_CASE__		: str     =     encoder_ffn_dim
											SCREAMING_SNAKE_CASE__		: str     =     encoder_layers
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     encoder_attention_heads
											SCREAMING_SNAKE_CASE__		: Any     =     decoder_ffn_dim
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     decoder_layers
											SCREAMING_SNAKE_CASE__		: Dict     =     decoder_attention_heads
											SCREAMING_SNAKE_CASE__		: List[str]     =     dropout
											SCREAMING_SNAKE_CASE__		: Tuple     =     attention_dropout
											SCREAMING_SNAKE_CASE__		: Tuple     =     activation_dropout
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     activation_function
											SCREAMING_SNAKE_CASE__		: Any     =     init_std
											SCREAMING_SNAKE_CASE__		: Dict     =     init_xavier_std
											SCREAMING_SNAKE_CASE__		: Any     =     encoder_layerdrop
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     decoder_layerdrop
											SCREAMING_SNAKE_CASE__		: Dict     =     encoder_layers
											SCREAMING_SNAKE_CASE__		: List[str]     =     auxiliary_loss
											SCREAMING_SNAKE_CASE__		: List[Any]     =     position_embedding_type
											SCREAMING_SNAKE_CASE__		: List[str]     =     backbone
											SCREAMING_SNAKE_CASE__		: Dict     =     use_pretrained_backbone
											SCREAMING_SNAKE_CASE__		: Any     =     dilation
											# Hungarian matcher
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     class_cost
											SCREAMING_SNAKE_CASE__		: Tuple     =     bbox_cost
											SCREAMING_SNAKE_CASE__		: List[Any]     =     giou_cost
											# Loss coefficients
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     mask_loss_coefficient
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     dice_loss_coefficient
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     bbox_loss_coefficient
											SCREAMING_SNAKE_CASE__		: Any     =     giou_loss_coefficient
											SCREAMING_SNAKE_CASE__		: List[str]     =     eos_coefficient
											super().__init__(is_encoder_decoder=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)



				@property
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											return self.encoder_attention_heads



				@property
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											return self.d_model



				@classmethod
				def 			__magic_name__					(cls     , SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)      ->	Tuple:



											"""simple docstring"""




											return cls(backbone_config=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)



				def 			__magic_name__					(self					)      ->	Dict[str, any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Dict     =     copy.deepcopy(self.__dict__					)
											if output["backbone_config"] is not None:
																		SCREAMING_SNAKE_CASE__		: Any     =     self.backbone_config.to_dict()
											SCREAMING_SNAKE_CASE__		: Dict     =     self.__class__.model_type
											return output






class 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				__UpperCamelCase   :		Any       =     version.parse('''1.11'''						)



				@property
				def 			__magic_name__					(self					)      ->	Mapping[str, Mapping[int, str]]:



											"""simple docstring"""




											return OrderedDict(
											    [
											        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
											        ("""pixel_mask""", {0: """batch"""}),
											    ]					)



				@property
				def 			__magic_name__					(self					)      ->	float:



											"""simple docstring"""




											return 1E-5



				@property
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											return 12






"""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 			lowerCAmelCase_		:


									"""simple docstring"""



									@staticmethod
									def 			__magic_name__					(*SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)      ->	Union[str, Any]:



																"""simple docstring"""




																pass






					def lowercase_						(     _snake_case		):
												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.
UpperCAmelCase__   :					str												=				(
    'https://huggingface.co/spaces/impira/docquery/resolve/2f6c96314dc84dfda62d40de9da55f2f5165d403/invoice.png'
)



@is_pipeline_test
@require_torch
@require_vision
class 			lowerCAmelCase_		(unittest.TestCase						):


				"""simple docstring"""



				__UpperCamelCase   :		List[Any]       =     MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING



				@require_pytesseract
				@require_vision
				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)      ->	Optional[Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[str]     =     pipeline(
											    """document-question-answering"""     , model=SCREAMING_SNAKE_CASE__     , tokenizer=SCREAMING_SNAKE_CASE__     , image_processor=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     INVOICE_URL
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     list(zip(*apply_tesseract(load_image(SCREAMING_SNAKE_CASE__					)     , SCREAMING_SNAKE_CASE__     , """"""					)					)					)
											SCREAMING_SNAKE_CASE__		: Any     =     """What is the placebo?"""
											SCREAMING_SNAKE_CASE__		: Dict     =     [
											    {
											        """image""": load_image(SCREAMING_SNAKE_CASE__					),
											        """question""": question,
											    },
											    {
											        """image""": image,
											        """question""": question,
											    },
											    {
											        """image""": image,
											        """question""": question,
											        """word_boxes""": word_boxes,
											    },
											]
											return dqa_pipeline, examples



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)      ->	List[Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Tuple     =     dqa_pipeline(SCREAMING_SNAKE_CASE__     , top_k=2					)
											self.assertEqual(
											    SCREAMING_SNAKE_CASE__     , [
											        [
											            {"""score""": ANY(SCREAMING_SNAKE_CASE__					), """answer""": ANY(SCREAMING_SNAKE_CASE__					), """start""": ANY(SCREAMING_SNAKE_CASE__					), """end""": ANY(SCREAMING_SNAKE_CASE__					)},
											            {"""score""": ANY(SCREAMING_SNAKE_CASE__					), """answer""": ANY(SCREAMING_SNAKE_CASE__					), """start""": ANY(SCREAMING_SNAKE_CASE__					), """end""": ANY(SCREAMING_SNAKE_CASE__					)},
											        ]
											    ]
											    * 3     , )



				@require_torch
				@require_detectrona
				@require_pytesseract
				def 			__magic_name__					(self					)      ->	List[Any]:



											"""simple docstring"""




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

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     [
											    {"""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__		: Any     =     dqa_pipeline(image=SCREAMING_SNAKE_CASE__     , question=SCREAMING_SNAKE_CASE__     , top_k=2					)
											self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     , decimals=4					)     , SCREAMING_SNAKE_CASE__					)

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

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

											# We can optionnally pass directly the words and bounding boxes
											SCREAMING_SNAKE_CASE__		: Tuple     =     """./tests/fixtures/tests_samples/COCO/000000039769.png"""
											SCREAMING_SNAKE_CASE__		: Dict     =     []
											SCREAMING_SNAKE_CASE__		: Any     =     []
											SCREAMING_SNAKE_CASE__		: Dict     =     dqa_pipeline(image=SCREAMING_SNAKE_CASE__     , question=SCREAMING_SNAKE_CASE__     , words=SCREAMING_SNAKE_CASE__     , boxes=SCREAMING_SNAKE_CASE__     , top_k=2					)
											self.assertEqual(SCREAMING_SNAKE_CASE__     , []					)



				@slow
				@require_torch
				@require_detectrona
				@require_pytesseract
				def 			__magic_name__					(self					)      ->	List[str]:



											"""simple docstring"""




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

											SCREAMING_SNAKE_CASE__		: List[str]     =     dqa_pipeline(image=SCREAMING_SNAKE_CASE__     , question=SCREAMING_SNAKE_CASE__     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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__		: Tuple     =     dqa_pipeline({"""image""": image, """question""": question}     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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[int]     =     dqa_pipeline(
											    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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 			__magic_name__					(self					)      ->	List[str]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[str]     =     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__		: Union[str, Any]     =     """What is the invoice number?"""

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

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

											SCREAMING_SNAKE_CASE__		: List[str]     =     dqa_pipeline(
											    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




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

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

											SCREAMING_SNAKE_CASE__		: str     =     dqa_pipeline({"""image""": image, """question""": question}     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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(SCREAMING_SNAKE_CASE__     , 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__		: Optional[Any]     =     list(zip(*apply_tesseract(load_image(SCREAMING_SNAKE_CASE__					)     , SCREAMING_SNAKE_CASE__     , """"""					)					)					)

											# This model should also work if `image` is set to None
											SCREAMING_SNAKE_CASE__		: Dict     =     dqa_pipeline({"""image""": None, """word_boxes""": word_boxes, """question""": question}     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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 			__magic_name__					(self					)      ->	List[str]:



											"""simple docstring"""




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

											SCREAMING_SNAKE_CASE__		: Optional[int]     =     dqa_pipeline(image=SCREAMING_SNAKE_CASE__     , question=SCREAMING_SNAKE_CASE__     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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__		: Union[str, Any]     =     dqa_pipeline(
											    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]     , top_k=2					)
											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE__     , 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__		: Any     =     list(zip(*apply_tesseract(load_image(SCREAMING_SNAKE_CASE__					)     , SCREAMING_SNAKE_CASE__     , """"""					)					)					)

											# 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(SCREAMING_SNAKE_CASE__     , 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 			__magic_name__					(self					)      ->	Optional[Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Tuple     =     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__		: Union[str, Any]     =     INVOICE_URL
											SCREAMING_SNAKE_CASE__		: List[Any]     =     """What is the invoice number?"""
											SCREAMING_SNAKE_CASE__		: int     =     dqa_pipeline(image=SCREAMING_SNAKE_CASE__     , question=SCREAMING_SNAKE_CASE__     , top_k=2					)
											self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     , decimals=4					)     , [{"""answer""": """us-001"""}]					)



				@require_tf
				@unittest.skip("""Document question answering not implemented in TF"""					)
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											pass




