
    Pil                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	  e
 ej        d                    Zd ZdId	Zd
 Zd Zd ZdJdZdKdZdLdZdMdZdNdOdZdPdZd ZdQd"Zd# Zd$ Z G d% d&ej                  Z	 	 dRdSd+Zd, Zd- Z d. Z!d/ Z"d0 Z#dTd2Z$d3 Z%d4 Z&d5 Z'd6 Z(d7 Z)d8Z*d9 Z+d: Z,	 dUdVdGZ-dH Z.dS )W    )annotationsN)PIPEPopenruffc                N    |                                  D ]\  }}|dk    r|c S dS )z9Finds the first key in a dictionary that is not "return".returnNitems)	some_dictkeyvalues      ~/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/cli/commands/components/_docs_utils.pyfind_first_non_return_keyr      s;    oo''  
U(??LLL 4    codestrtypec                   |dk    rd|  } t           s| S g d}t          |t          t          t          d          }|                    t	          |                     \  }}|dk    r"t          j        dd|t
          j        	          }t          j        d
|t
          j	                  }|r'|
                    d                                          S |                                dk    r| S |                                S )zFormats code using ruff.r   zvalue = )r   format-z--line-length=60T)stdinstdoutstderruniversal_newlines)inputz^\s*value =\s* flagsz^\s*\((.*)\)\s*$   )RUFF_INSTALLEDr   r   communicater   resub	MULTILINEsearchDOTALLgroupstrip)r   r   	ruff_argsprocessformatted_codeerrstripped_sources          r   r   r      s   w $   ;;;I  G "--CII->>NCwr>
 
 
 i 3^RYOOO &$$Q''--///					2	%	%##%%%r   c                |   t          | t                    rd|  dS t          j        |           rE| j        dk    r:t          | dd          }|%t          j        |           r| j         d| j         }|S t          j        |           r| j         d| j         S t          | dd          }|t          |           }|S )zGets the name of a parameter."builtins__name__N.)
isinstancer   inspectisclass
__module__getattrr1   )paramp
param_names      r   get_param_namer;   8   s     % 5|||u %"2j"@"@E:t,,9//9#66en66Au 6"55U^555
D11JZZ
r   c                8    | | t          d          u s| dv rdS | S )z Formats None and NonType values.N)NoneNoneTyper=   )r   r   s    r   format_noner@   N   s,    }d++u8L/L/LvLr   c                ^    | dS t          | t                    rd|  dS t          |           S )zFormats a value.Nr=   r/   )r3   r   r?   s    r   format_valuerB   U   s8    }v% 5|||u::r   	docstringparameter_namec                    d| d}t          j        || t           j                  }|r'|                    d                                          S dS )z#Gets the docstring for a parameter.z\bz\b:[ \t]*(.*?)(?=\n|$)r   r   N)r"   r%   r&   r'   r(   )rC   rD   patternmatchs       r   get_parameter_docstringrH   ^   sS    :N:::GIgy	:::E &{{1~~##%%%4r   c                    d}t          j        || t           j        t           j        z            }|r'|                    d                                          S dS )z&Gets the docstring for a return value.z*\bReturn(?:s){0,1}\b:[ \t\n]*(.*?)(?=\n|$)r   r   N)r"   r%   r&   
IGNORECASEr'   r(   )rC   rF   rG   s      r   get_return_docstringrK   i   sO    ;GIgy	BM0IJJJE &{{1~~##%%%4r   objdictr   r   
typing.Anyc                @    |dk    rdnd}t          ||          | |<   | S )zAdds a value to a dictionary.defaultr   r   )r   )rL   r   r   r   s       r   	add_valuerQ   t   s-    Y&&77FDeT""CHJr   
dictionarykeys	list[str]c                b    |dd         D ]}|                      |i           } || |d         <   dS )zESets a value in a nested dictionary for a key path that may not existN)
setdefault)rR   rS   r   r   s       r   set_deeprX   }   sD    CRCy 4 4**333

 JtBxr   c                F    	 |D ]
}| |         } | S # t           $ r |cY S w xY w)zPGets a value from a nested dictionary without erroring if the key doesn't exist.)KeyError)rR   rS   rP   r   s       r   get_deepr[      sK     	) 	)C#CJJ   s      r   tuplec                    t          | d          r| j        S t          | d          r| j        j        S t          j        |           S )z(Gets the type arguments for a type hint.__args__	__extra__)hasattrr^   r_   typingget_args)	type_hints    r   get_type_argumentsrd      sK    y*%% *!!	K	(	( *"++y)))r   c                   t          j        |           r| j        S t          | t          j                  r| j        j        S t          | t          j                  rdS t          | dd          t          j
        u rdS t          |           S )z&Gets a human readable name for a type.Union
