U
    9%e{                  !   @   sl
  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mZ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 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 ddlm Z m!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB ddlCmDZDmEZE ddlFmGZG ddlHmIZI ddlJmKZK ddlLmMZM ddlNmOZO ddlPmQZQ ddlRmSZS ddlTmUZU ddlVmWZW dd lXmYZY dd!lZm[Z[m\Z\ dd"l]m^Z^m_Z_ dd#l`maZambZbmcZc dd$ldmeZe dd%lfmgZg dd&lhmiZi dd'ljmkZkmlZlmmZmmnZn dd(lompZp dd)lqmrZr dd*lsmtZt dd+lumvZvmwZw dd,lxmyZy dd-lzm{Z{ e1 rd dl|Z}dd.l~mZmZmZmZmZmZmZmZmZmZmZ e2 rdd dlZdd/l"mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ erdd0lmZ dd1lmZ dd2lmZ e3eZd3d4d5d6d7Ze5d8e2 refnd8d9d:d;iid<d=e7d8e2 reefnd8d9d:d>iid?d=eid8e2 reefnd8d9d:d@iidAd=eKe1 r&efnd8e2 r6efnd8d9dBdBdCid?d=eee1 rZefnd8e2 rjefnd8d9dDdDdCidAd=ene1 refnd8e2 refnd8d9dEdEdCidAd=e\e1 refnd8e2 refnd8d9dFdFdCidAd=e_e2 refnd8e1 refnd8d9dGdGdCidAdHere2 r*efnd8d8d9d:dIiid?dHeIe2 rNefnd8d8d9d:dJiid?dHeMe1 rrefnd8e2 refnd8d9dKdKdCidAd=eae1 refnd8e2 refnd8d9dLdMdCidAd=ece1 refnd8e2 refnd8d9dNdNdCid9dNdNdCid9dNdNdCidOdAd=ebe1 r*efnd8e2 r:efnd8d9dNdNdCidAd=ege1 r^efnd8e2 rnefnd8d9dPdPdCidAd=ewe1 refnd8e2 refnd8dQdRdCdQdRdCdSdAd=eye1 refnd8e2 refnd8d9dTdTdCid?d=etd8e2 refnd8d9d:dUiid?d=eEe1 r(eefnd8e2 r:eefnd8d9dVdVdCidAd=eOe1 r^efnd8e2 rnefnd8d9dWdWdCidXd=eQd8e2 reefnd8d9d:dYiid?d=eUe1 refnd8e2 refnd8d9dZdZdCid?d=eYd8e2 refnd8d9d:d[iid?d=e{d8e2 refnd8d9d:d\iid?d=eGd8e2 r6e#fnd8d9d:d]iidXd=epd8e2 rZefnd8d9d:d^iid_d=eWd8e2 r~efnd8d9d:d`iid?d=eSd8e2 re$fnd8d9d:daiidXd=dbZe Ze Ze ZdcdddehZe D ]\ZZedf dAk	r
ee ee ndedf dgk	r$ee nJedf dhk	rHee ee n&edf d?kredie djedf  qe@eedkZe
e dldmdnZdeee edodpdqZeeee	ef drdsdtZdudv Zdeeeedxdyf  eeeef  eeee)dzf  eeeef  eeeef  ee ee eeeeef  eeeed{f  ee e	eef ee e=d|d}d~ZdS )    N)Path)TYPE_CHECKINGAnyDictListOptionalTupleUnion)
model_info)isin   )PretrainedConfig)get_class_from_dynamic_module)PreTrainedFeatureExtractor)BaseImageProcessor)
AutoConfig)FEATURE_EXTRACTOR_MAPPINGAutoFeatureExtractor)IMAGE_PROCESSOR_MAPPINGAutoImageProcessor)AutoModelForDepthEstimationAutoModelForImageToImage)TOKENIZER_MAPPINGAutoTokenizer)PreTrainedTokenizer)	HUGGINGFACE_CO_RESOLVE_ENDPOINTfind_adapter_config_fileis_kenlm_availableis_offline_modeis_peft_availableis_pyctcdecode_availableis_tf_availableis_torch_availablelogging   )AudioClassificationPipeline)"AutomaticSpeechRecognitionPipeline)
ArgumentHandlerCsvPipelineDataFormatJsonPipelineDataFormatPipedPipelineDataFormatPipelinePipelineDataFormatPipelineExceptionPipelineRegistryget_default_model_and_revisioninfer_framework_load_model)ConversationConversationalPipeline)DepthEstimationPipeline)!DocumentQuestionAnsweringPipeline)FeatureExtractionPipeline)FillMaskPipeline)ImageClassificationPipeline)ImageSegmentationPipeline)ImageToImagePipeline)ImageToTextPipeline)MaskGenerationPipeline)ObjectDetectionPipeline) QuestionAnsweringArgumentHandlerQuestionAnsweringPipeline)%TableQuestionAnsweringArgumentHandlerTableQuestionAnsweringPipeline)SummarizationPipelineText2TextGenerationPipelineTranslationPipeline)TextClassificationPipeline)TextGenerationPipeline)TextToAudioPipeline)AggregationStrategyNerPipeline"TokenClassificationArgumentHandlerTokenClassificationPipeline)VideoClassificationPipeline)VisualQuestionAnsweringPipeline)#ZeroShotAudioClassificationPipeline)%ZeroShotClassificationArgumentHandlerZeroShotClassificationPipeline)#ZeroShotImageClassificationPipeline)ZeroShotObjectDetectionPipeline)TFAutoModelTFAutoModelForCausalLM!TFAutoModelForImageClassificationTFAutoModelForMaskedLMTFAutoModelForQuestionAnsweringTFAutoModelForSeq2SeqLM$TFAutoModelForSequenceClassification$TFAutoModelForTableQuestionAnswering!TFAutoModelForTokenClassificationTFAutoModelForVision2Seq)TFAutoModelForZeroShotImageClassification)	AutoModelAutoModelForAudioClassificationAutoModelForCausalLMAutoModelForCTC%AutoModelForDocumentQuestionAnsweringAutoModelForImageClassificationAutoModelForImageSegmentationAutoModelForMaskedLMAutoModelForMaskGenerationAutoModelForObjectDetectionAutoModelForQuestionAnswering AutoModelForSemanticSegmentationAutoModelForSeq2SeqLM"AutoModelForSequenceClassificationAutoModelForSpeechSeq2Seq"AutoModelForTableQuestionAnsweringAutoModelForTextToSpectrogramAutoModelForTextToWaveformAutoModelForTokenClassificationAutoModelForVideoClassificationAutoModelForVision2Seq#AutoModelForVisualQuestionAnswering'AutoModelForZeroShotImageClassification#AutoModelForZeroShotObjectDetection)TFPreTrainedModel)PreTrainedModel)PreTrainedTokenizerFasttext-classificationtoken-classificationvisual-question-answeringtext-to-audio)zsentiment-analysisZnerZvqaztext-to-speech modelpt)zsuperb/wav2vec2-base-superb-ksZ372e048audio)impltfr~   defaulttype)zfacebook/wav2vec2-base-960hZ55bb623Z
multimodal)zsuno/bark-smallZ645cfbatext)zdistilbert-base-casedZ935ac13)r~   r   )z/distilbert-base-uncased-finetuned-sst-2-englishZaf0f99b)z0dbmdz/bert-large-cased-finetuned-conll03-englishZf2482bf)z%distilbert-base-cased-distilled-squadZ626af31)zgoogle/tapas-base-finetuned-wtqZ69ceee2)r   r~   r   r   r   )zdandelin/vilt-b32-finetuned-vqaZ4355f59)zimpira/layoutlm-document-qaZ52e01b3)zdistilroberta-baseZec58a5b)zsshleifer/distilbart-cnn-12-6Za4f8f3e)zt5-smallZd769bba)zt5-baseZ686f1db))enfr)r   de)r   ro)Zgpt2Z6c0e608)zfacebook/bart-large-mnliZc626438)zroberta-large-mnliZ130fb28)r}   config)zopenai/clip-vit-base-patch32Zf4881ba)zlaion/clap-htsat-fusedZ973b6e5)zmicrosoft/DialoGPT-mediumZ8bada3b)zgoogle/vit-base-patch16-224Z5dca96dimage)z facebook/detr-resnet-50-panopticZfc15262)zydshieh/vit-gpt2-coco-enZ65636df)zfacebook/detr-resnet-50Z2729413)zgoogle/owlvit-base-patch32Z17740e1)zIntel/dpt-largeZe93beec)z(MCG-NJU/videomae-base-finetuned-kineticsZ4800870video)zfacebook/sam-vit-hugeZ997b15)z!caidas/swin2SR-classical-sr-x2-64Z4aaedcb)zaudio-classificationautomatic-speech-recognitionr{   zfeature-extractionrx   ry   zquestion-answeringztable-question-answeringrz   zdocument-question-answeringz	fill-maskZsummarizationtranslationztext2text-generationztext-generationzzero-shot-classificationzzero-shot-image-classificationzzero-shot-audio-classificationconversationalzimage-classificationzimage-segmentationzimage-to-textzobject-detectionzzero-shot-object-detectionzdepth-estimationzvideo-classificationzmask-generationzimage-to-imageZSpeechEncoderDecoderConfigZVisionEncoderDecoderConfigZVisionTextDualEncoderConfigr   >   r   r   >   r   zSUPPORTED_TASK z contains invalid type )Zsupported_tasksZtask_aliases)returnc                   C   s   t  S )z3
    Returns a list of supported task strings.
    )PIPELINE_REGISTRYget_supported_tasksr|   r|   r|   ^/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/transformers/pipelines/__init__.pyr     s    r   )r}   tokenr   c              
   K   s   | dd }|d k	r4tdt |d k	r0td|}t rBtdzt| |d}W n0 tk
