
    ;3h-                    `    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y)
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_pipelineNc                    t        t               j                        j                  d      rt	               nDt        t               j                        j                  d      rt               nt        d       fd}rj                         ni }||d<   |d= |d= t        t               j                        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                    r@ d   |  }t        t              j                        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         }|S  d   |      }|S t        t              j                        j                  d      r di |} d   |      }|S y 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pipelinepipeline_infos       P/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/pipelines.pyfnzload_from_pipeline.<locals>.fn&   s[   .=.7D4>,,-889QR2 !55PP!66RR!66JJ!66RR	 $T?D#+d+D !22JJ!66RR :]=9$q	JF  :]=9$?FT(^../::;PQ'$'5}5d; R
 =>>    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_pipeliner0      s     4>$$%001JK4X>	T(^&&	'	2	23I	J1(;L
 	
&?P .;]'')NN4|$}%
 tH~(()445MN 	**(( 7 r&   c                    t        t               j                        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   }j                  dd      }|r ||  n| } |  d {   }|r ||g|r| nd }|S |}|S 7 w)Nr
   r   postprocess_takes_inputsFr   )get)	r   r
   r   r3   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 5?j&1V (*= >>  W5M6SUW 	 $# ! 	 $# ?s   .AAAinputsoutputsz ())r%   r8   r9   r'   )
r   r   r   r   r   r   taskr)   r*   _name_or_pathr.   s   `  @r$   load_from_js_pipeliner=   ]   s    
4>$$%001FG7AKLL$  ) +MM?"X^^%:%:%H%H$IK	N r&   )r"   z3transformers.Pipeline | diffusers.DiffusionPipelinereturndict)r>   r?   )__doc__
__future__r   typingr   gradio.pipelines_utilsr   r   r   	diffusersr   r0   r=   r   r&   r$   <module>rE      sE   ; #    GAG	GTr&   