'''simple docstring'''




import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin






class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			UpperCAmelCase_     :	int						=			['''image_processor''', '''tokenizer''']
			UpperCAmelCase_     :	Tuple						=			'''AutoImageProcessor'''
			UpperCAmelCase_     :	Union[str, Any]						=			'''AutoTokenizer'''



			def __init__(  self			,       __lowerCAmelCase=None			,       __lowerCAmelCase=None			,       **__lowerCAmelCase):




					"""simple docstring"""


					lowerCAmelCase     =    None
					if "feature_extractor" in kwargs:
							warnings.warn(
							    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
							    """ instead."""			,       __lowerCAmelCase			,       )
							lowerCAmelCase     =    kwargs.pop("""feature_extractor""")

					lowerCAmelCase     =    image_processor if image_processor is not None else feature_extractor
					if image_processor is None:
							raise ValueError("""You need to specify an `image_processor`.""")
					if tokenizer is None:
							raise ValueError("""You need to specify a `tokenizer`.""")

					super().__init__(__lowerCAmelCase			,       __lowerCAmelCase)
					lowerCAmelCase     =    self.image_processor
					lowerCAmelCase     =    False



			def __call__(  self			,       *__lowerCAmelCase			,       **__lowerCAmelCase):




					"""simple docstring"""


					if self._in_target_context_manager:
							return self.current_processor(*__lowerCAmelCase			,       **__lowerCAmelCase)

					lowerCAmelCase     =    kwargs.pop("""images"""			,       __lowerCAmelCase)
					lowerCAmelCase     =    kwargs.pop("""text"""			,       __lowerCAmelCase)
					if len(__lowerCAmelCase) > 0:
							lowerCAmelCase     =    args[0]
							lowerCAmelCase     =    args[1:]

					if images is None and text is None:
							raise ValueError("""You need to specify either an `images` or `text` input to process.""")

					if images is not None:
							lowerCAmelCase     =    self.image_processor(__lowerCAmelCase			,       *__lowerCAmelCase			,       **__lowerCAmelCase)
					if text is not None:
							lowerCAmelCase     =    self.tokenizer(__lowerCAmelCase			,       **__lowerCAmelCase)

					if text is None:
							return inputs
					elif images is None:
							return encodings
					else:
							lowerCAmelCase     =    encodings["""input_ids"""]
							return inputs



			def 				a_			(  self			,       *__lowerCAmelCase			,       **__lowerCAmelCase):




					"""simple docstring"""


					return self.tokenizer.batch_decode(*__lowerCAmelCase			,       **__lowerCAmelCase)



			def 				a_			(  self			,       *__lowerCAmelCase			,       **__lowerCAmelCase):




					"""simple docstring"""


					return self.tokenizer.decode(*__lowerCAmelCase			,       **__lowerCAmelCase)



			@contextmanager
			def 				a_			(  self):




					"""simple docstring"""


					warnings.warn(
					    """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
					    """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
					    """your images inputs, or in a separate call.""")
					lowerCAmelCase     =    True
					lowerCAmelCase     =    self.tokenizer
					yield
					lowerCAmelCase     =    self.image_processor
					lowerCAmelCase     =    False



			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase=False			,       __lowerCAmelCase=None):




					"""simple docstring"""


					if added_vocab is None:
							lowerCAmelCase     =    self.tokenizer.get_added_vocab()

					lowerCAmelCase     =    {}

					while tokens:
							lowerCAmelCase     =    re.search(r"""<s_(.*?)>"""			,       __lowerCAmelCase			,       re.IGNORECASE)
							if start_token is None:
									break
							lowerCAmelCase     =    start_token.group(1)
							lowerCAmelCase     =    re.search(rf"</s_{key}>"			,       __lowerCAmelCase			,       re.IGNORECASE)
							lowerCAmelCase     =    start_token.group()
							if end_token is None:
									lowerCAmelCase     =    tokens.replace(__lowerCAmelCase			,       """""")
							else:
									lowerCAmelCase     =    end_token.group()
									lowerCAmelCase     =    re.escape(__lowerCAmelCase)
									lowerCAmelCase     =    re.escape(__lowerCAmelCase)
									lowerCAmelCase     =    re.search(f"{start_token_escaped}(.*?){end_token_escaped}"			,       __lowerCAmelCase			,       re.IGNORECASE)
									if content is not None:
											lowerCAmelCase     =    content.group(1).strip()
											if r"<s_" in content and r"</s_" in content:  # non-leaf node
													lowerCAmelCase     =    self.tokenajson(__lowerCAmelCase			,       is_inner_value=__lowerCAmelCase			,       added_vocab=__lowerCAmelCase)
													if value:
															if len(__lowerCAmelCase) == 1:
																	lowerCAmelCase     =    value[0]
															lowerCAmelCase     =    value
											else:  # leaf nodes
													lowerCAmelCase     =    []
													for leaf in content.split(r"""<sep/>"""):
															lowerCAmelCase     =    leaf.strip()
															if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
																	lowerCAmelCase     =    leaf[1:-2]  # for categorical special tokens
															output[key].append(__lowerCAmelCase)
													if len(output[key]) == 1:
															lowerCAmelCase     =    output[key][0]

									lowerCAmelCase     =    tokens[tokens.find(__lowerCAmelCase) + len(__lowerCAmelCase) :].strip()
									if tokens[:6] == r"<sep/>":  # non-leaf nodes
											return [output] + self.tokenajson(tokens[6:]			,       is_inner_value=__lowerCAmelCase			,       added_vocab=__lowerCAmelCase)

					if len(__lowerCAmelCase):
							return [output] if is_inner_value else output
					else:
							return [] if is_inner_value else {"text_sequence": tokens}



			@property
			def 				a_			(  self):




					"""simple docstring"""


					warnings.warn(
					    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""			,       __lowerCAmelCase			,       )
					return self.image_processor_class







			@property
			def 				a_			(  self):




					"""simple docstring"""


					warnings.warn(
					    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""			,       __lowerCAmelCase			,       )
					return self.image_processor





'''simple docstring'''




from typing import TYPE_CHECKING

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


__lowercase        =    {
    '''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:
						__lowercase        =    ['''ChineseCLIPFeatureExtractor''']
						__lowercase        =    ['''ChineseCLIPImageProcessor''']

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__lowercase        =    [
						    '''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

						__lowercase        =    _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




