o
    ۷i                     @  s\   d Z ddlmZ ddlmZ ddlmZmZmZ er"ddl	Z	ddl
Z
dd
dZdddZdS )zThis module should not be used directly as its API is subject to change. Instead,
please use the `gr.Interface.from_pipeline()` function.    )annotations)TYPE_CHECKING)handle_diffusers_pipelinehandle_transformers_js_pipelinehandle_transformers_pipelineNpipeline3transformers.Pipeline | diffusers.DiffusionPipelinereturndictc                   s   t t jdrt nt t jdrt ntd fdd}r/ ni }||d< |d= |d= t t jd	rJ jj	j
n jj|d
< |S )aB  
    Gets the appropriate Interface kwargs for a given Hugging Face transformers.Pipeline or diffusers.DiffusionPipeline.
    pipeline (transformers.Pipeline): the transformers.Pipeline from which to create an interface
    Returns:
    (dict): a dictionary of kwargs that can be used to construct an Interface object
    ztransformers.pipelines.zdiffusers.pipelines.z>pipeline must be a transformers.pipeline or diffusers.pipelinec                    s   rnd |  }t t jdrSddlm} t |jj|j	j
|j	j|jjfr. | }n di |}t |jj|jjfrKd || d }|S d |}|S t t jdrl di |}d |}|S d S td)	N
preprocesstransformers.pipelinesr   )	pipelinespostprocesszdiffusers.pipelineszpipeline_info can not be None. )strtype
__module__
startswithtransformersr   
isinstancetext_classificationTextClassificationPipelinetext2text_generationText2TextGenerationPipelineTranslationPipelinetoken_classificationTokenClassificationPipelineobject_detectionObjectDetectionPipeline
ValueError)paramsdatar   outputr   pipeline_infor   F/home/ubuntu/vllm_env/lib/python3.10/site-packages/gradio/pipelines.pyfn&   s<   
	zload_from_pipeline.<locals>.fnr&   r   r   r   title)r   r   r   r   r   r   r   copymodelconfigname_or_path	__class____name__r   r&   interface_infor   r#   r%   load_from_pipeline   s"   


(r0   c                   sb   t t jdrt ntd fdd}|d d  j d jjj	 dd	}|S )
Nztransformers_js_py.z0pipeline must be a transformers_js_py's pipelinec                    sd   d }d } dd}|r||  n| } | I d H }|r.||g|r'| ndR  }|S |}|S )Nr   r   postprocess_takes_inputsFr   )get)r    r   r   r1   preprocessed_paramspipeline_outputpostprocessed_outputr#   r   r%   r&   c   s   z!load_from_js_pipeline.<locals>.fninputsoutputsz ())r&   r6   r7   r'   )
r   r   r   r   r   r   taskr)   r*   _name_or_pathr.   r   r#   r%   load_from_js_pipeline]   s   
r;   )r   r   r	   r
   )r	   r
   )__doc__
__future__r   typingr   gradio.pipelines_utilsr   r   r   	diffusersr   r0   r;   r   r   r   r%   <module>   s    
J