


'''simple docstring'''


import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
				import torch

				from transformers import AutoModelForImageClassification

if is_vision_available():
				from transformers import AutoImageProcessor





@require_torch
@require_vision
class     lowercase__  (						unittest.TestCase					):





							'''simple docstring'''


							@slow
							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       Any     		=      AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""  )
											_SCREAMING_SNAKE_CASE :       Dict     		=      AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""  )
											model.to(__snake_case  )

											from datasets import load_dataset

											_SCREAMING_SNAKE_CASE :       List[Any]     		=      load_dataset("""nielsr/rvlcdip-demo"""  )

											_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      dataset["""train"""][0]["""image"""].convert("""RGB"""  )

											_SCREAMING_SNAKE_CASE :       Dict     		=      image_processor(__snake_case    ,					return_tensors="""pt"""  ).to(__snake_case  )

											# forward pass
											with torch.no_grad():
															_SCREAMING_SNAKE_CASE :       int     		=      model(**__snake_case  )
															_SCREAMING_SNAKE_CASE :       str     		=      outputs.logits

											_SCREAMING_SNAKE_CASE :       List[Any]     		=      torch.Size((1, 16)  )
											self.assertEqual(logits.shape    ,					__snake_case  )

											_SCREAMING_SNAKE_CASE :       List[Any]     		=      torch.tensor(
											    [-0.4158, -0.4092, -0.4347]    ,					device=__snake_case    ,					dtype=torch.float    ,					)
											self.assertTrue(torch.allclose(logits[0, :3]    ,					__snake_case    ,					atol=1e-4  )  )








'''simple docstring'''


import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
				import ctypes
				import msvcrt  # noqa





				class     lowercase__  (						ctypes.Structure					):





											'''simple docstring'''


											A_							:      Optional[Any]      	=  [("""size""", ctypes.c_int), ("""visible""", ctypes.c_byte)]







def 			snake_case_   (  ):







				"""simple docstring"""





				if os.name == "nt":
								_SCREAMING_SNAKE_CASE :       Tuple     		=      CursorInfo()
								_SCREAMING_SNAKE_CASE :       Tuple     		=      ctypes.windll.kernelaa.GetStdHandle(-11     )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
								_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      False
								ctypes.windll.kernelaa.SetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25l"""     )
								sys.stdout.flush()







def 			snake_case_   (  ):







				"""simple docstring"""





				if os.name == "nt":
								_SCREAMING_SNAKE_CASE :       int     		=      CursorInfo()
								_SCREAMING_SNAKE_CASE :       List[str]     		=      ctypes.windll.kernelaa.GetStdHandle(-11     )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
								_SCREAMING_SNAKE_CASE :       Tuple     		=      True
								ctypes.windll.kernelaa.SetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25h"""     )
								sys.stdout.flush()







@contextmanager
def 			snake_case_   (  ):







				"""simple docstring"""





				try:
								hide_cursor()
								yield
				finally:
								show_cursor()