__origin__NLiteral)r4   r5   r1   r3   typesGenericAliasrg   	UnionTyper7   ra   rh   r   )args    r   get_container_namerm      s~    s |#u)** ~&&	C	)	) w	lD	)	)V^	;	;y3xxr   _typelist[typing.Any]c                   g }d}| D ]}t          |t                    rt          |          }'t          |t                    r8t	          |          dk    rP|                    t          |                      t|                    |           t	          |          dk    r|S |dv rd                    |          S | dd                    |           dS )z+Pretty formats a possibly nested type hint.Nr   )rh   rf   z| [,])r3   r   r@   listlenappendformat_typejoin)rn   s_currentts       r   rw   rw      s     	AH 
 
a 		"1~~H4   	1vv{{HHA())))HHQKKKK
1vv{{	)	)	)yy||++SXXa[[++++r   c                x    	 	 ddfd|j         dz   }i }g } | |||d          }t          |          }|||fS )	z$Gets the type hints for a parameter.TNuser_fn_refsrT   c           	        g }t          |           }t          j        |           r| j                            |          rt          j        |           }t          t          j        dd|t          j	                  d          }|ht          ||dg          }	|		| j        g}	n8t          |	t                    r#| j        |	vr|	                    | j                   t          ||dg|	           t          || j        dg          t          || j        dg|           t!          j        |                                           D ]?}
 |
|||d| j                  }t'          |          d	k    r|                    |           @|r=|                    | j                   | j        |vr|                    | j                   nt'          |          d	k    ro|r"|                    t)          |                      t          |          D ]:} ||||||          }t'          |          d	k    r|                    |           ;n$|r"|                    t+          |                      |S )
z4Recursively extracts the arguments from a type hint.z(\"\"\".*?\"\"\")r   r   otherNrefssourceFr   )rd   r4   r5   r6   
startswith	getsourcer   r"   r#   r&   r[   r1   r3   rt   rv   rX   ra   get_type_hintsvaluesru   rm   r;   )rl   module_name_prefixadditional_interfacesr}   rv   arg_of	arg_namesargssource_coder   
field_typenew_args	inner_argextract_argss                r   r   z$get_type_hints.<locals>.extract_args   s    	!#&& ?3 8	6CN$=$=>P$Q$Q 8	6 "+C00K +RBINNNPW K ! 57GHH<L>DDd++ .D0H0HKK---.0@$GGG-h/GHHP.x0H+VVV$3C88??AA / /
'<&) L  x==1$$$$X... 6  ...<|33 ''555YY]] :  !3C!8!8999!$ZZ / /	'<&)   x==1$$$$X.../  6  !4!4555r   r2   )TN)r}   rT   )r1   rw   )r8   moduler   r   r}   r   formatted_typer   s          @r   r   r      s     F F F F F F FP  3.L< D !&&N1<@@r   c           
        i }d}t          j        |           D ]2\  }}|                    d          rt          j        |          st          j        |          ri ||<   t          j        |          pd}t                              dd |                    d          D                       }|||         d<   i ||         d<   di i|d	<   t          j        |          D ]1\  }}t          j	        |          st          j        |          r|d
vr4i ||         d         |<   t          j        |          pd}	d}
	 t          j        |          }n# t          $ r d}
|j        }d}Y nw xY wt          j        |          }|                                D ]\  }}|dk    r|dk    s|dk    r|dk    r|
dk    r|                    |d          }i }g }nt          ||           \  }}}|d	         d                             |           i ||         d         |         |<   |dk    rt%          |	          }nt'          |	|          }t)          ||         d         |         |         d|           |j                            |d           V|j        |         j        }|t           j        ur6t)          ||         d         |         |         dt1          |                     |||         d         |         |         d<   |dv rt3          ||         d         |                   ||         d         |         d<   t5          |d	d|g          }|#t7          |d	d|gt9          |                     t9          |          }|                    |           t7          |d	d|g|           |dk    r`i ||         d<   t;          |t<                    r@|D ]=}d d |j                             d|          d||         d         t          |          <   >3t5          |d	d|g          }|!t7          |d	d|gt=          |                     4||fS )Ncomplex_r   
c                <    g | ]}t          j        d |          |S )z^\S+:)r"   rG   ).0ry   s     r   
<listcomp>z&extract_docstrings.<locals>.<listcomp>(  s*    TTTqbhxQR>S>STTTTr   descriptionmembersr   __meta__)__init__
preprocesspostprocesssimpler   r   r   r   rP   )r   r   r   r}   EVENTSeventsz{{ component }})r   rP   r   )!r4   
getmembersr   
isfunctionr5   getdocr   rx   splitismethodra   r   	Exception__annotations__	signaturer
   getupdaterK   rH   rQ   
