
    Fg6                        S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
Jr  \" \5      r0 rS rS r/ S	Qr\" S
S9SS j5       rSSS.S jrSS jrS rS rg)zNContains methods that generate documentation for Gradio functions and classes.    )annotationsN)defaultdict)Callable)	lru_cachec                    g)zRA no-op for backwards compatibility of custom components published prior to 4.16.0N )ms    l/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/gradio_client/documentation.pyset_documentation_groupr      s        c                   [         R                  " U R                  5      nUR                  S5       Vs/ s H  o3R	                  5       PM     nnS n[        U5       H?  u  pSUR                  SU-   S-   5      (       d  UR                  SU-   S-   5      (       d  M?    O   Uc  [        SU SU R                   35      eUR                  SU5      nUR                  SUS-   5      n[        US-   U5       HD  nXH   R                  S5      (       d  M  [        S	U SU R                   S
3XH   -   S-   XE   -   5      e   SR                  XFS-   U 5      n	U	$ s  snf )N
zself.:z =zCould not find z in z"""   z-Found another attribute before docstring for : z
 start: )inspect	getsource__init__splitstrip	enumerate
startswith	NameError__name__indexrange
ValueErrorjoin)
clsattrcodelinelinesi
start_lineend_linej
doc_strings
             r
   extract_instance_attr_docr*      s]   S\\*D&*jj&67&6dZZ\&6E7AU#??7T>C/00DOOdNT!5
 5
 	 $
 	y/$tCLL>BCCUA&J{{5*q.1H1q5*%8w''?vT#,,WYZ( (  & %Q:;J) 8s   E))zgradio._simple_templates	component)zgradio.blockblock)zgradio.chatchatinterface)zgradio.componentr+   )zgradio.eventshelpers)zgradio.data_classesr.   )zgradio.exceptionsr.   )zgradio.externalr.   )zgradio.flagflagging)zgradio.helpersr.   )zgradio.interface	interface)zgradio.layoutlayout)zgradio.routeroutes)zgradio.themethemes)gradio_client.z	py-client)zgradio.utilsr.   )zgradio.renderable
renderable
   )maxsizec                r    [          H  u  pU R                  U5      (       d  M  Us  $    [        SU < 35      e)Nz(No known documentation group for module )_module_prefixesr   r   )modnameprefixgroups      r
   _get_module_documentation_groupr=   C   s9    )f%%L * ?{K
LLr   F)inheritdocumentation_groupc                    ^ ^^ UmUUU 4S jnU$ )a  
Defines the @document decorator which adds classes or functions to the Gradio
documentation at www.gradio.app/docs.

Usage examples:
- Put @document() above a class to document the class and its constructor.
- Put @document("fn1", "fn2") above a class to also document methods fn1 and fn2.
- Put @document("*fn3") with an asterisk above a class to document the instance attribute methods f3.
c                  > [        T5      n[        U S5      (       a  XR                  -  nT(       a	  S [        U '   TnTcZ   [        R
                  " U 5      R                  nUR                  S5      (       d  UR                  S5      (       a  [        U5      nO [        U   R                  X45        U $ ! [         a&  n[        R                  " SU  SU 35         S nANFS nAff = f)NEVENTSzgradio.r4   z&Could not get documentation group for r   )listhasattrrB   classes_inherit_documentationr   	getmoduler   r   r=   	Exceptionwarningswarnclasses_to_documentappend)r    	functionsr?   r:   exc_documentation_groupfnsr>   s        r
   	inner_docdocument.<locals>.inner_docW   s    I	3!!#I15)#.2'
U!++C099%%i00G4F4F$5 5 +J'*R'  	/0778HI
  U Fse2cUSTTUs   AB6 6
C& C!!C&r   )r>   r?   rO   rP   rN   s   ` ` @r
   documentrR   K   s     /. r   c                J   [         R                  " U 5      =(       d    SnUR                  S5      n[         R                  " U 5      n/ 0 / / 4u  pVpxSn	U GH  n
U
R	                  5       n
U
S:X  a  Sn	M  U
R                  S5      (       aM  Sn	SU
;   aC  S	U
;   a;  U
R                  S5      S
   R                  S	5      S   nXR                  :w  a  Sn	M{  M}  M  M  U
S:X  a  Sn	M  U	S:X  a*  UR                  U
R                  5       (       a  U
OS5        M  U
R                  S5      (       d  U
R                  5       S:X  d  [        U
5        U
R                  S5      (       d/  U
R                  5       S:X  d  [        SU R                   SU
 35      eU
SS n
U	S:X  aE  U
R                  S5      nUS:  a  [        SU R                   SU
 35      eU
SU nXS-   S nXU'   GM  U	S:X  a  UR                  U
5        GM  U	S:X  d  GM  UR                  U
5        GM     SR                  U5      n/ nUR                  R                  5        GH  u  nnUR                  S5      (       a  M  US:X  a  M'  US;   a  UU;  a  M5  UUR                  UR!                  U5      S.nUU;   a  UU	 UR"                  [         R$                  R&                  :w  ab  UR"                  n[)        U[*        5      (       a  SU-   S-   nUR,                  R.                  S:w  a  UR,                  R                   S3nUUS '   O"US!   b  S"US!   ;   a  S#US"'   S$US!   ;   a  S#US$'   UR                  U5        GM     U(       ab  [1        SU R                   S%S&R                  UR3                  5       5       S'S&R                  UR                  R3                  5       5       35      e[5        U5      S:X  a  0 nO$[5        U5      S
:X  a  UR6                  US   S(.nO0 n[5        U5      S:  a  SR                  U5      OSnUUUU4$ ))ag  
Generates documentation for any function.
Parameters:
    fn: Function to document
Returns:
    description: General description of fn
    parameters: A list of dicts for each parameter, storing data for the parameter name, annotation and doc
    return: A dict storing data for the returned annotation and doc
    example: Code for an example use of the fn
 r   descriptionzParameters:	parameterzExample:example()r   r   ignorezReturns:return<br>    Documentation format for  has format error in line:    Nr      r   _self)kwargsargs)name
annotationdoc"builtinsz()defaultri   re   Trf   z# documents nonexistent parameters: z, z. Valid parameters: )rh   ri   )r   getdocr   	signaturerstripr   r   rK   r   printSyntaxErrorr   r   
parametersitemsrh   getrl   	Parameterempty
isinstancestr	__class__
__module__r   keyslenreturn_annotation)fnr    doc_str	doc_linesrn   rU   rr   returnsexamplesmoder#   ccolon_indexrV   parameter_docdescription_docparameter_docs
param_nameparamrl   return_docsexamples_docs                         r
   document_fnr   q   s    nnR &BGd#I!!"%I13RR.KWD{{}= D__Z((Dd{sd{JJsOA&,,S1!4$#D %  +{ ZD}$""4::<<4VDOOF++tzz|r/AdOOF++tzz|r/A!/}<WX\W]^  8D{""jj.#%3BKK=@[\`[ab  !+.	 $1_%6 7(59%!t$"%G H hh{+ON&11779
E  %%++
*0L**>>*-

 #:&==G--333mmG'3''-#-  ++z9$..778;'.M)$5!-=//*.h'u--(,f%m,5 :6 '} 5''+yy1B'C&D E!!%9+?+?+D+D+F!G HJ
 	

 7|q	W	%.%@%@QRT*-h-!*;499X&LNKEEr   c                (   [         R                  " U 5      nUc  S0 S4$ 0 n/ nSnUR                  S5       GHQ  nUR                  5       nUR	                  S5      (       a  SU;  a  US S R                  5       n/ X$'   MI  UR                  S5      S   R	                  S5      (       aT  UR                  S5      (       d>  US UR                  S5       R                  5       nXUR                  S5      S	-   S  nXrU'   M  US:X  a*  UR                  UR                  5       (       a  UOS
5        M  UR                  S5      (       d0  UR                  5       (       a  [        SU R                   SU 35      eX$   R                  USS  5        GMT     SU;   a  SR                  US   5      nUS	 OS nUR                  5        H/  u  p[        U
[        5      (       d  M  S
R                  U
5      X)'   M1     SR                  U5      R!                  SS
5      nXU4$ )NrT   rU   r   r   r   ra   r   r]   rb   r\   r^   r_   r`   rW   )r   rm   r   ro   endswithlowerr   r   rK   r   rq   r   r   rs   rw   rC   replace)r    r   tagsdescription_linesr   r#   tagvaluerW   keyvalrU   s               r
   document_clsr      s   nnS!G2rzDDd#{{}==#T/9??$DDJZZ_Q((--doof6M6M(C)//1CC1,./EI]"$$TZZ\\TvFOOF++4::<<!/~=XY]X^_  Jd12h'! $" D))DO,OJJLc4  C(DI ! ((,-55dFCKg%%r   c                     0 n [         R                  5        GH  u  p/ X'   U GHw  u  p4[        R                  " U5      (       d  [        R
                  " U5      (       a  UOUR                  n[        XS5      u  pgp[        US5      (       a  [        UR                  5      (       al  [        US5      (       a[  [        UR                  5      (       aA  [        UR                  U5      n	[        UR                  U5      n
U	S   U	S   S.U
S   U
S   S.p[        U5      u  pnUUR                  UUUUU/ S.n[        US5      (       aO  [        UR                  5      (       a5  [        US5      (       a$  [        UR                  5      (       a
  W	US'   W
US'   U H  nUR                  S5      nU(       a!  USS  n[        U" 5       U5      R                   nO[        X?5      n[        U5      (       d$  [#        U5      n0 n0 nSnS	UR                   S
U 3nO)[        UU5      u  nnnnU[        US/ 5      ;   a  USS  nS nU(       a  [%        X?5      nUS   R'                  UUU0 UUUUS.5        M     X   R'                  U5        U[(        ;   d  GMk  US   [(        U'   GMz     GM     [         R                  5        H  u  p[+        U5       H  u  nu  p6[(        R                  5        H~  u  nn[        R,                  " U5      (       d  M#  [/        UU5      (       d  M6  UU:w  d  M>  U H:  n[1        U5      n [%        UUS   5      US'   X   U   S   R'                  U5        M<     M     M     M     U $ ! [2         a     N7f = f)N
preprocesspostprocessr   rb   )r   
return_doc)classrg   rU   r   rr   r   rW   rO   *rT   zgr..rB   rO   )r~   rg   rU   r   rr   r   rW   override_signaturerg   rU   )rJ   rs   r   
isfunctiondataclassesis_dataclassr   r   rD   callabler   r   r   r   r   getattr__call__rx   r*   rK   rE   r   isclass
issubclassdictr   )documentationr   
class_listr    rO   fn_to_documentrc   r   r   preprocess_docpostprocess_doccls_descriptioncls_tagscls_examplecls_documentationfn_nameinstance_attribute_fnr~   r   r   r   r   r   r%   super_classinherited_fns                             r
   generate_documentationr      s   M/557 "HC %%c**k.F.Fs.K.K \\ 
 /:..N+Aj\**S^^,,C//S__--!,S^^S!A"-coos"C *8):&4Q&7
 *9);&5a&8 !0 6B#5F2O{. +%&	! \**S^^,,C//S__--2@!,/3B!-0(/(:(:3(?%(%abkG !099B .B||&)"gO%'N"$K#%L+.s||nAgY)G& $B,'&#$'#x"<<)7);)-&(&?&MO!%(//  ''6 "&4#.#/.@	7 N &&'89335Fu5M-c2k # 8p 0557$Z0KAx$A$G$G$I SOOC(("344{*(+'+L'9!:S #\&%9;L7
 &+A.u5<<\J ), %J 1 8"   * ! !s   3M00
M=<M=)r[   rx   )r~   r   r[   z(tuple[str, list[dict], dict, str | None])__doc__
__future__r   r   r   rH   collectionsr   collections.abcr   	functoolsr   rC   rJ   rE   r   r*   r9   r=   rR   r   r   r   r   r   r
   <module>r      s|    T "    # $ !$'  " 	
2 * 2M M !d #L_FD!&Hkr   