r } ztd| W 5 d }~X Y nX |j	std|  dt
|d	d
d
krtd|j d|j	}|S )Nuse_auth_tokenVThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers.V`token` and `use_auth_token` are both specified. Please set only the argument `token`.zMYou cannot infer task automatically within `pipeline` when using offline mode)r   z=Instantiating a pipeline without a task set raised an error: z
The model zS does not seem to have a correct `pipeline_tag` set to infer the task automaticallylibrary_nametransformersz$This model is meant to be used with z not with transformers)popwarningswarnFutureWarning
ValueErrorr   RuntimeErrorr
   	ExceptionZpipeline_taggetattrr   )r}   r   Zdeprecated_kwargsr   infoetaskr|   r|   r   get_task  s.      
r   )r   r   c                 C   s
   t | S )a  
    Checks an incoming task string, to validate it's correct and return the default Pipeline and Model classes, and
    default models if they exist.

    Args:
        task (`str`):
            The task defining which pipeline will be returned. Currently accepted tasks are:

            - `"audio-classification"`
            - `"automatic-speech-recognition"`
            - `"conversational"`
            - `"depth-estimation"`
            - `"document-question-answering"`
            - `"feature-extraction"`
            - `"fill-mask"`
            - `"image-classification"`
            - `"image-segmentation"`
            - `"image-to-text"`
            - `"image-to-image"`
            - `"object-detection"`
            - `"question-answering"`
            - `"summarization"`
            - `"table-question-answering"`
            - `"text2text-generation"`
            - `"text-classification"` (alias `"sentiment-analysis"` available)
            - `"text-generation"`
            - `"text-to-audio"` (alias `"text-to-speech"` available)
            - `"token-classification"` (alias `"ner"` available)
            - `"translation"`
            - `"translation_xx_to_yy"`
            - `"video-classification"`
            - `"visual-question-answering"`
            - `"zero-shot-classification"`
            - `"zero-shot-image-classification"`
            - `"zero-shot-object-detection"`

    Returns:
        (normalized_task: `str`, task_defaults: `dict`, task_options: (`tuple`, None)) The normalized task name
        (removed alias and options). The actual dictionary required to initialize the pipeline and some extra task
        options for parametrized tasks like "translation_XX_to_YY"


    )r   
