
    gD                     b   d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZ ddlmZ ddlmZmZmZm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z&  ej'        e(          Z) eg d          Z* eee*          Z+de,fdZ- G d d          Z.dS )zAutoProcessor class.    N)OrderedDict   )PretrainedConfig)get_class_from_dynamic_moduleresolve_trust_remote_code)FeatureExtractionMixin)ImageProcessingMixin)ProcessorMixin)TOKENIZER_CONFIG_FILE)FEATURE_EXTRACTOR_NAMEPROCESSOR_NAMEget_file_from_repologging   )_LazyAutoMapping)CONFIG_MAPPING_NAMES
AutoConfigmodel_type_to_module_name!replace_list_option_in_docstrings)AutoFeatureExtractor)AutoImageProcessor)AutoTokenizer)C)alignAlignProcessor)altclipAltCLIPProcessor)barkBarkProcessor)blipBlipProcessor)zblip-2Blip2Processor)bridgetowerBridgeTowerProcessor)	chameleonChameleonProcessor)chinese_clipChineseCLIPProcessor)clapClapProcessor)clipCLIPProcessor)clipsegCLIPSegProcessor)clvpClvpProcessor)flavaFlavaProcessor)fuyuFuyuProcessor)gitGitProcessor)zgrounding-dinoGroundingDinoProcessor)groupvitr+   )hubertWav2Vec2Processor)ideficsIdeficsProcessor)idefics2Idefics2Processor)idefics3Idefics3Processor)instructblipInstructBlipProcessor)instructblipvideoInstructBlipVideoProcessor)zkosmos-2Kosmos2Processor)
layoutlmv2LayoutLMv2Processor)
layoutlmv3LayoutLMv3Processor)llavaLlavaProcessor)
llava_nextLlavaNextProcessor)llava_next_videoLlavaNextVideoProcessor)llava_onevisionLlavaOnevisionProcessor)markuplmMarkupLMProcessor)mctctMCTCTProcessor)zmgp-strMgpstrProcessor)mllamaMllamaProcessor)	oneformerOneFormerProcessor)owlv2Owlv2Processor)owlvitOwlViTProcessor)	paligemmaPaliGemmaProcessor)
pix2structPix2StructProcessor)pixtralPixtralProcessor)	pop2pianoPop2PianoProcessor)qwen2_audioQwen2AudioProcessor)qwen2_vlQwen2VLProcessor)samSamProcessor)seamless_m4tSeamlessM4TProcessor)sewr9   )zsew-dr9   )siglipSiglipProcessor)speech_to_textSpeech2TextProcessor)speech_to_text_2Speech2Text2Processor)speecht5SpeechT5Processor)trocrTrOCRProcessor)tvltTvltProcessor)tvpTvpProcessor)udopUdopProcessor)	unispeechr9   )zunispeech-satr9   )video_llavaVideoLlavaProcessor)viltViltProcessor)vipllavarJ   )zvision-text-dual-encoderVisionTextDualEncoderProcessor)wav2vec2r9   )zwav2vec2-bertr9   )zwav2vec2-conformerr9   )wavlmr9   )whisperWhisperProcessor)xclipXCLIPProcessor
class_namec                    t                                           D ]S\  }}| |v rJt          |          }t          j        d| d          }	 t          ||           c S # t          $ r Y Ow xY wTt          j        	                                D ]}t          |dd           | k    r|c S t          j        d          }t          ||           rt          ||           S d S )N.ztransformers.models__name__transformers)PROCESSOR_MAPPING_NAMESitemsr   	importlibimport_modulegetattrAttributeErrorPROCESSOR_MAPPING_extra_contentvalueshasattr)r   module_name
processorsmodule	processormain_modules         d/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/auto/processing_auto.pyprocessor_class_from_namer   y   s   #:#@#@#B#B  Z##3K@@K,->->->@UVVFvz22222!    $ '5<<>>  	9j$//:== >
 ).99K{J'' 0{J///4s   A
A*)A*c                   h    e Zd ZdZd Ze ee          d                         Ze	dd            Z
dS )AutoProcessora  
    This is a generic processor class that will be instantiated as one of the processor classes of the library when
    created with the [`AutoProcessor.from_pretrained`] class method.

    This class cannot be instantiated directly using `__init__()` (throws an error).
    c                      t          d          )Nz}AutoProcessor is designed to be instantiated using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method.)EnvironmentError)selfs    r   __init__zAutoProcessor.__init__   s    _
 
 	
    c                                         dd          }|Dt          j        dt                                         dd          t          d          |d<                        dd          }                     dd          }dd	<   d}d}fd