parametersrP   _emptyrB   r   r[   rX   setr3   rt   docreplace)r   docsglobal_type_modenamerL   main_docstringcleaned_docstringmember_namemembermember_docstring	type_modehintsr   r:   r8   r   r   r}   rC   default_valueadditional_refseventfinal_user_fn_refss                          r   extract_docstringsr     sF   D '// |Y |Y	c??3 	c"" t	goc&:&: t	DJ$^C006BN #TTN0066TTT! !
 ):DJ}%$&DJy! 7<D'.'9#'>'> h h#V#F++ \"w/A&/I/I \""*SSS 9;DJy)+6'.~f'='='C$ )I4 & 5f = =$ 4 4 4$,	 & 6+3(((4
 !( 1& 9 9I .3[[]] I" I")
E&(22{m7S7S(H449T9T$$00(-		*b(A(AI461+-LL !/uf = =	 ) 5 , Z()@AHH1   JLT
9-k::F%11(<=M(N(NII(? 0*) )I " Jy1+>zJ"%   %/33JEEQ,5,@,L,TM,GNBB )$(Jy$9+$Fz$R$-$0$?$?!" !" !" & T
9-k::F)
 '*GGG 9$(Jy$9+$F!" !" !Jy1+>wG
 /7 $z>4&H/ /O  /6 ($(%/$F$'$5$5!" !" !" !" 36o2F2F / 6 6| D D D ($(%/$F$3!" !" !"
 (**+-DJx(!&$// %+  E(,+//4y/@/@$5t0" 0"@ @DJx0U<< &dZ,NOO)TJ=tDV?W?WXXX"##s    EE-,E-c                  $    e Zd ZU ded<   ded<   dS )AdditionalInterfacerT   r   r   r   N)r1   r6   __qualname__r    r   r   r   r     s"         OOOKKKKKr   r   
interfaces%dict[str, AdditionalInterface] | Noner}   dict[str, list[str]] | Nonec           	         d}| <|                                  D ]'\  }}|d| d|                    dd          pd dz  }(|dz  }d}|&|                                 D ]\  }}|d	| d| dz  }|dz  }d
| d| dS )z8Makes the javascript code for the additional interfaces.{Nz
            z: r   z[]z, }z
          zfunction() {
    const refs = z;
    const user_fn_refs = a  ;
    requestAnimationFrame(() => {

        Object.entries(user_fn_refs).forEach(([key, refs]) => {
            if (refs.length > 0) {
                const el = document.querySelector(`.${key}-user-fn`);
                if (!el) return;
                refs.forEach(ref => {
                    el.innerHTML = el.innerHTML.replace(
                        new RegExp("\\b"+ref+"\\b", "g"),
                        `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
                    );
                })
            }
        })

        Object.entries(refs).forEach(([key, refs]) => {
            if (refs.length > 0) {
                const el = document.querySelector(`.${key}`);
                if (!el) return;
                refs.forEach(ref => {
                    el.innerHTML = el.innerHTML.replace(
                        new RegExp("\\b"+ref+"\\b", "g"),
                        `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
                    );
                })
            }
        })
    })
}
)r
   r   )r   r}   js_obj_interfacesinterface_name	interfacejs_obj_user_fn_refs
class_namer   s           r   make_jsr     s   
 )3)9)9);); 	I 	I%NI "I"I "I(}}VT::Bd"I "I "I I , 2 2 4 4 	$ 	$J $$$$ $$$$ $$ $$ $ 3 #   -       r   c                n    d}|                                  D ]\  }}|d| d| d|d          d| d	z  }|S )GRenders additional helper classes or types that were extracted earlier.r   z

    code_z = gr.Markdown("""
## ``
```python
r   z%
```""", elem_classes=["md-custom", "z"], header_links=True)
r	   r   r   r   r   s       r   render_additional_interfacesr     s     F%/%5%5%7%7  !	 
   8	 
 )7   	 Mr   c                b    d}|                                  D ]\  }}|d| d|d          dz  }|S )r   r   
