
    Fg                          S r SSKJr  SSKrSSKrSSKJrJr  SSKJ	r	  SSK
JrJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  \(       a  SSKJr   " S S\5      r " S S\5      r\" 5        " S S\5      5       rg)zgr.Label() component.    )annotationsN)CallableSequence)Path)TYPE_CHECKINGAnyOptionalUnion)document)	Component)GradioModel)Events)Timerc                  2    \ rS rSr% SrS\S'   SrS\S'   Srg)LabelConfidence   N Optional[Union[str, int, float]]labelzOptional[float]
confidence )__name__
__module____qualname____firstlineno__r   __annotations__r   __static_attributes__r       h/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/gradio/components/label.pyr   r      s    .2E+2"&J&r   r   c                  2    \ rS rSr% SrS\S'   SrS\S'   Srg)	LabelData   Nr   r   zOptional[list[LabelConfidence]]confidencesr   )r   r   r   r   r   r   r"   r   r   r   r   r    r       s    .2E+237K07r   r    c                    ^  \ rS rSrSrSr\r\R                  \R                  /r SSSSSSSSSSSSSSSSS.                               SU 4S jjjjr    SS	 jr    SS
 jrSS jrSS jrSrU =r$ )Label   a2  
Displays a classification label, along with confidence scores of top categories, if provided. As this component does not
accept user input, it is rarely used as an input component.

Guides: image-classification-in-pytorch, image-classification-in-tensorflow, image-classification-with-vision-transformers
r"   NT   )num_top_classesr   everyinputs
show_label	containerscale	min_widthvisibleelem_idelem_classesrenderkeycolorshow_headingc               ^   > X l         Xl        UU l        [        TU ]  UUUUUUU	U
UUUUUS9  g)a
  
Parameters:
    value: Default value to show in the component. If a str or number is provided, simply displays the string or number. If a {Dict[str, float]} of classes and confidences is provided, displays the top class on top and the `num_top_classes` below, along with their confidence bars. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
    num_top_classes: number of most confident classes to show.
    label: the label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
    every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
    inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
    show_label: if True, will display label.
    container: If True, will place the component in a container - providing some extra padding around the border.
    scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
    min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
    visible: If False, component will be hidden.
    elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
    elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
    render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
    key: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.
    color: The background color of the label (either a valid css color name or hexadecimal string).
    show_heading: If False, the heading will not be displayed if a dictionary of labels and confidences is provided. The heading will still be visible if the value is a string or number.
)r   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   valueN)r'   r3   r4   super__init__)selfr6   r'   r   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   	__class__s                    r   r8   Label.__init__,   sR    N  /
(!% 	 	
r   c                    Uc  gUR                   c  UR                  $ UR                  5       S    Vs0 s H  o"S   US   _M     sn$ s  snf )z
Parameters:
    payload: An instance of `LabelData` containing the label and confidences.
Returns:
    Depending on the value, passes the label as a `str | int | float`, or the labels and confidences as a `dict[str, float]`.
Nr"   r   r   )r"   r   
model_dump)r9   payloadds      r   
preprocessLabel.preprocessf   s]     ?&== 181C1C1Em1T
1TAgJ,'1T
 	
 
s   Ac                L   Ub  U0 :X  a  0 $ [        U[        5      (       aj  UR                  S5      (       aT  [        U5      R	                  5       (       a6  [        S0 [        R                  " [        U5      R                  5       5      D6$ [        U[        [        [        45      (       a  [        [        U5      S9$ [        U[        5      (       a  SU;   a5  [        US   [        5      (       a  US   nU Vs0 s H  o"S   US   _M     nn[        UR                  5       [        R                  " S5      SS	9nU R                   b  USU R                    n[        US
   S
   U Vs/ s H  n[#        US
   US   S9PM     snS9$ [%        S['        U5       35      es  snf s  snf )a  
Parameters:
    value: Expects a `dict[str, float]` of classes and confidences, or `str` with just the class or an `int | float` for regression outputs, or a `str` path to a .json file containing a json dictionary in one of the preceding formats.
Returns:
    Returns a `LabelData` object with the label and confidences, or a `dict` of the same format, or a `str` or `int` or `float` if the input was a single label.
Nz.json)r   r"   r   r      T)r2   reverser   r   r   r   r"   zThe `Label` output interface expects one of: a string label, or an int label, a float label, or a dictionary whose keys are labels and values are confidences. Instead, got a r   )
isinstancestrendswithr   existsr    jsonloads	read_textfloatintdictsorteditemsoperator
itemgetterr'   r   
ValueErrortype)r9   r6   csorted_predpreds        r   postprocessLabel.postprocessw   s    =ERKIeS!!ennW&=&=$u+BTBTBVBVCtzz$u+*?*?*ABCCec5#.//3u:..eT""%*U=5I4*P*Pm,>CDe7Q|_4eD 8#6#6q#94K ##/)*@D,@,@A!!nQ' !, + $$q'd1gF +  "5k],
 	
 Es   9F&F!
c                    SSSS.SSS./S.$ )NCatcat?rE   dog皙?rF   r   r9   s    r   example_payloadLabel.example_payload   s$    s3s3
 	
r   c                    SSS.$ )Nr_   ra   )r^   r`   r   rb   s    r   example_valueLabel.example_value   s    3''r   )r3   r'   r4   )N) r6   z0dict[str, float] | str | float | Callable | Noner'   
int | Noner   
str | Noner(   zTimer | float | Noner)   z7Component | Sequence[Component] | set[Component] | Noner*   zbool | Noner+   boolr,   rh   r-   rO   r.   rj   r/   ri   r0   zlist[str] | str | Noner1   rj   r2   zint | str | Noner3   ri   r4   rj   )r>   zLabelData | Nonereturnz+dict[str, float] | str | int | float | None)r6   z3dict[str | float, float] | str | int | float | Nonerk   zLabelData | dict | None)rk   r   )r   r   r   r   __doc__CONFIDENCES_KEYr    
data_modelr   changeselectEVENTSr8   r@   rZ   rc   rf   r   __classcell__)r:   s   @r   r$   r$      sE    $OJmmV]]+F CG8
 '+ &*JN"& "/3 $ !%8
?8
 $	8

 8
 $8
 H8
  8
 8
 8
 8
 8
 8
 -8
 8
  !8
" #8
$ %8
 8
t
'
	4
"#
H#
	 #
J
( (r   r$   )rl   
__future__r   rK   rS   collections.abcr   r   pathlibr   typingr   r   r	   r
   gradio_client.documentationr   gradio.components.baser   gradio.data_classesr   gradio.eventsr   gradio.componentsr   r   r    r$   r   r   r   <module>r|      sg     "   .  6 6 0 , +  ''k '
8 8
 
F(I F( F(r   