t          j        t                    j	        
                                D             }t          |t          fi |}	|	Qt          j        |fi \  }
}|
                    dd          }d|
                    di           v r|
d         d         }|t          |t          fi |}|Qt          j        |fi \  }
}|
                    dd          }d|
                    di           v r|
d         d         }|S|Qt#          j        |fi \  }
}|
                    dd          }d|
                    di           v r|
d         d         }|t          |t&          fi |}|yt)          |d          5 }t+          j        |          }
ddd           n# 1 swxY w Y   |
                    dd          }d|
                    di           v r|
d         d         }|`t/          |t0                    st3          j        |fd|i}t7          |dd          }t9          |d          rd|j        v r|j        d         }|t=          |          }|du}|dupt?          |          t@          v }tC          ||||          }|ri|rgtE          ||fi }                     dd          }tF          j$        %                    |          r|&                                  |j        |fd|iS | |j        |fd|iS t?          |          t@          v r%tA          t?          |                   j        |fi S 	 tO          j        |fd|iS # tP          $ rQ 	 tS          j        |fd|icY S # tP          $ r Y nw xY w	 tU          j        |fd|icY S # tP          $ r Y nw xY wY nw xY wt          d| d          )a  
        Instantiate one of the processor classes of the library from a pretrained model vocabulary.

        The processor class to instantiate is selected based on the `model_type` property of the config object (either
        passed as an argument or loaded from `pretrained_model_name_or_path` if possible):

        List options

        Params:
            pretrained_model_name_or_path (`str` or `os.PathLike`):
                This can be either:

                - a string, the *model id* of a pretrained feature_extractor hosted inside a model repo on
                  huggingface.co.
                - a path to a *directory* containing a processor files saved using the `save_pretrained()` method,
                  e.g., `./my_model_directory/`.
            cache_dir (`str` or `os.PathLike`, *optional*):
                Path to a directory in which a downloaded pretrained model feature extractor should be cached if the
                standard cache should not be used.
            force_download (`bool`, *optional*, defaults to `False`):
                Whether or not to force to (re-)download the feature extractor files and override the cached versions
                if they exist.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible.
                Will be removed in v5 of Transformers.
            proxies (`Dict[str, str]`, *optional*):
                A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
            token (`str` or *bool*, *optional*):
                The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
                when running `huggingface-cli login` (stored in `~/.huggingface`).
            revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
                identifier allowed by git.
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final feature extractor object. If `True`, then this
                functions returns a `Tuple(feature_extractor, unused_kwargs)` where *unused_kwargs* is a dictionary
                consisting of the key/value pairs whose keys are not feature extractor attributes: i.e., the part of
                `kwargs` which has not been used to update `feature_extractor` and is otherwise ignored.
            trust_remote_code (`bool`, *optional*, defaults to `False`):
                Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
                should only be set to `True` for repositories you trust and in which you have read the code, as it will
                execute code present on the Hub on your local machine.
            kwargs (`Dict[str, Any]`, *optional*):
                The values in kwargs of any keys which are feature extractor attributes will be used to override the
                loaded values. Behavior concerning key/value pairs whose keys are *not* feature extractor attributes is
                controlled by the `return_unused_kwargs` keyword parameter.

        <Tip>

        Passing `token=True` is required when you want to use a private model.

        </Tip>

        Examples:

        ```python
        >>> from transformers import AutoProcessor

        >>> # Download processor from huggingface.co and cache.
        >>> processor = AutoProcessor.from_pretrained("facebook/wav2vec2-base-960h")

        >>> # If processor files are in a directory (e.g. processor was saved using *save_pretrained('./test/saved_model/')*)
        >>> # processor = AutoProcessor.from_pretrained("./test/saved_model/")
        ```use_auth_tokenNzrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.tokenzV`token` and `use_auth_token` are both specified. Please set only the argument `token`.configtrust_remote_codeT
_from_autoc                 *    i | ]}|v ||         S  r   ).0keykwargss     r   
<dictcomp>z1AutoProcessor.from_pretrained.<locals>.<dictcomp>   s2     %
 %
 %
!$cfjpcpcpCcpcpcpr   processor_classr   auto_mapzutf-8)encodingcode_revisionz!Unrecognized processing class in z. Can't instantiate a processor, a tokenizer, an image processor or a feature extractor for this model. Make sure the repository contains the files of at least one of those processing classes.)+popwarningswarnFutureWarningget
ValueErrorinspect	signaturer   
parameterskeysr   r
   get_processor_dictr   r	   get_image_processor_dictr   get_feature_extractor_dictr   openjsonload
isinstancer   r   from_pretrainedr   r   r   r   typer   r   r   ospathisdirregister_for_auto_classr   	Exceptionr   r   )clspretrained_model_name_or_pathr   r   r   r   r   processor_auto_mapget_file_from_repo_kwargsprocessor_config_fileconfig_dict_preprocessor_config_filetokenizer_config_filereaderhas_remote_codehas_local_codes     `              r   r   zAutoProcessor.from_pretrained   s   J  $4d;;%M E   zz'4((4 l   -F7OHd++"JJ':DAA#|!%
 %
 %
 %
