
    ;3h6                        d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ  ee      Zi Zd Zd Zg d	Z ed
      dd       ZddddZddZd Zd Zy)zNContains methods that generate documentation for Gradio functions and classes.    )annotationsN)defaultdict)Callable)	lru_cachec                     y)zRA no-op for backwards compatibility of custom components published prior to 4.16.0N )ms    [/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio_client/documentation.pyset_documentation_groupr      s        c                   t        j                  | j                        }|j                  d      D cg c]  }|j	                          }}d }t        |      D ]5  \  }}|j                  d|z   dz         s|j                  d|z   dz         s5 n |t        d| d| j                         |j                  d|      }|j                  d|dz         }t        |dz   |      D ]A  }||   j                  d      st        d	| d| j                   d
||   z   dz   ||   z          dj                  ||dz   |       }	|	S c c}w )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*      se   S\\*D&*jj&67dTZZ\7E7AU# 4??7T>C/0DOOdNT!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                d    t         D ]  \  }}| j                  |      s|c S  t        d|       )Nz(No known documentation group for module )_module_prefixesr   r   )modnameprefixgroups      r
   _get_module_documentation_groupr=   C   s=    ) f%L ?{K
LLr   F)inheritdocumentation_groupc                     | fd}|S )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              }t        | d      r|| j                  z  }r	d t        | <   }O	 t	        j
                  |       j                  }|j                  d      s|j                  d      rt        |      }n	 t        |   j                  | |f       | S # t        $ r%}t        j                  d|  d|        Y d }~Ed }~ww xY w)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_doczdocument.<locals>.inner_docW   s    I	3!#I15)#.2'
U!++C099%%i0G4F4F$5 +J'*R'  	/077i8HI
  U Fse2cUSTTUs   AB" "	C+CCr   )r>   r?   rO   rP   rN   s   ` ` @r
   documentrQ   K   s     /. r   c                   t        j                  |       xs d}|j                  d      }t        j                  |       }g i g g f\  }}}}d}	|D ]  }
|
j	                         }
|
dk(  rd}	|
j                  d      rEd}	d|
v s4d	|
v s9|
j                  d      d
   j                  d	      d   }||j                  k7  sod}	r|
dk(  rd}	z|	dk(  r$|j                  |
j                         r|
nd       |
j                  d      s|
j                         dk(  st        |
       |
j                  d      s.|
j                         dk(  st        d| j                   d|
       |
dd }
|	dk(  rE|
j                  d      }|dk  rt        d| j                   d|
       |
d| }|
|dz   d }|||<   `|	dk(  r|j                  |
       x|	dk(  s|j                  |
        dj                  |      }g }|j                  j                         D ]  \  }}|j                  d      r|dk(  r|dv r||vr'||j                  |j!                  |      d}||v r||= |j"                  t         j$                  j&                  k7  r\|j"                  }t)        |t*              rd|z   dz   }|j,                  j.                  dk7  r|j,                  j                   d}||d <   n|d!   d"|d!   v rd#|d"<   d$|d!   v rd#|d$<   |j                  |        |rbt1        d| j                   d%d&j                  |j3                                d'd&j                  |j                  j3                                      t5        |      dk(  ri }n#t5        |      d
k(  r|j6                  |d   d(}ni }t5        |      dkD  rdj                  |      nd}||||fS ))a  
    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()defaultrh   rd   Tre   z# documents nonexistent parameters: z, z. Valid parameters: )rg   rh   )r   getdocr   	signaturerstripr   r   rK   r   printSyntaxErrorr   r   
parametersitemsrg   getrk   	Parameterempty
isinstancestr	__class__
__module__r   keyslenreturn_annotation)fnr    doc_str	doc_linesrm   rT   rq   returnsexamplesmoder#   ccolon_indexrU   parameter_docdescription_docparameter_docs
param_nameparamrk   return_docsexamples_docs                         r
   document_fnr   q   s    nnR &BGd#I!!"%I13RR.KWh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(5
9%!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                   t        j                  |       }|di dfS i }g }d}|j                  d      D ]0  }|j                         }|j	                  d      rd|vr|d d j                         }g ||<   B|j                  d      d   j	                  d      rP|j                  d      s?|d |j                  d       j                         }||j                  d      d	z   d  }|||<   |dk(  r$|j                  |j                         r|nd
       |j                  d      s+|j                         rt        d| j                   d|       ||   j                  |dd         3 d|v rdj                  |d         }|d= nd }|j                         D ]*  \  }	}
t        |
t              sd
j                  |
      ||	<   , dj                  |      j!                  dd
      }|||fS )NrS   rT   r   r   r   r`   r   r\   ra   r[   r]   r^   r_   rV   )r   rl   r   rn   endswithlowerr   r   rK   r   rp   r   r   rr   rv   rC   replace)r    r~   tagsdescription_linesr   r#   tagvaluerV   keyvalrT   s               r
   document_clsr      s   nnS!G2rzDDd# ({{}==#T/9??$DDJZZ_Q((-doof6M(C)//1CC1,./EDI]"$$TZZ\TvFOOF+4::<!/~=XY]X^_  Jd12h'!(" D))DO,OJJL )Sc4 C(DI) ((,-55dFCKg%%r   c                 P   i } t         j                         D ]F  \  }}g | |<   |D ]5  \  }}t        j                  |      st	        j
                  |      r|n|j                  }t        ||      \  }}}}t        |d      rxt        |j                        rct        |d      rWt        |j                        rBt        |j                  |      }	t        |j                  |      }
