
    !kh                        d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ e
rddlmZ  e        G d de             ZdZy)zAPredefined button to sign in with Hugging Face in a Gradio Space.    )annotationsN)Sequence)Path)TYPE_CHECKINGLiteral)document)utils)Button	Component)get_blocks_context)Request)Timerc                       e Zd ZdZdZ	 	 ddddd ej                  d      ddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Zd
 ZddZ	 xZ
S )LoginButtonaN  
    Creates a button that redirects the user to Sign with Hugging Face using OAuth. If
    created inside of a Blocks context, it will add an event to check if the user is logged in
    and update the button text accordingly. If created outside of a Blocks context, call the
    `LoginButton.activate()` method to add the event.
    TNhuggingfacelgzhuggingface-logo.svgvalueeveryinputsvariantsizeiconlinkvisibleinteractiveelem_idelem_classesrenderkeypreserved_by_keyscale	min_widthc                   || _         t        | 	  ||||||||	|
|||||||       t               r| j	                          yy)z
        Parameters:
            logout_value: The text to display when the user is signed in. The string should contain a placeholder for the username with a call-to-action to logout, e.g. "Logout ({})".
        r   N)logout_valuesuper__init__r   activate)selfr   r%   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   	__class__s                     Z/opt/mcp/mcp-sentiment/venv/lib/python3.12/site-packages/gradio/components/login_button.pyr'   zLoginButton.__init__!   se    2 )#%-! 	 	
$ MMO      c                   t         j                  dt        j                  | j                              j                  d| j
                        }| j                  d | gd |       | j                  | j                  d        y )NBUTTON_DEFAULT_VALUEREDIRECT_URL)fnr   outputsjs)	_js_handle_redirectreplacejsondumpsr   pageclickattach_load_event_check_login_status)r)   _jss     r+   r(   zLoginButton.activateP   sg     "))"DJJtzz$:

'.$))
, 	 	

dD64C
@t77>r,   c                   t        |dd       xs t        |j                  dd       }|d|vrt        | j                  d      S |d   }|j	                  d      }|@|t        j
                         k  r)|j                  dd        t        | j                  d      S |d   d   }t        | j                  j                  |      d      S )Nsession
oauth_infoT)r   
expires_atuserinfopreferred_username)	getattrrequestr   r   gettimepopr%   format)r)   rC   r=   r>   r?   usernames         r+   r:   zLoginButton._check_login_status[   s    '9d3 
wOOY8
 ?l'9tzzt<<\*
^^L1
!j499;&>KKd+tzzt<< j)*>?4,,33H=4PPr,   )zSign in with Hugging FacezLogout ({}))"r   strr%   rI   r   zTimer | float | Noner   z7Component | Sequence[Component] | set[Component] | Noner   z6Literal['primary', 'secondary', 'stop', 'huggingface']r   zLiteral['sm', 'md', 'lg']r   zstr | Path | Noner   
str | Noner   boolr   rK   r   rJ   r   list[str] | str | Noner   rK   r    z(int | str | tuple[int | str, ...] | Noner!   rL   r"   
int | Noner#   rM   )rC   r   returnr   )__name__
__module____qualname____doc__is_templater	   get_icon_pathr'   r(   r:   __classcell__)r*   s   @r+   r   r      s    K 1)-
 '+JNJW*."5%"5"56L"M "/38<3:  $'-- -
 $- H- H- (-  - - - - - -- -  6!-" 1#-$ %-& '-^	?Qr,   r   aN  
(buttonValue) => {
    uri = buttonValue === BUTTON_DEFAULT_VALUE ? '/login/huggingface?_target_url=/REDIRECT_URL' : '/logout?_target_url=/REDIRECT_URL';
    window.parent?.postMessage({ type: "SET_SCROLLING", enabled: true }, "*");
    setTimeout(() => {
        window.location.assign(uri + window.location.search);
    }, 500);
}
)rR   
__future__r   r5   rE   collections.abcr   pathlibr   typingr   r   gradio_client.documentationr   gradior	   gradio.componentsr
   r   gradio.contextr   gradio.routesr   r   r   r3    r,   r+   <module>r`      s[    G "   $  ) 0  / - !' 
WQ& WQ WQz r,   