
    PiU                        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                  |     e Zd ZdZdZ	 	 d0dddd ej        d          dd	ddddddd
dddd1 fd*Zd+ Zd2d/Z	 xZ
S )3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_selfvalueeveryinputsvariantsizeiconlinklink_target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   -Literal['_self', '_blank', '_parent', '_top']r   bool | Literal['hidden']r    boolr!   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&   r'   	__class__s                      r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/components/login_button.pyr8   zLoginButton.__init__)   s    4 )##%-# 	 	
 	
 	
&  	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)r:   _jss     r<   r9   zLoginButton.activateZ   s{     "))"DJtz$:$:
 

'.$)
,
, 	 	

dD64C
@@@t7>>>>>r=   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)	getattrrM   r   r   gettimepopr)   format)r:   rM   rP   rQ   rR   usernames         r<   rK   zLoginButton._check_login_statuse   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Pr=   )r   r   )$r   r(   r)   r(   r   r*   r   r+   r   r,   r   r-   r   r.   r   r/   r   r0   r   r1   r    r2   r!   r/   r"   r3   r#   r2   r$   r4   r%   r3   r&   r5   r'   r5   )rM   r   rN   r   )__name__
__module____qualname____doc__is_templater	   get_icon_pathr8   r9   rK   __classcell__)r;   s   @r<   r   r      s          K 1)/
 '+JNJW*."5%"56L"M"MEL,0 "/38<3:  $)/ / / / / / / /b	? 	? 	?Q Q Q Q Q Q Q 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);
}
)r^   
__future__r   rF   rW   collections.abcr   pathlibr   typingr   r   gradio_client.documentationr   gradior	   gradio.componentsr
   r   gradio.contextr   gradio.routesr   r   r   rD    r=   r<   <module>rl      s@   G G " " " " " "   $ $ $ $ $ $       ) ) ) ) ) ) ) ) 0 0 0 0 0 0       / / / / / / / / - - - - - - ! ! ! ! ! ! ('''''' 
aQ aQ aQ aQ aQ& aQ aQ aQN   r=   