
    wi                        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dS )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                  z     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 )/LoginButtona  
    Creates a "Sign In" button that redirects the user to sign in with Hugging Face OAuth.
    Once the user is signed in, the button will act as a logout button, and you can
    retrieve a signed-in user's profile by adding a parameter of type `gr.OAuthProfile`
    to any Gradio function. This will only work if this Gradio app is running in a
    Hugging Face Space. Permissions for the OAuth app can be configured in the Spaces
    README file, as described here: https://huggingface.co/docs/hub/en/spaces-oauth.
    For local development, instead of OAuth, the local Hugging Face account that is
    logged in (via `hf auth login`) will be available through the `gr.OAuthProfile`
    object.

    Demos: login_with_huggingface
    Guides: sharing-your-app
    TSign in with Hugging FaceLogout ({})N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_widthstrlogout_valuer   Timer | float | Noner   7Component | Sequence[Component] | set[Component] | Noner   6Literal['primary', 'secondary', 'stop', 'huggingface']r   Literal['sm', 'md', 'lg']r   str | Path | Noner   
str | Noner   boolr   r   r    list[str] | str | Noner!   r"   (int | str | tuple[int | str, ...] | Noner#   r$   
int | Noner%   c                   || _         t                                          ||||||||	|
|||||||           t                      r|                                  dS dS )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)r'   super__init__r   activate)selfr   r'   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   	__class__s                     n/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/gradio/components/login_button.pyr4   zLoginButton.__init__)   s    2 )#%-! 	 	
 	
 	
$  	MMOOOOO	 	    c                   t                               dt          j        | j                                                d| j                  }|                     d | gd |           |                     | j        d            d S )NBUTTON_DEFAULT_VALUEREDIRECT_URL)fnr   outputsjs)	_js_handle_redirectreplacejsondumpsr   pageclickattach_load_event_check_login_status)r6   _jss     r8   r5   zLoginButton.activateX   s{     "))"DJtz$:$:
 

'.$)
,
, 	 	

dD64C
@@@t7>>>>>r9   requestr   returnc                   t          |dd           pt          |j        dd           }|d|vrt          | j        d          S |d         }|                    d          }|C|t          j                    k     r,|                    dd            t          | j        d          S |d         d         }t          | j                            |          d          S )Nsession
oauth_infoT)r   
expires_atuserinfopreferred_username)	getattrrI   r   r   gettimepopr'   format)r6   rI   rL   rM   rN   usernames         r8   rG   zLoginButton._check_login_statusc   s    '9d33 
wOY8
 8
 ?l'99tzt<<<<\*
^^L11
!j49;;&>&>KKd+++tzt<<<< j)*>?4,33H==4PPPPr9   )r   r   )"r   r&   r'   r&   r   r(   r   r)   r   r*   r   r+   r   r,   r   r-   r   r.   r   r.   r   r-   r    r/   r!   r.   r"   r0   r#   r/   r$   r1   r%   r1   )rI   r   rJ   r   )__name__
__module____qualname____doc__is_templater	   get_icon_pathr4   r5   rG   __classcell__)r7   s   @r8   r   r      s          K 1)-
 '+JNJW*."5%"56L"M"M "/38<3:  $'- - - - - - - -^	? 	? 	?Q Q Q Q Q Q Q Qr9   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);
}
)rZ   
__future__r   rB   rS   collections.abcr   pathlibr   typingr   r   gradio_client.documentationr   gradior	   gradio.componentsr
   r   gradio.contextr   gradio.routesr   r   r   r@    r9   r8   <module>rh      s@   G G " " " " " "   $ $ $ $ $ $       ) ) ) ) ) ) ) ) 0 0 0 0 0 0       / / / / / / / / - - - - - - ! ! ! ! ! ! ('''''' 
_Q _Q _Q _Q _Q& _Q _Q _QJ   r9   