|	d   |	d   d|
d   |
d   d}
}	t        |      \  }}}||j                  |||||g d}t        |d      r@t        |j                        r+t        |d      rt        |j                        r
	|d<   
|d<   |D ]  }|j                  d      }|r!|dd  }t         |       |      j                   }nt        ||      }t        |      s$t#        |      }i }i }d}d	|j                   d
| }n't        ||      \  }}}}|t        |dg       v r|dd  }d }|rt%        ||      }|d   j'                  |||i ||||d        | |   j'                  |       |t(        v s*|d   t(        |<   8 I t         j                         D ]  \  }}t+        |      D ]  \  }\  }}t(        j                         D ]m  \  }}t        j,                  |      st/        ||      s)||k7  s/|D ]:  }t1        |      }	 t%        ||d         |d<   | |   |   d   j'                  |       < o   | S # t2        $ r Y /w xY w)N
preprocesspostprocessr   ra   )r   
return_doc)classrf   rT   r   rq   r   rV   rO   *rS   zgr..rB   rO   )r}   rf   rT   r   rq   r   rV   override_signaturerf   rT   )rJ   rr   r   
isfunctiondataclassesis_dataclassr   r   rD   callabler   r   r   r   r   getattr__call__rw   r*   rK   rE   r   isclass
issubclassdictr   )documentationr   
class_listr    rO   fn_to_documentrb   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 WNj d" U	NHC %%c*k.F.Fs.K \\ 
 /:.#.N+A}j!\*S^^,C/S__-!,S^^S!A"-coos"C *8):&4Q&7
 *9);&5a&8 !0 6B#5F2OX{. +%&	! \*S^^,C/S__-2@!,/3B!-0 &(/(:(:3(?%(%abkG !099B g.B|&)"gO%'N"$K#%L+.s||nAgY)G& $B,'&#$'#x"<<)7);)-&(&?W&MO!%(//  ''6 "&4#.#/.@	7&N $&&'89335Fu5M-c2kU	NWNp 0557 Kj$Z0 	KKAxQ$A$G$G$I K SOOC("34{*(+ K'+L'9!:S #\&%9;L7
 &d+A.u5<<\JKK	KK"   * ! !s   #L	L%$L%)rZ   rw   )r}   r   rZ   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=   rQ   r   r   r   r   r   r
   <module>r      s|    T "    # $ !$'  " 	
2 * 2M M !d #L_FD!&Hkr   