o
    ej                     @   sh   d Z ddlZddlZddlmZmZ ddlZed e G dd dejZe G dd dejZ	dS )	z8
Ways to transform interfaces to produce new interfaces
    N)documentset_documentation_groupZmix_interfacec                       (   e Zd ZdZdejf fddZ  ZS )ParallelaA  
    Creates a new Interface consisting of multiple Interfaces in parallel (comparing their outputs).
    The Interfaces to put in Parallel must share the same input components (but can have different output components).

    Demos: interface_parallel, interface_parallel_load
    Guides: advanced-interface-features
    
interfacesc                    s   g  D ]}t |tjstd |j q fdd}ddd  D |_| d j	d}|
| t jd
i | d	S )a*  
        Parameters:
            interfaces: any number of Interface objects that are to be compared in parallel
            options: additional kwargs that are passed into the new Interface object to customize it
        Returns:
            an Interface object comparing the given models
        zOParallel requires all inputs to be of type Interface. May not work as expected.c                     s   t j fddD  I d H }dd |D }g }t|D ]\}}t|jdkr/|| q|| qtdkr?|d S |S )Nc                    s   g | ]
}| d t qS )r   )call_functionlist).0	interfaceargs :D:\Projects\ConvertPro\env\Lib\site-packages\gradio/mix.py
<listcomp>,   s    z:Parallel.__init__.<locals>.parallel_fn.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )
predictionr   )r	   rvr   r   r   r   .   s       r   )asynciogatherziplenoutput_componentsappendextend)r   Zreturn_values_with_durationsZreturn_valuesZcombined_listr
   return_valuer   outputsr   r   parallel_fn*   s   
z&Parallel.__init__.<locals>.parallel_fnz | c                 S      g | ]}|j qS r   __name__r	   ior   r   r   r   9       z%Parallel.__init__.<locals>.<listcomp>r   )fninputsr   Nr   )
isinstancegradio	Interfacewarningswarnr   r   joinr    input_componentsupdatesuper__init__)selfr   optionsr
   r   kwargs	__class__r   r   r/      s   
zParallel.__init__r    
__module____qualname____doc__r'   r(   r/   __classcell__r   r   r3   r   r          r   c                       r   )Seriesa#  
    Creates a new Interface from multiple Interfaces in series (the output of one is fed as the input to the next,
    and so the input and output components must agree between the interfaces).

    Demos: interface_series, interface_series_load
    Guides: advanced-interface-features
    r   c                    s    fdd} D ]}t |tjstd qddd  D |_| d j d j d j	d	}|
| t jdi | d
S )a*  
        Parameters:
            interfaces: any number of Interface objects that are to be connected in series
            options: additional kwargs that are passed into the new Interface object to customize it
        Returns:
            an Interface object connecting the given models
        c                     s   t D ]E\}}|dkr|js fddt |jD  |dt I d H d  t|jdkr3 g |td k rJ|jsJ fddt |jD  qt|jdkrV d S  S )Nr   c                       g | ]\}}|  | qS r   )
preprocess)r	   iZinput_componentdatar   r   r   [       z9Series.__init__.<locals>.connected_fn.<locals>.<listcomp>r   r   c                    r<   r   )postprocess)r	   r>   Zoutput_componentr?   r   r   r   g   rA   )	enumerateapi_moder,   r   r   r   r   )r@   idxr
   r   r?   r   connected_fnW   s&   

z%Series.__init__.<locals>.connected_fnzMSeries requires all inputs to be of type Interface. May not work as expected.z => c                 S   r   r   r   r!   r   r   r   r   x   r#   z#Series.__init__.<locals>.<listcomp>r   )r$   r%   r   Z	_api_modeNr   )r&   r'   r(   r)   r*   r+   r    r,   r   rD   r-   r.   r/   )r0   r   r1   rG   r
   r2   r3   rF   r   r/   N   s   	
zSeries.__init__r5   r   r   r3   r   r;   D   r:   r;   )
r8   r   r)   Zgradio_client.documentationr   r   r'   r(   r   r;   r   r   r   r   <module>   s    5