check_task)r   r|   r|   r   r     s    ,r   c                    s   dd l  d| krtd| dd}t|tr4|g}t fdd|D | d< | dd}t|trj|g}t fd	d|D | d< | d fS )
Nr   r   zNThis model introduces a custom pipeline without specifying its implementation.r~   r|   c                 3   s   | ]}t  |V  qd S Nr   .0cr   r|   r   	<genexpr>  s     z$clean_custom_task.<locals>.<genexpr>r   c                 3   s   | ]}t  |V  qd S r   r   r   r   r|   r   r     s     )r   r   get
isinstancestrtuple)Z	task_infoZpt_class_namesZtf_class_namesr|   r   r   clean_custom_task  s    

r   Trv   ru   rw   ztorch.device)r   r}   r   	tokenizerfeature_extractorimage_processor	frameworkrevisionuse_fastr   devicetrust_remote_codemodel_kwargspipeline_classr   c           -      K   s*  |dkri }| dd}|dk	r@tdt |	dk	r<td|}	||	|dd}| dkrf|dkrftd|dkr~|dk	r~td|dkr|dk	rtdt|trt|}t|trt	j
|fd	| i||}|j|d
< n|dkrht|trht rF|dd}t||||d}|dk	rFt|ddd}t|}|d }W 5 Q R X t	j
|fd	| i||}|j|d
< i }|dk	rtt|di dkr|j}| dkr|dk	rt|dkrt| d } ntdd|  | dkr|dk	rt|tstd| dt||} | |krh| }t||  \}}|dkr|sNtd|d }t||||d}n t| \}}}|dkr|d }|dkrt|||\}}|dk	r|n|}td| d| dt d| d 	 |dkrt|trt	j
|fd	| i||}|j|d
< |dk	rHd!|kr,td"|
dk	r@td# ||d!< |dk	rld$|krdtd%||d$< t|tr||nd}t|ts|dkr|d& |d' d(}t |f|||| d)||\}}|j!}|j!j|d
< t"|t#kp|j$dk	} t"|t%kp|dk	}!t"|t&kp|dk	}"|"r.|!r.d}!|dkrZ| sZ|t'krZ|j(j)t*krZd*} |dkr|"s|t+kr|j(j)t*kr|d+krd*}"|dkr|!s|t,kr|j(j)t*krd*}!| t'krd} | t,krd}!| t+krd}"| r|dkr"t|tr|}nt|tr|}nt-d,t|tt.frt|t.r`|d  d-|}|d }#|d }$n|}#|/ }$|$ d$d t0j
|#f|| d.||$}|"r|dkrt|tr|}n6t|tr|}n$|dk	rt|t1r|}nt-d/t|tt.frt2j
|fd	| i||}|!rl|dkrNt|tr4|}nt|trF|}nt-d0t|tt.frlt3j
|fd	| i||}|j4rl|j45d1rlt|trlztddl6}%dd2l7m8}& t9j:;|st9j:<|r|&=|}'n,t9j:|&j>d3}(|&j?})|(|)g}*|&j@||*d4}'|'|d5< W n^ tAk
rj }+ z>td6| d7|+  tB sHtd8 tC sZtd9 W 5 d}+~+X Y nX | d:kr|j!jDr|j!jDD ]0},|,Ed:r|,} td;|  d<tF  qq|dk	r||d=< |dk	r||d>< |dk	r||d$< |dk	r||d?< |
dk	r|
|d@< |f ||| dA|S )Ba1%  
    Utility factory method to build a [`Pipeline`].

    Pipelines are made of:

        - A [tokenizer](tokenizer) in charge of mapping raw textual input to token.
        - A [model](model) to make predictions from the inputs.
        - Some (optional) post processing for enhancing model's output.

    Args:
        task (`str`):
            The task defining which pipeline will be returned. Currently accepted tasks are:

            - `"audio-classification"`: will return a [`AudioClassificationPipeline`].
            - `"automatic-speech-recognition"`: will return a [`AutomaticSpeechRecognitionPipeline`].
            - `"conversational"`: will return a [`ConversationalPipeline`].
            - `"depth-estimation"`: will return a [`DepthEstimationPipeline`].
            - `"document-question-answering"`: will return a [`DocumentQuestionAnsweringPipeline`].
            - `"feature-extraction"`: will return a [`FeatureExtractionPipeline`].
            - `"fill-mask"`: will return a [`FillMaskPipeline`]:.
            - `"image-classification"`: will return a [`ImageClassificationPipeline`].
            - `"image-segmentation"`: will return a [`ImageSegmentationPipeline`].
            - `"image-to-image"`: will return a [`ImageToImagePipeline`].
            - `"image-to-text"`: will return a [`ImageToTextPipeline`].
            - `"mask-generation"`: will return a [`MaskGenerationPipeline`].
            - `"object-detection"`: will return a [`ObjectDetectionPipeline`].
            - `"question-answering"`: will return a [`QuestionAnsweringPipeline`].
            - `"summarization"`: will return a [`SummarizationPipeline`].
            - `"table-question-answering"`: will return a [`TableQuestionAnsweringPipeline`].
            - `"text2text-generation"`: will return a [`Text2TextGenerationPipeline`].
            - `"text-classification"` (alias `"sentiment-analysis"` available): will return a
              [`TextClassificationPipeline`].
            - `"text-generation"`: will return a [`TextGenerationPipeline`]:.
            - `"text-to-audio"` (alias `"text-to-speech"` available): will return a [`TextToAudioPipeline`]:.
            - `"token-classification"` (alias `"ner"` available): will return a [`TokenClassificationPipeline`].
            - `"translation"`: will return a [`TranslationPipeline`].
            - `"translation_xx_to_yy"`: will return a [`TranslationPipeline`].
            - `"video-classification"`: will return a [`VideoClassificationPipeline`].
            - `"visual-question-answering"`: will return a [`VisualQuestionAnsweringPipeline`].
            - `"zero-shot-classification"`: will return a [`ZeroShotClassificationPipeline`].
            - `"zero-shot-image-classification"`: will return a [`ZeroShotImageClassificationPipeline`].
            - `"zero-shot-audio-classification"`: will return a [`ZeroShotAudioClassificationPipeline`].
            - `"zero-shot-object-detection"`: will return a [`ZeroShotObjectDetectionPipeline`].

        model (`str` or [`PreTrainedModel`] or [`TFPreTrainedModel`], *optional*):
            The model that will be used by the pipeline to make predictions. This can be a model identifier or an
            actual instance of a pretrained model inheriting from [`PreTrainedModel`] (for PyTorch) or
            [`TFPreTrainedModel`] (for TensorFlow).

            If not provided, the default for the `task` will be loaded.
        config (`str` or [`PretrainedConfig`], *optional*):
            The configuration that will be used by the pipeline to instantiate the model. This can be a model
            identifier or an actual pretrained model configuration inheriting from [`PretrainedConfig`].

            If not provided, the default configuration file for the requested model will be used. That means that if
            `model` is given, its default configuration will be used. However, if `model` is not supplied, this
            `task`'s default model's config is used instead.
        tokenizer (`str` or [`PreTrainedTokenizer`], *optional*):
            The tokenizer that will be used by the pipeline to encode data for the model. This can be a model
            identifier or an actual pretrained tokenizer inheriting from [`PreTrainedTokenizer`].

            If not provided, the default tokenizer for the given `model` will be loaded (if it is a string). If `model`
            is not specified or not a string, then the default tokenizer for `config` is loaded (if it is a string).
            However, if `config` is also not given or not a string, then the default tokenizer for the given `task`
            will be loaded.
        feature_extractor (`str` or [`PreTrainedFeatureExtractor`], *optional*):
            The feature extractor that will be used by the pipeline to encode data for the model. This can be a model
            identifier or an actual pretrained feature extractor inheriting from [`PreTrainedFeatureExtractor`].

            Feature extractors are used for non-NLP models, such as Speech or Vision models as well as multi-modal
            models. Multi-modal models will also require a tokenizer to be passed.

            If not provided, the default feature extractor for the given `model` will be loaded (if it is a string). If
            `model` is not specified or not a string, then the default feature extractor for `config` is loaded (if it
            is a string). However, if `config` is also not given or not a string, then the default feature extractor
            for the given `task` will be loaded.
        framework (`str`, *optional*):
            The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be
            installed.

            If no framework is specified, will default to the one currently installed. If no framework is specified and
            both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model is
            provided.
        revision (`str`, *optional*, defaults to `"main"`):
            When passing a task name or a string model identifier: 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.
        use_fast (`bool`, *optional*, defaults to `True`):
            Whether or not to use a Fast tokenizer if possible (a [`PreTrainedTokenizerFast`]).
        use_auth_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`).
        device (`int` or `str` or `torch.device`):
            Defines the device (*e.g.*, `"cpu"`, `"cuda:1"`, `"mps"`, or a GPU ordinal rank like `1`) on which this
            pipeline will be allocated.
        device_map (`str` or `Dict[str, Union[int, str, torch.device]`, *optional*):
            Sent directly as `model_kwargs` (just a simpler shortcut). When `accelerate` library is present, set
            `device_map="auto"` to compute the most optimized `device_map` automatically (see
            [here](https://huggingface.co/docs/accelerate/main/en/package_reference/big_modeling#accelerate.cpu_offload)
            for more information).

            <Tip warning={true}>

            Do not use `device_map` AND `device` at the same time as they will conflict

            </Tip>

        torch_dtype (`str` or `torch.dtype`, *optional*):
            Sent directly as `model_kwargs` (just a simpler shortcut) to use the available precision for this model
            (`torch.float16`, `torch.bfloat16`, ... or `"auto"`).
        trust_remote_code (`bool`, *optional*, defaults to `False`):
            Whether or not to allow for custom code defined on the Hub in their own modeling, configuration,
            tokenization or even pipeline 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.
        model_kwargs (`Dict[str, Any]`, *optional*):
            Additional dictionary of keyword arguments passed along to the model's `from_pretrained(...,
            **model_kwargs)` function.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional keyword arguments passed along to the specific pipeline init (see the documentation for the
            corresponding pipeline class for possible values).

    Returns:
        [`Pipeline`]: A suitable pipeline for the task.

    Examples:

    ```python
    >>> from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer

    >>> # Sentiment analysis pipeline
    >>> analyzer = pipeline("sentiment-analysis")

    >>> # Question answering pipeline, specifying the checkpoint identifier
    >>> oracle = pipeline(
    ...     "question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="bert-base-cased"
    ... )

    >>> # Named entity recognition pipeline, passing in a specific model and tokenizer
    >>> model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english")
    >>> tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
    >>> recognizer = pipeline("ner", model=model, tokenizer=tokenizer)
    ```Nr   r   r   )r   r   r   _commit_hashz}Impossible to instantiate a pipeline without either a task or a model being specified. Please provide a task class or a modela  Impossible to instantiate a pipeline with tokenizer specified but not the model as the provided tokenizer may not be compatible with the default model. Please provide a PreTrainedModel class or a path/identifier to a pretrained model when providing tokenizer.a  Impossible to instantiate a pipeline with feature_extractor specified but not the model as the provided feature_extractor may not be compatible with the default model. Please provide a PreTrainedModel class or a path/identifier to a pretrained model when providing feature_extractor._from_pipeliner   	subfolder)r   r   r   rzutf-8)encodingZbase_model_name_or_pathcustom_pipelinesr   Fr$   zhWe can't infer the task automatically for this model as there are multiple tasks available. Pick one in z, z^Inferring the task automatically requires to check the hub with a model_id defined as a `str`.z is not a valid model_id.zLoading this pipeline requires you to execute the code in the pipeline file in that repo on your local machine. Make sure you have read the code there to avoid malicious use, then set the option `trust_remote_code=True` to remove this error.r   )r   r   z$No model was supplied, defaulted to z and revision z (/zb).
Using a pipeline without specifying a model name and revision in production is not recommended.
device_mapzYou cannot use both `pipeline(... device_map=..., model_kwargs={"device_map":...})` as those arguments might conflict, use only one.)zBoth `device` and `device_map` are specified. `device` will override `device_map`. You will most likely encounter unexpected behavior. Please remove `device` and keep `device_map`.torch_dtypezYou cannot use both `pipeline(... torch_dtype=..., model_kwargs={"torch_dtype":...})` as those arguments might conflict, use only one.)r   r~   )r   r~   )model_classesr   r   r   Tr   zImpossible to guess which tokenizer to use. Please provide a PreTrainedTokenizer class or a path/identifier to a pretrained tokenizer.r   )r   r   zImpossible to guess which image processor to use. Please provide a PreTrainedImageProcessor class or a path/identifier to a pretrained image processor.zImpossible to guess which feature extractor to use. Please provide a PreTrainedFeatureExtractor class or a path/identifier to a pretrained feature extractor.ZWithLM)BeamSearchDecoderCTC*)allow_patternsdecoderz!Could not load the `decoder` for z . Defaulting to raw CTC. Error: z*Try to install `kenlm`: `pip install kenlmz6Try to install `pyctcdecode`: `pip install pyctcdecoder   zO"translation" task was used, instead of "translation_XX_to_YY", defaulting to ""r   r   r   r   )r}   r   r   )Gr   r   r   r   r   r   r   r   r   r   Zfrom_pretrainedr   r   r   r   openjsonloadlenr   r   listkeysjoinr   r   r   r   r/   loggerwarningr   r0   r   r   r   Ztokenizer_classr   r   NO_TOKENIZER_TASKS	__class____name__MULTI_MODEL_CONFIGSNO_IMAGE_PROCESSOR_TASKSNO_FEATURE_EXTRACTOR_TASKSr   r   copyr   r   r   r   Z_processor_classendswithkenlmZpyctcdecoder   ospathisdirisfileZload_from_dirZ$_LANGUAGE_MODEL_SERIALIZED_DIRECTORYZ_ALPHABET_SERIALIZED_FILENAMEZload_from_hf_hubImportErrorr   r    Ztask_specific_params
startswithUserWarning)-r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   kwargsr   Z
hub_kwargsr   Zmaybe_adapter_pathfZadapter_configZcustom_tasksZnormalized_taskZtargeted_taskZtask_optionsZ	class_refZdefault_revisionZ
model_namer   Zmodel_configZload_tokenizerZload_feature_extractorZload_image_processorZtokenizer_identifierZtokenizer_kwargsr   r   r   Zlanguage_model_globZalphabet_filenamer   r   keyr|   r|   r   pipeline  s     " 




 



   



















  
 
 
 







r   )N)NNNNNNNNTNNNNNNN)ior   r   r   pathlibr   typingr   r   r   r   r   r   r	   Zhuggingface_hubr
   numpyr   Zconfiguration_utilsr   Zdynamic_module_utilsr   Zfeature_extraction_utilsr   Zimage_processing_utilsr   Zmodels.auto.configuration_autor   Z#models.auto.feature_extraction_autor   r   Z!models.auto.image_processing_autor   r   Zmodels.auto.modeling_autor   r   Zmodels.auto.tokenization_autor   r   Ztokenization_utilsr   utilsr   r   r   r   r   r    r!   r"   r#   Zaudio_classificationr%   Zautomatic_speech_recognitionr&   baser'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r   r1   r2   Zdepth_estimationr3   Zdocument_question_answeringr4   Zfeature_extractionr5   Z	fill_maskr6   Zimage_classificationr7   Zimage_segmentationr8   Zimage_to_imager9   Zimage_to_textr:   Zmask_generationr;   Zobject_detectionr<   Zquestion_answeringr=   r>   Ztable_question_answeringr?   r@   Ztext2text_generationrA   rB   rC   Ztext_classificationrD   Ztext_generationrE   Ztext_to_audiorF   Ztoken_classificationrG   rH   rI   rJ   Zvideo_classificationrK   Zvisual_question_answeringrL   Zzero_shot_audio_classificationrM   Zzero_shot_classificationrN   rO   Zzero_shot_image_classificationrP   Zzero_shot_object_detectionrQ   Z
tensorflowr   Zmodels.auto.modeling_tf_autorR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   Ztorchr]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   Zmodeling_tf_utilsru   Zmodeling_utilsrv   Ztokenization_utils_fastrw   Z
get_loggerr   r   ZTASK_ALIASESZSUPPORTED_TASKSsetr   r   r   r   itemsr   valuesaddr   r   r   r   r   r   r   boolintr   r|   r|   r|   r   <module>   s  $,04h



 
 
	  







  }


/                
