




'''simple docstring'''
import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
  from PIL import Image






class        SCREAMING_SNAKE_CASE(				unittest.TestCase   ,      a_     ):

       def     snake_case__			(    self     )    ->					List[Any]:

           """simple docstring"""



           __lowercase							=						load_tool("""image-captioning"""     )
           self.tool.setup()
           __lowercase							=						load_tool("""image-captioning"""					,		remote=lowerCamelCase__     )

       def     snake_case__			(    self     )    ->					int:

           """simple docstring"""



           __lowercase							=						Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
           __lowercase							=						self.tool(lowerCamelCase__     )
           self.assertEqual(lowerCamelCase__					,		"""two cats sleeping on a couch"""     )

       def     snake_case__			(    self     )    ->					Tuple:

           """simple docstring"""



           __lowercase							=						Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
           __lowercase							=						self.remote_tool(lowerCamelCase__     )
           self.assertEqual(lowerCamelCase__					,		"""two cats sleeping on a couch"""     )

       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           __lowercase							=						Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
           __lowercase							=						self.tool(image=lowerCamelCase__     )
           self.assertEqual(lowerCamelCase__					,		"""two cats sleeping on a couch"""     )




       def     snake_case__			(    self     )    ->					Any:

           """simple docstring"""



           __lowercase							=						Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
           __lowercase							=						self.remote_tool(image=lowerCamelCase__     )
           self.assertEqual(lowerCamelCase__					,		"""two cats sleeping on a couch"""     )







import importlib.metadata
import subprocess
import sys





def 	snake_case_      (__A     :						bool = False     )			->	str:
   __lowerCAmelCase  :			Any					    =						False
   if "IPython" in sys.modules:
      __lowerCAmelCase  :			Optional[int]					    =						"""google.colab""" in str(sys.modules["""IPython"""].get_ipython()     )

   if in_colab:
      if upgrade:
         __lowerCAmelCase  :			int					    =						["""pip""", """install""", """-U""", """torch"""]
         subprocess.run(__A					,   check=__A     )
      # get the current version of torch
      __lowerCAmelCase  :			List[Any]					    =						importlib.metadata.version("""torch"""     )
      __lowerCAmelCase  :			List[Any]					    =						torch_version[: torch_version.rindex("""."""     )]
      __lowerCAmelCase  :			int					    =						f'''https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl'''
      __lowerCAmelCase  :			List[Any]					    =						["""pip""", """install""", xla_wheel]
      subprocess.run(__A					,   check=__A     )
   else:
      raise RuntimeError("""`install_xla` utility works only on google colab."""     )


