
    Pi                    Z    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
Z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                2    t          t                     j                                      d          rt	                     nSt          t                     j                                      d          rt                     nt          d           fd}r                                ni }||d<   |d= |d= t          t                     j                                      d          r 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                    r2 d         |  }t          t                    j                                      d          rddlm} t          |j        j        |j	        j
        |j	        j        |j        j        f          r | }n di |}t          |j        j        |j        j        f          r d         || d                   }n d         |          }|S t          t                    j                                      d          r 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   outputr   pipeline_infos       d/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/pipelines.pyfnzload_from_pipeline.<locals>.fn&   s    %	?.=.7D4>>,--889QRR !222222 !5P!6R!6J!6R	  , $8T?DD#8++d++D !2J!6R  	@ :]=9$q	JJFF9]=9$??FT(^^.//::;PQQ x''$''5}5d;; 
 =>>>    r(   r   r   r   title)r   r   r   r   r   r   r"   copymodelconfigname_or_path	__class____name__r   r(   interface_infor&   s   `  @r'   load_from_pipeliner3      s1    4>>$%%001JKK 
4X>>	T(^^&	'	'	2	23I	J	J 
1(;;L
 
 	
&? &? &? &? &? &?P .;B]'')))NN4|$}%
 tH~~())445MNN	)**( 7 r)   c                    t          t                     j                                      d          rt	                     nt          d           fd}|d         d          j         d j        j        j	         dd}|S )	Nztransformers_js_py.z0pipeline must be a transformers_js_py's pipelinec                    K   d         }d         }                     dd          }|r ||  n| } |  d {V }|r ||g|r| ndR  n|}|S )Nr   r   postprocess_takes_inputsFr   )get)	r#   r   r   r6   preprocessed_paramspipeline_outputpostprocessed_outputr   r&   s	          r'   r(   z!load_from_js_pipeline.<locals>.fnc   s      "<0
#M2#0#4#45OQV#W#W 5?Kjj&11V (*= >>>>>>> !KKW5M+U66SUWWWW  	 $#r)   inputsoutputsz ())r(   r;   r<   r*   )
r   r   r   r   r   r"   taskr,   r-   _name_or_pathr1   s   `  @r'   load_from_js_pipeliner@   ]   s    
4>>$%%001FGG M7AAKLLL$ $ $ $ $ $  ) +MKKX^%:%HKKK	 N r)   )r   r	   r
   r   )r
   r   )__doc__
__future__r   typingr   gradio.pipelines_utilsr   r   r   	diffusersr   r3   r@   r   r)   r'   <module>rF      s   ; ; # " " " " "                       G G G GT     r)   