




"""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 					A_    (  *lowercase  ,      **lowercase  ):
										pass







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






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






			'''simple docstring'''



			lowerCamelCase__      =			MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING
			@require_pytesseract
			@require_vision
			def 					A_    (  self  ,      lowercase  ,      lowercase  ,      lowercase  ):
							_lowerCamelCase     :			str    =    pipeline(
							    'document-question-answering'  ,      model=UpperCamelCase__  ,      tokenizer=UpperCamelCase__  ,      image_processor=UpperCamelCase__  )

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

							_lowerCamelCase     :			Dict    =    [
							    {"score": 0.00_01, "answer": "oy 2312/2019", "start": 38, "end": 39},
							    {"score": 0.00_01, "answer": "oy 2312/2019 DUE", "start": 38, "end": 40},
							]
							_lowerCamelCase     :			List[Any]    =    dqa_pipeline(image=UpperCamelCase__  ,      question=UpperCamelCase__  ,      top_k=2  )
							self.assertEqual(nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      UpperCamelCase__  )

							_lowerCamelCase     :			int    =    dqa_pipeline({'image': image, 'question': question}  ,      top_k=2  )
							self.assertEqual(nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      UpperCamelCase__  )

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

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

							_lowerCamelCase     :			int    =    dqa_pipeline(image=UpperCamelCase__  ,      question=UpperCamelCase__  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.99_44, 'answer': 'us-001', 'start': 16, 'end': 16},
							        {'score': 0.00_09, 'answer': 'us-001', 'start': 16, 'end': 16},
							    ]  ,      )

							_lowerCamelCase     :			Tuple    =    dqa_pipeline({'image': image, 'question': question}  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.99_44, 'answer': 'us-001', 'start': 16, 'end': 16},
							        {'score': 0.00_09, 'answer': 'us-001', 'start': 16, 'end': 16},
							    ]  ,      )

							_lowerCamelCase     :			Tuple    =    dqa_pipeline(
							    [{'image': image, 'question': question}, {'image': image, 'question': question}]  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        [
							            {'score': 0.99_44, 'answer': 'us-001', 'start': 16, 'end': 16},
							            {'score': 0.00_09, 'answer': 'us-001', 'start': 16, 'end': 16},
							        ],
							    ]
							    * 2  ,      )
			@slow
			@require_torch
			@require_detectrona
			@require_pytesseract
			def 					A_    (  self  ):
							_lowerCamelCase     :			Optional[int]    =    pipeline(
							    'document-question-answering'  ,      model='tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa'  ,      revision='9977165'  ,      max_seq_len=50  ,      )
							_lowerCamelCase     :			Dict    =    INVOICE_URL
							_lowerCamelCase     :			Optional[Any]    =    "What is the invoice number?"

							_lowerCamelCase     :			Tuple    =    dqa_pipeline(image=UpperCamelCase__  ,      question=UpperCamelCase__  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.99_74, 'answer': '1110212019', 'start': 23, 'end': 23},
							        {'score': 0.99_48, 'answer': 'us-001', 'start': 16, 'end': 16},
							    ]  ,      )

							_lowerCamelCase     :			Optional[Any]    =    dqa_pipeline({'image': image, 'question': question}  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.99_74, 'answer': '1110212019', 'start': 23, 'end': 23},
							        {'score': 0.99_48, 'answer': 'us-001', 'start': 16, 'end': 16},
							    ]  ,      )

							_lowerCamelCase     :			int    =    dqa_pipeline(
							    [{'image': image, 'question': question}, {'image': image, 'question': question}]  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        [
							            {'score': 0.99_74, 'answer': '1110212019', 'start': 23, 'end': 23},
							            {'score': 0.99_48, 'answer': 'us-001', 'start': 16, 'end': 16},
							        ]
							    ]
							    * 2  ,      )
			@slow
			@require_torch
			@require_pytesseract
			@require_vision
			def 					A_    (  self  ):
							_lowerCamelCase     :			str    =    AutoTokenizer.from_pretrained(
							    'impira/layoutlm-document-qa'  ,      revision='3dc6de3'  ,      add_prefix_space=UpperCamelCase__  )
							_lowerCamelCase     :			Dict    =    pipeline(
							    'document-question-answering'  ,      model='impira/layoutlm-document-qa'  ,      tokenizer=UpperCamelCase__  ,      revision='3dc6de3'  ,      )
							_lowerCamelCase     :			Dict    =    INVOICE_URL
							_lowerCamelCase     :			Any    =    "What is the invoice number?"

							_lowerCamelCase     :			Union[str, Any]    =    dqa_pipeline(image=UpperCamelCase__  ,      question=UpperCamelCase__  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.42_51, 'answer': 'us-001', 'start': 16, 'end': 16},
							        {'score': 0.08_19, 'answer': '1110212019', 'start': 23, 'end': 23},
							    ]  ,      )

							_lowerCamelCase     :			Dict    =    dqa_pipeline({'image': image, 'question': question}  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.42_51, 'answer': 'us-001', 'start': 16, 'end': 16},
							        {'score': 0.08_19, 'answer': '1110212019', 'start': 23, 'end': 23},
							    ]  ,      )

							_lowerCamelCase     :			Optional[int]    =    dqa_pipeline(
							    [{'image': image, 'question': question}, {'image': image, 'question': question}]  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        [
							            {'score': 0.42_51, 'answer': 'us-001', 'start': 16, 'end': 16},
							            {'score': 0.08_19, 'answer': '1110212019', 'start': 23, 'end': 23},
							        ]
							    ]
							    * 2  ,      )

							_lowerCamelCase     :			int    =    list(zip(*apply_tesseract(load_image(UpperCamelCase__  )  ,      UpperCamelCase__  ,      ''  )  )  )

							# This model should also work if `image` is set to None
							_lowerCamelCase     :			List[str]    =    dqa_pipeline({'image': None, 'word_boxes': word_boxes, 'question': question}  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.42_51, 'answer': 'us-001', 'start': 16, 'end': 16},
							        {'score': 0.08_19, 'answer': '1110212019', 'start': 23, 'end': 23},
							    ]  ,      )
			@slow
			@require_torch
			@require_pytesseract
			@require_vision
			def 					A_    (  self  ):
							_lowerCamelCase     :			Any    =    AutoTokenizer.from_pretrained(
							    'impira/layoutlm-document-qa'  ,      revision='3dc6de3'  ,      add_prefix_space=UpperCamelCase__  )
							_lowerCamelCase     :			Dict    =    pipeline(
							    'document-question-answering'  ,      model='impira/layoutlm-document-qa'  ,      tokenizer=UpperCamelCase__  ,      revision='3dc6de3'  ,      max_seq_len=50  ,      )
							_lowerCamelCase     :			List[str]    =    INVOICE_URL
							_lowerCamelCase     :			Any    =    "What is the invoice number?"

							_lowerCamelCase     :			str    =    dqa_pipeline(image=UpperCamelCase__  ,      question=UpperCamelCase__  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.99_99, 'answer': 'us-001', 'start': 16, 'end': 16},
							        {'score': 0.99_98, 'answer': 'us-001', 'start': 16, 'end': 16},
							    ]  ,      )

							_lowerCamelCase     :			Dict    =    dqa_pipeline(
							    [{'image': image, 'question': question}, {'image': image, 'question': question}]  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        [
							            {'score': 0.99_99, 'answer': 'us-001', 'start': 16, 'end': 16},
							            {'score': 0.99_98, 'answer': 'us-001', 'start': 16, 'end': 16},
							        ]
							    ]
							    * 2  ,      )

							_lowerCamelCase     :			Tuple    =    list(zip(*apply_tesseract(load_image(UpperCamelCase__  )  ,      UpperCamelCase__  ,      ''  )  )  )

							# This model should also work if `image` is set to None
							_lowerCamelCase     :			Optional[Any]    =    dqa_pipeline({'image': None, 'word_boxes': word_boxes, 'question': question}  ,      top_k=2  )
							self.assertEqual(
							    nested_simplify(UpperCamelCase__  ,      decimals=4  )  ,      [
							        {'score': 0.99_99, 'answer': 'us-001', 'start': 16, 'end': 16},
							        {'score': 0.99_98, 'answer': 'us-001', 'start': 16, 'end': 16},
							    ]  ,      )
			@slow
			@require_torch
			def 					A_    (  self  ):
							_lowerCamelCase     :			Optional[int]    =    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'  ,      )

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






			@require_tf
			@unittest.skip('Document question answering not implemented in TF'  )
			def 					A_    (  self  ):
							pass





from math import sqrt

def      A      (      _SCREAMING_SNAKE_CASE = 100_0000    )	-> int:
       lowerCamelCase   :      int			 =					0
       lowerCamelCase   :      int			 =					0
       lowerCamelCase   :      int

       while num_cuboids <= limit:
              max_cuboid_size += 1
              for sum_shortest_sides in range(2 ,2 * max_cuboid_size + 1    ):
                     if sqrt(sum_shortest_sides**2 + max_cuboid_size**2    ).is_integer():
                            num_cuboids += (
                                min(_SCREAMING_SNAKE_CASE ,sum_shortest_sides // 2    )
                                - max(1 ,sum_shortest_sides - max_cuboid_size    )
                                + 1
                            )

       return max_cuboid_size


if __name__ == "__main__":
       print(f'''{solution() = }''')






