
    +j                        d Z ddlm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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)oauth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                      b/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/gradio/components/login_button.pyr9   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=   r:   zLoginButton.activateY   s{     "))"DJtz$:$:
 

'.$)
,
, 	 	

dD64C
@@@t7>>>>>r>   requestr   returnc                F   t          |dd           pt          |j        dd           }|t          | j        d          S t	          j        |          }|t          | j        d          S |d         d         }t          | j                            |          d          S )NsessionT)r!   userinfopreferred_username)getattrrN   r   r   r	   "_get_valid_oauth_info_from_sessionr*   format)r;   rN   rQ   
oauth_infousernames        r=   rL   zLoginButton._check_login_statusd   s    '9d33 
wOY8
 8
 ?tzt<<<<=gFF
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   r0   r   r1   r    r2   r!   r3   r"   r0   r#   r4   r$   r3   r%   r5   r&   r4   r'   r6   r(   r6   )rN   r   rO   r   )__name__
__module____qualname____doc__is_templater
   get_icon_pathr9   r:   rL   __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   rG   collections.abcr   pathlibr   typingr   r   gradio_client.documentationr   gradior	   r
   gradio.componentsr   r   gradio.contextr   gradio.routesr   r   r   rE    r>   r=   <module>rj      s=   G G " " " " " "  $ $ $ $ $ $       ) ) ) ) ) ) ) ) 0 0 0 0 0 0         / / / / / / / / - - - - - - ! ! ! ! ! ! ('''''' 
_Q _Q _Q _Q _Q& _Q _Q _QJ   r>   