(/(9:L(M(M(X(](](_(_%
 %
 %
!
 !3)>!
 !
=V!
 !
 !,+>?\gg`fggNK)oo.?FFO+//*b"A"AAA%0%<_%M""'9-/E( (Ib( ($ (3!5!NOl!w!wpv!w!wQ"-//2CT"J"J"kooj"&E&EEE)4Z)@)Q& (38O!7!R1" "5;" "Q #.//2CT"J"J"kooj"&E&EEE)4Z)@)Q&"$6-/D% %Ha% %! %0/'BBB 4f"&)F"3"3K4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 #.//2CT"J"J"kooj"&E&EEE)4Z)@)Q&"f&677 #31 EVZ` 
 &f.?FFOvz** F&//Q/Q%+__%E"&7HHO,D8(4YVHY8Y5<no
 
  	l0 	l;"$A EK O 

?D11Aw}}:;; :779992?2- ARV\   (2?2- ARV\   &\\...$T&\\2BC`kkdjkkk	 0- ARV\    	 	 	)91 EVZ`        +;1 EVZ`        	 E0M E E E
 
 	
sl   H;;H?H?O2 2
Q=PQ
P QP  Q$P:7Q:
QQQQQFc                 @    t                               | ||           dS )a  
        Register a new processor for this class.

        Args:
            config_class ([`PretrainedConfig`]):
                The configuration corresponding to the model to register.
            processor_class ([`FeatureExtractorMixin`]): The processor to register.
        )exist_okN)r   register)config_classr   r   s      r   r   zAutoProcessor.registerj  s%     	""<8"TTTTTr   N)F)r   
__module____qualname____doc__r   classmethodr   r   r   staticmethodr   r   r   r   r   r      s         
 
 
 &&'>??G
 G
 @? [G
R 	U 	U 	U \	U 	U 	Ur   r   )/r   r   r   r   r   r   collectionsr   configuration_utilsr   dynamic_module_utilsr   r   feature_extraction_utilsr   image_processing_utilsr	   processing_utilsr
   tokenization_utilsr   utilsr   r   r   r   auto_factoryr   configuration_autor   r   r   r   feature_extraction_autor   image_processing_autor   tokenization_autor   
get_loggerr   loggerr   r   strr   r   r   r   r   <module>r      s            				  # # # # # # 4 3 3 3 3 3 \ \ \ \ \ \ \ \ > > > > > > : : : : : : . . . . . . 7 7 7 7 7 7 X X X X X X X X X X X X * * * * * *            : 9 9 9 9 9 5 5 5 5 5 5 , , , , , , 
	H	%	%%+D D DF F P %$%9;RSS #    0cU cU cU cU cU cU cU cU cU cUr   