






import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin


class      lowercase__     (			_UpperCamelCase	):
	a_         ="MCTCTFeatureExtractor"
	a_         ="AutoTokenizer"

	def __init__(							self		,    __UpperCAmelCase		,    __UpperCAmelCase       )->					str:







							'''simple docstring'''





							super().__init__(__a		,    __a       )
							lowerCAmelCase__       =						self.feature_extractor
							lowerCAmelCase__       =						False

	def __call__(							self		,    *__UpperCAmelCase		,    **__UpperCAmelCase       )->					Any:







							'''simple docstring'''





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

							if "raw_speech" in kwargs:
													warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."       )
													lowerCAmelCase__       =						kwargs.pop("raw_speech"       )
							else:
													lowerCAmelCase__       =						kwargs.pop("audio"		,    __a       )
							lowerCAmelCase__       =						kwargs.pop("sampling_rate"		,    __a       )
							lowerCAmelCase__       =						kwargs.pop("text"		,    __a       )
							if len(__a       ) > 0:
													lowerCAmelCase__       =						args[0]
													lowerCAmelCase__       =						args[1:]

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

							if audio is not None:
													lowerCAmelCase__       =						self.feature_extractor(__a		,    *__a		,    sampling_rate=__a		,    **__a       )
							if text is not None:
													lowerCAmelCase__       =						self.tokenizer(__a		,    **__a       )

							if text is None:
													return inputs
							elif audio is None:
													return encodings
							else:
													lowerCAmelCase__       =						encodings["input_ids"]
													return inputs

	def 		UpperCAmelCase  (							self		,    *__UpperCAmelCase		,    **__UpperCAmelCase       )->					str:







							'''simple docstring'''





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

	def 		UpperCAmelCase  (							self		,    *__UpperCAmelCase		,    **__UpperCAmelCase       )->					Optional[int]:







							'''simple docstring'''





							if self._in_target_context_manager:
													return self.current_processor.pad(*__a		,    **__a       )

							lowerCAmelCase__       =						kwargs.pop("input_features"		,    __a       )
							lowerCAmelCase__       =						kwargs.pop("labels"		,    __a       )
							if len(__a       ) > 0:
													lowerCAmelCase__       =						args[0]
													lowerCAmelCase__       =						args[1:]

							if input_features is not None:
													lowerCAmelCase__       =						self.feature_extractor.pad(__a		,    *__a		,    **__a       )
							if labels is not None:
													lowerCAmelCase__       =						self.tokenizer.pad(__a		,    **__a       )

							if labels is None:
													return input_features
							elif input_features is None:
													return labels
							else:
													lowerCAmelCase__       =						labels["input_ids"]
													return input_features

	def 		UpperCAmelCase  (							self		,    *__UpperCAmelCase		,    **__UpperCAmelCase       )->					Any:







							'''simple docstring'''





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


	@contextmanager
	def 		UpperCAmelCase  (							self       )->					str:







							'''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 audio inputs, or in a separate call."       )
							lowerCAmelCase__       =						True
							lowerCAmelCase__       =						self.tokenizer
							yield
							lowerCAmelCase__       =						self.feature_extractor
							lowerCAmelCase__       =						False














import argparse

from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection

from diffusers import UnCLIPImageVariationPipeline, UnCLIPPipeline


if __name__ == "__main__":
	a_							=    argparse.ArgumentParser()

	parser.add_argument('''--dump_path''', default=None, type=str, required=True, help='''Path to the output model.''')

	parser.add_argument(
	    '''--txt2img_unclip''',
	    default='''kakaobrain/karlo-v1-alpha''',
	    type=str,
	    required=False,
	    help='''The pretrained txt2img unclip.''',
	)

	a_							=    parser.parse_args()

	a_							=    UnCLIPPipeline.from_pretrained(args.txtaimg_unclip)

	a_							=    CLIPImageProcessor()
	a_							=    CLIPVisionModelWithProjection.from_pretrained('''openai/clip-vit-large-patch14''')

	a_							=    UnCLIPImageVariationPipeline(
	    decoder=txtaimg.decoder,
	    text_encoder=txtaimg.text_encoder,
	    tokenizer=txtaimg.tokenizer,
	    text_proj=txtaimg.text_proj,
	    feature_extractor=feature_extractor,
	    image_encoder=image_encoder,
	    super_res_first=txtaimg.super_res_first,
	    super_res_last=txtaimg.super_res_last,
	    decoder_scheduler=txtaimg.decoder_scheduler,
	    super_res_scheduler=txtaimg.super_res_scheduler,
	)

	imgaimg.save_pretrained(args.dump_path)