## `r   r   
```
r	   r   s       r   %render_additional_interfaces_markdownr     sg     F%/%5%5%7%7  !	   8   	 Mr   c                $    | r	d| d| dS d| dS )z[Renders a version badge for the package. PyPi badge if it exists, otherwise a static badge.z"<a href="https://pypi.org/project/zP/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/z"></a>zH<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%20z%20-%20orange">r   )pypi_existslocal_versionr   s      r   render_version_badger     sP     } [d  [  [  MQ  [  [  [  	[|\i||||r   c                    | dS d|  dS )z>Renders a github badge for the package if a repo is specified.Nr   	<a href="z/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a>r   )repos    r   render_github_badger     s,    |r gT  g  g  g  	gr   c                    | dS d|  dS )z@Renders a discuss badge for the package if a space is specified.Nr   r   z/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>r   )spaces    r   render_discuss_badger     s,    }r @U  @  @  @  	@r   r   c                @    t          |           dk    rdS d| ddg dS )Renders the events for a class.r   r   z?
    gr.Markdown("### Events")
    gr.ParamViewer(value=_docs["z"]["events"], linkify=Event)

)ru   )r   r   s     r   render_class_eventsr     sC    
6{{ar!% >EY   	r   c                    ||||dS d}||rdt          |           dndz  }||rdt          |           ndz  }|||d|pd d	|pd d
z  }| d|  dS )&Makes the user function for the class.Nr   a  
    gr.Markdown("""

### User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

z- **As input:** Is passed, r   z - **As output:** Should return, z%

 ```python
def predict(
    value: Unknownz
) -> z:
    return value
```z"
""", elem_classes=["md-custom", "z-user-fn"], header_links=True)
format_description)r   user_fn_input_typeuser_fn_input_descriptionuser_fn_output_typeuser_fn_output_descriptionmds         r   make_user_fnr     s     	"'%-&.r
B $	W&89R&S&SWWWWB %	[+=>X+Y+Y[[[B %)<)H
  +)	 
 &Y   	   %/   r   c                    | d                                          | dd          z   } |                     d          dz   } | S )Nr   r   r2   )lowerrstrip)r   s    r   r   r   T  sB    a.&&((;qrr?:K$$S))C/Kr   c                    | |||dS d}||rdt          |           dndz  }||rdt          |           ndz  }| ||d| pd d	|pd d
z  }|S )r   Nr   a  
### User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

z- **As output:** Is passed, r   z- **As input:** Should return, z'

 ```python
 def predict(
     value: r   z
 ) -> z:
     return value
 ```
 r   )r   r   r   r   r   s        r   make_user_fn_markdownr   Z  s     	"'%-&.r

B $	X'9:S'T'TXXXXB %	Z*<=W*X*XZZZB %)<)H
   ,9	 
 'i   	 Ir   c                    t          |           dk    rdS d}|                                 D ]\  }}|d| d|d          dz  }|S )r   r   r   z;
### Events

| name | description |
|:-----|:------------|
z| `z` | r   z |
)ru   r
   )r   event_table
event_namer   s       r   render_class_events_markdownr     sj    
6{{arK $\\^^ H H
EGZGGU=-AGGGGr   c                   d}| D ]}t          ||ddddg          }t          ||ddddg          }t          ||ddddg          }t          ||ddddg          }t          |d	d
gi           pi }|d| d| dt          |                                           dt          ||                             dd          |           dt          |||||           dz  }|S )0Renders the class documentation for the package.r   r   r   r   r   r   r   r   r   r   z
    gr.Markdown("""
## `zk`

### Initialization
""", elem_classes=["md-custom"], header_links=True)

    gr.ParamViewer(value=_docs["z#"]["members"]["__init__"], linkify=r   r   N

r   )r[   rt   rS   r   r   r   )	exportsr   docs_classesr   r   r   r   r   linkifys	            r   render_class_docsr    si   L & &
%:y,&I
 
 %-:y,-P%
 %
! ':y-&I
 
 &.:y--P&
 &
" 4*.E!FKKQr   ",      T*%))(D99:FF  ")#*    	. r   a  
<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>value</code></td>
<td align="left"><code>list[Parameter] | None</code></td>
<td align="left"><code>None</code></td>
<td align="left">A list of dictionaries with keys "type", "description", and "default" for each parameter.</td>
</tr>
</tbody></table>
c                    d}|                                  D ])\  }}|d| d|d          d|d          d|d          d		z  }*|d
z   S )z,Renders the parameter table for the package.z<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>z
<tr>
<td align="left"><code>z></code></td>
<td align="left" style="width: 25%;">

```python
r   z#
```

</td>
<td align="left"><code>rP   z</code></td>
<td align="left">r   z</td>
</tr>
z</tbody></table>r	   )paramstabler:   r8   s       r   render_param_tabler    s    	E $\\^^  
E "  v  i(  &   	 %%%r   c                   d}| D ]}t          ||ddddg          }t          ||ddddg          }t          ||ddddg          }t          ||ddddg          }|d	| d
t          ||         d         d                    dt          ||                             dd                     dt	          ||||           d	z  }|S )r   r   r   r   r   r   r   r   r   r   z`

