a
    hP                     @   s4  d 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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& ddl'm(Z( e)e*Z+eg dZ,eee,Z-e.dddZ/G dd dZ0ddgZ1d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VIDEO_PROCESSOR_NAMEcached_filelogging)BaseVideoProcessor   )_LazyAutoMapping)CONFIG_MAPPING_NAMES
AutoConfigmodel_type_to_module_name!replace_list_option_in_docstrings)AutoFeatureExtractor)AutoImageProcessor)AutoTokenizer)i)Zaimv2CLIPProcessor)alignZAlignProcessor)ZaltclipZAltCLIPProcessor)ZariaZAriaProcessor)Z
aya_visionZAyaVisionProcessor)ZbarkZBarkProcessor)ZblipZBlipProcessor)zblip-2ZBlip2Processor)ZbridgetowerZBridgeTowerProcessor)Z	chameleonZChameleonProcessor)Zchinese_clipZChineseCLIPProcessor)clapZClapProcessor)Zclipr   )ZclipsegZCLIPSegProcessor)ZclvpZClvpProcessor)Zcohere2_visionZCohere2VisionProcessor)ZcolpaliZColPaliProcessor)Zcolqwen2ZColQwen2Processor)Zdeepseek_vlZDeepseekVLProcessor)Zdeepseek_vl_hybridZDeepseekVLHybridProcessor)ZdiaZDiaProcessor)Zemu3ZEmu3Processor)ZevollaZEvollaProcessor)ZflavaZFlavaProcessor)Z	florence2ZFlorence2Processor)ZfuyuZFuyuProcessor)Zgemma3ZGemma3Processor)Zgemma3nZGemma3nProcessor)gitZGitProcessor)Zglm4vGlm4vProcessor)Z	glm4v_moer   )Zgot_ocr2ZGotOcr2Processor)Zgranite_speechZGraniteSpeechProcessor)zgrounding-dinoGroundingDinoProcessor)Zgroupvitr   )ZhubertWav2Vec2Processor)ZideficsZIdeficsProcessor)Zidefics2ZIdefics2Processor)Zidefics3ZIdefics3Processor)ZinstructblipZInstructBlipProcessor)ZinstructblipvideoZInstructBlipVideoProcessor)ZinternvlZInternVLProcessor)ZjanusZJanusProcessor)zkosmos-2ZKosmos2Processor)z
kosmos-2.5ZKosmos2_5Processor)Zkyutai_speech_to_textZKyutaiSpeechToTextProcessor)Z
layoutlmv2ZLayoutLMv2Processor)Z
layoutlmv3ZLayoutLMv3Processor)Zllama4ZLlama4Processor)ZllavaLlavaProcessor)Z
llava_nextZLlavaNextProcessor)Zllava_next_videoZLlavaNextVideoProcessor)Zllava_onevisionZLlavaOnevisionProcessor)ZmarkuplmZMarkupLMProcessor)ZmctctZMCTCTProcessor)Z
metaclip_2r   )zmgp-strZMgpstrProcessor)Zmistral3PixtralProcessor)ZmllamaZMllamaProcessor)zmm-grounding-dinor   )Z	moonshiner    )Z	oneformerZOneFormerProcessor)Zovis2ZOvis2Processor)Zowlv2ZOwlv2Processor)ZowlvitZOwlViTProcessor)Z	paligemmaZPaliGemmaProcessor)Zperception_lmZPerceptionLMProcessor)Zphi4_multimodalZPhi4MultimodalProcessor)Z
pix2structZPix2StructProcessor)Zpixtralr"   )Z	pop2pianoZPop2PianoProcessor)Zqwen2_5_omniZQwen2_5OmniProcessor)Z
qwen2_5_vlZQwen2_5_VLProcessor)Zqwen2_audioZQwen2AudioProcessor)Zqwen2_vlZQwen2VLProcessor)ZsamZSamProcessor)Zsam2ZSam2Processor)Zsam_hqZSamHQProcessor)Zseamless_m4tZSeamlessM4TProcessor)Zsewr    )zsew-dr    )Zshieldgemma2ZShieldGemma2Processor)ZsiglipZSiglipProcessor)Zsiglip2ZSiglip2Processor)ZsmolvlmZSmolVLMProcessor)Zspeech_to_textZSpeech2TextProcessor)Zspeech_to_text_2ZSpeech2Text2Processor)Zspeecht5ZSpeechT5Processor)ZtrocrZTrOCRProcessor)ZtvltZTvltProcessor)ZtvpZTvpProcessor)ZudopZUdopProcessor)Z	unispeechr    )zunispeech-satr    )Zvideo_llavaZVideoLlavaProcessor)ZviltZViltProcessor)Zvipllavar!   )zvision-text-dual-encoderZVisionTextDualEncoderProcessor)ZvoxtralZVoxtralProcessor)Zwav2vec2r    )zwav2vec2-bertr    )zwav2vec2-conformerr    )Zwavlmr    )ZwhisperZWhisperProcessor)ZxclipZXCLIPProcessor)
class_namec              	   C   s   t  D ]R\}}| |v rt|}td| d}zt|| W   S  tyX   Y qY q0 qtj	 D ]}t|dd | krf|  S qftd}t
|| rt|| S d S )N.ztransformers.models__name__Ztransformers)PROCESSOR_MAPPING_NAMESitemsr   	importlibimport_modulegetattrAttributeErrorPROCESSOR_MAPPINGZ_extra_contentvalueshasattr)r#   module_nameZ
processorsmodule	processorZmain_module r2   d/var/www/html/assistant/venv/lib/python3.9/site-packages/transformers/models/auto/processing_auto.pyprocessor_class_from_name   s    



