
from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch






@require_torch
@require_tf
class     UpperCAmelCase						(		A_					):



   def 							_SCREAMING_SNAKE_CASE  (self						:   str					)						->      Dict:


          '''simple docstring'''


          snake_case			:  Optional[Any]     							= SMALL_MODEL_IDENTIFIER
          snake_case			:  Optional[Any]     							= "pt"
          snake_case			:  List[Any]     							= "tf"



   def 							_SCREAMING_SNAKE_CASE  (self						:   Tuple       ,		snake_case__						:   Tuple					)						->      Tuple:


          '''simple docstring'''


          snake_case			:  int     							= AutoModel.from_pretrained(self.test_model					)
          model_pt.save_pretrained(snake_case__					)



   def 							_SCREAMING_SNAKE_CASE  (self						:   int       ,		snake_case__						:   Any					)						->      List[str]:


          '''simple docstring'''


          snake_case			:  str     							= TFAutoModel.from_pretrained(self.test_model       ,		from_pt=snake_case__					)
          model_tf.save_pretrained(snake_case__					)



   def 							_SCREAMING_SNAKE_CASE  (self						:   Union[str, Any]					)						->      Tuple:


          '''simple docstring'''


          snake_case			:  Optional[int]     							= "mock_framework"

          # Framework provided - return whatever the user provides
          snake_case			:  List[str]     							= FeaturesManager.determine_framework(self.test_model       ,		snake_case__					)
          self.assertEqual(snake_case__       ,		snake_case__					)

          # Local checkpoint and framework provided - return provided framework
          # PyTorch checkpoint
          with TemporaryDirectory() as local_pt_ckpt:
                 self._setup_pt_ckpt(snake_case__					)
                 snake_case			:  Union[str, Any]     							= FeaturesManager.determine_framework(snake_case__       ,		snake_case__					)
                 self.assertEqual(snake_case__       ,		snake_case__					)

          # TensorFlow checkpoint
          with TemporaryDirectory() as local_tf_ckpt:
                 self._setup_tf_ckpt(snake_case__					)
                 snake_case			:  Optional[int]     							= FeaturesManager.determine_framework(snake_case__       ,		snake_case__					)
                 self.assertEqual(snake_case__       ,		snake_case__					)



   def 							_SCREAMING_SNAKE_CASE  (self						:   Union[str, Any]					)						->      Any:


          '''simple docstring'''


          with TemporaryDirectory() as local_pt_ckpt:
                 self._setup_pt_ckpt(snake_case__					)
                 snake_case			:  List[Any]     							= FeaturesManager.determine_framework(snake_case__					)
                 self.assertEqual(snake_case__       ,		self.framework_pt					)

          # TensorFlow checkpoint
          with TemporaryDirectory() as local_tf_ckpt:
                 self._setup_tf_ckpt(snake_case__					)
                 snake_case			:  Dict     							= FeaturesManager.determine_framework(snake_case__					)
                 self.assertEqual(snake_case__       ,		self.framework_tf					)

          # Invalid local checkpoint
          with TemporaryDirectory() as local_invalid_ckpt:
                 with self.assertRaises(snake_case__					):
                        snake_case			:  Union[str, Any]     							= FeaturesManager.determine_framework(snake_case__					)



   def 							_SCREAMING_SNAKE_CASE  (self						:   Union[str, Any]					)						->      Any:


          '''simple docstring'''


          snake_case			:  Tuple     							= MagicMock(return_value=snake_case__					)
          with patch("transformers.onnx.features.is_tf_available"       ,		snake_case__					):
                 snake_case			:  Tuple     							= FeaturesManager.determine_framework(self.test_model					)
                 self.assertEqual(snake_case__       ,		self.framework_pt					)

          # PyTorch not in environment -> use TensorFlow
          snake_case			:  Optional[Any]     							= MagicMock(return_value=snake_case__					)
          with patch("transformers.onnx.features.is_torch_available"       ,		snake_case__					):
                 snake_case			:  Optional[int]     							= FeaturesManager.determine_framework(self.test_model					)
                 self.assertEqual(snake_case__       ,		self.framework_tf					)

          # Both in environment -> use PyTorch
          snake_case			:  Union[str, Any]     							= MagicMock(return_value=snake_case__					)
          snake_case			:  Any     							= MagicMock(return_value=snake_case__					)
          with patch("transformers.onnx.features.is_tf_available"       ,		snake_case__					), patch(
              "transformers.onnx.features.is_torch_available"       ,		snake_case__					):
                 snake_case			:  Optional[Any]     							= FeaturesManager.determine_framework(self.test_model					)
                 self.assertEqual(snake_case__       ,		self.framework_pt					)

          # Both not in environment -> raise error
          snake_case			:  int     							= MagicMock(return_value=snake_case__					)
          snake_case			:  List[str]     							= MagicMock(return_value=snake_case__					)
          with patch("transformers.onnx.features.is_tf_available"       ,		snake_case__					), patch(
              "transformers.onnx.features.is_torch_available"       ,		snake_case__					):
                 with self.assertRaises(snake_case__					):
                        snake_case			:  List[Any]     							= FeaturesManager.determine_framework(self.test_model					)







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__lowerCamelCase				=			{
    """configuration_chinese_clip""": [
        """CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """ChineseCLIPConfig""",
        """ChineseCLIPOnnxConfig""",
        """ChineseCLIPTextConfig""",
        """ChineseCLIPVisionConfig""",
    ],
    """processing_chinese_clip""": ["""ChineseCLIPProcessor"""],
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __lowerCamelCase				=			["""ChineseCLIPFeatureExtractor"""]
   __lowerCamelCase				=			["""ChineseCLIPImageProcessor"""]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __lowerCamelCase				=			[
       """CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """ChineseCLIPModel""",
       """ChineseCLIPPreTrainedModel""",
       """ChineseCLIPTextModel""",
       """ChineseCLIPVisionModel""",
   ]

if TYPE_CHECKING:
   from .configuration_chinese_clip import (
       CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
       ChineseCLIPConfig,
       ChineseCLIPOnnxConfig,
       ChineseCLIPTextConfig,
       ChineseCLIPVisionConfig,
   )
   from .processing_chinese_clip import ChineseCLIPProcessor

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_chinese_clip import ChineseCLIPFeatureExtractor, ChineseCLIPImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_chinese_clip import (
          CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
          ChineseCLIPModel,
          ChineseCLIPPreTrainedModel,
          ChineseCLIPTextModel,
          ChineseCLIPVisionModel,
      )

else:
   import sys

   __lowerCamelCase				=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