### Initialization

r   r   r   Nr   )r[   r  r   r   r   )r   r   r  r   r   r   r   r   s           r   render_class_docs_markdownr	    s@   L  
%:y,&I
 
 %-:y,-P%
 %
! ':y-&I
 
 &.:y--P&
 &
" 	  
 D$Y/
;<<  d:.228TBBCC  "")#*	    	$ r   Fr   r   r   r   
str | Nonedemor   r   r   boolsuppress_demo_checkc	                "   d | D             }	|sA|                     d          dk    r(|                     d          dk    rt          d          |                    dd          }d}
t          |	|           }|
d	|  d
| dt	          |||           dt          |           dt          |           d| d| d| d| dt          | d         d                    dt          t          | ddg          t          | ddg                     dz  }
|
S )Nc                    g | ]
}|d k    |S r   r   r   r   s     r   r   zmake_space.<locals>.<listcomp>3  "    >>>SC:,=,=S,=,=,=r   zif __name__ == '__main__'rV   zif __name__ == "__main__"a0  The demo must be launched using `if __name__ == '__main__'`, otherwise the docs page will not function correctly.

To fix this error, launch the demo inside of an if statement like this:

if __name__ == '__main__':
    demo.launch()

To ignore this error pass `--suppress-demo-check` to the docs command.z"""z\"\"\"z;
import gradio as gr
from app import demo as app
import os
z	
_docs = a  

abs_path = os.path.join(os.path.dirname(__file__), "css.css")

with gr.Blocks(
    css=abs_path,
    theme=gr.themes.Default(
        font_mono=[
            gr.themes.GoogleFont("Inconsolata"),
            "monospace",
        ],
    ),
) as demo:
    gr.Markdown(
"""
# `z*`

<div style="display: flex; gap: 7px;">
 z	
</div>

z
""", elem_classes=["md-custom"], header_links=True)
    app.render()
    gr.Markdown(
"""
## Installation

```bash
pip install 
```

## Usage

```python
z:
```
""", elem_classes=["md-custom"], header_links=True)

r   r   r   z
    demo.load(None, js=r"""r}   z
""")

demo.launch()
)
find
ValueErrorr   r  r   r   r   r   r   r[   )r   r   r   r   r  r   r   r   r  filtered_keysr   r  s               r   
make_spacer  (  s    ?>D>>>M 
		-.."44II122b88J	
 	
 		
 <<{++DF %]D99L
 /	/ /  	!/ /& k=$77'/ /& ;Nd:S:S'/ /& WkkpVqVq'/ /, -/ /< =/ /H I/ /P Q/ /T d:./FGHHU/ /V  'xzCZ6['\'\^fgknx  {I  nJ  _K  _K   L   LW/ / / /Fb Mr   c                   d | D             }d| dt          |||           dt          |           dt          |           d| d| d| d}	t          ||           }
|	|
z  }	|	t	          | d	         d
                   z  }	|	S )Nc                    g | ]
}|d k    |S r  r   r  s     r   r   z!make_markdown.<locals>.<listcomp>  r  r   z
# `z`
r  r   z'

## Installation

```bash
pip install r  r   r   r   )r   r   r   r	  r   )r   r   r   r   r  r   r   r   r  r   r  s              r   make_markdownr    s     ?>D>>>M k=$77 :Md:S:S VjkpVqVq  	      F& .mTBBL
lF
3Z01  F Mr   )r   r   r   r   )rC   r   rD   r   )rC   r   )rL   rM   r   r   r   rN   )rR   rM   rS   rT   r   rN   )N)rR   rM   rS   rT   )r   r\   )rn   ro   )NN)r   r   r}   r   )r   rM   )F)r   rM   r   r   r   r   r   r
  r  r   r   r
  r   r
  r   r  r  r  )/
__future__r   r4   r"   shutilri   ra   
subprocessr   r   r  whichr    r   r   r;   r@   rB   rH   rK   rQ   rX   r[   rd   rm   rw   r   r   	TypedDictr   r   r   r   r   r   r   r   r   r   r   r   r  htmlr  r	  r  r  r   r   r   <module>r"     s   " " " " " "  				    " " " " " " " "lfl6**++   &  &  &  &F  ,             ! ! ! !    * * * *  , , , ,0YA YA YAxA$ A$ A$H    &*    9=044 4 4 4 4n    } } }g g g@ @ @
 
 
 
5 5 5p  1 1 1h  $* * *Z(& & &D" " "\ !&V V V V Vr         r   