
"""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 		UpperCAmelCase_						(unittest.TestCase    ):
 """simple docstring"""




 @slow
 def 	a   (			self							:			int			)->       Tuple:



      """simple docstring"""

      UpperCAmelCase_    :     Optional[int]            =	AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""			)
      UpperCAmelCase_    :     List[Any]            =	AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""			)
      model.to(a_			)

      from datasets import load_dataset

      UpperCAmelCase_    :     Optional[Any]            =	load_dataset("""nielsr/rvlcdip-demo"""			)

      UpperCAmelCase_    :     str            =	dataset["""train"""][0]["""image"""].convert("""RGB"""			)

      UpperCAmelCase_    :     Union[str, Any]            =	image_processor(a_  , return_tensors="""pt"""			).to(a_			)

      # forward pass
      with torch.no_grad():
           UpperCAmelCase_    :     Optional[int]            =	model(**a_			)
           UpperCAmelCase_    :     Union[str, Any]            =	outputs.logits

      UpperCAmelCase_    :     Optional[Any]            =	torch.Size((1, 16)			)
      self.assertEqual(logits.shape  , a_			)

      UpperCAmelCase_    :     Any            =	torch.tensor(
          [-0.4158, -0.4092, -0.4347]  , device=a_  , dtype=torch.float  , )
      self.assertTrue(torch.allclose(logits[0, :3]  , a_  , atol=1E-4			)			)



"""simple docstring"""







from typing import Optional
from urllib.parse import quote

import huggingface_hub as hfh
from packaging import version




def       A_      (       lowercase    ,			lowercase    ,			lowercase = None   )  ->				str:


     """simple docstring"""







     if version.parse(hfh.__version__   ).release < version.parse("""0.11.0"""   ).release:
          # old versions of hfh don't url-encode the file path
          UpperCAmelCase_    :     Tuple            =	quote(lowercase   )
     return hfh.hf_hub_url(lowercase    ,			lowercase    ,			repo_type="""dataset"""    ,			revision=lowercase   )