r4   c                   @   s:   e Zd ZdZdd Zeeedd Ze	d
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                 C   s   t dd S )Nz}AutoProcessor is designed to be instantiated using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method.)OSError)selfr2   r2   r3   __init__   s    zAutoProcessor.__init__c                    s    dd}|dur>tdt  ddur6td| d<   dd}  dd}d d	< d}d} fd
dttj	D }|
dddd t|tfi |}	|	durtj|fi  \}
}|
dd}d|
di v r|
d d }|du r&t|tfi |}|durPtj|fi  \}
}|
dd}d|
di v rP|
d d }|du rt|tfi |}|durtj|fi  \}
}|
dd}d|
di v r|
d d }|du r&t|tfi |}|dur&|du r&tj|fi  \}
}|
dd}d|
di v r&|
d d }|du rt|tfi |}|durt|dd}t|}
W d   n1 sz0    Y  |
dd}d|
di v r|
d d }|du rt|tstj|fd|i }t|dd}t|drd|j v r|j d }|durt!|}|du}|dup6t"|t#v }|rld|v rX|$dd }nd}t%|||||}|r|rt&||fi  }  dd}|'  |j|fd|i S |dur|j|fd|i S t"|t#v rt#t"| j|fi  S zt(j|fd|i W S  t)y   zt*j|fd|i W  Y S  t)yT   Y n0 zt+j|fd|i W  Y S  t)y   Y n0 Y n0 td| ddS )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 `hf auth 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_codeTZ
_from_autoc                    s   i | ]}| v r| | qS r2   r2   ).0keykwargsr2   r3   
<dictcomp>      z1AutoProcessor.from_pretrained.<locals>.<dictcomp>F)Z _raise_exceptions_for_gated_repoZ%_raise_exceptions_for_missing_entriesZ'_raise_exceptions_for_connection_errorsprocessor_classr5   auto_mapzutf-8)encodingz--r   Z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updater   r	   Zget_processor_dictr   r   Zget_image_processor_dictr   r   Zget_video_processor_dictr   Zget_feature_extractor_dictr
   openjsonload
isinstancer   r   from_pretrainedr*   r.   rD   r4   typer,   splitr   r   Zregister_for_auto_classr   	Exceptionr   r   )clsZpretrained_model_name_or_pathr@   r9   r;   r<   rC   Zprocessor_auto_mapZcached_file_kwargsZprocessor_config_fileZconfig_dict_Zpreprocessor_config_fileZtokenizer_config_filereaderZhas_remote_codeZhas_local_codeZupstream_repor2   r?   r3   rT      sD   E	








*






zAutoProcessor.from_pretrainedFc                 C   s   t j| ||d dS )a  
        Register a new processor for this class.

        Args:
            config_class ([`PretrainedConfig`]):
                The configuration corresponding to the model to register.
            processor_class ([`ProcessorMixin`]): The processor to register.
        )exist_okN)r,   register)Zconfig_classrC   r[   r2   r2   r3   r\     s    
zAutoProcessor.registerN)F)r%   
__module____qualname____doc__r8   classmethodr   r&   rT   staticmethodr\   r2   r2   r2   r3   r5      s    cr5   r,   )2r_   r(   rL   rQ   rG   collectionsr   Zconfiguration_utilsr   Zdynamic_module_utilsr   r   Zfeature_extraction_utilsr   Zimage_processing_utilsr   Zprocessing_utilsr	   Ztokenization_utilsr
   utilsr   r   r   r   r   Zvideo_processing_utilsr   Zauto_factoryr   Zconfiguration_autor   r   r   r   Zfeature_extraction_autor   Zimage_processing_autor   Ztokenization_autor   Z
get_loggerr%   loggerr&   r,   strr4   r5   __all__r2   r2   r2   r3   <module>   s8   
n
  