
    8P[iU                        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		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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
    TN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_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$   r%   	__class__s                      l/var/www/html/chatbot/Makanify-Chatbot-2/venv/lib/python3.12/site-packages/gradio/components/login_button.pyr)   zLoginButton.__init__)   sh    4 )##%-# 	 	
& 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.activateZ   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+   rE   r?   r@   rA   usernames         r-   r<   zLoginButton._check_login_statuse   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'   rK   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   z-Literal['_self', '_blank', '_parent', '_top']r   zbool | Literal['hidden']r   boolr   rL   r    list[str] | str | Noner!   rM   r"   z(int | str | tuple[int | str, ...] | Noner#   rN   r$   
int | Noner%   rO   )rE   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EL,0 "/38<3:  $)// /
 $/ H/ H/ (/  / / C/ */ / / -/  !/" 6#/$ 1%/& '/( )/b	?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);
}
)rT   
__future__r   r7   rG   collections.abcr   pathlibr   typingr   r   gradio_client.documentationr   gradior	   gradio.componentsr
   r   gradio.contextr   gradio.routesr   r   r   r5    r.   r-   <module>rb      s[    G "   $  ) 0  / - !' 
aQ& aQ aQN r.   