@@ -168,18 +168,11 @@ def run(self):
168168 _| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|
169169
170170 To login, `huggingface_hub` now requires a token generated from https://huggingface.co/settings/tokens .
171- (Deprecated, will be removed in v0.3.0) To login with username and password instead, interrupt with Ctrl+C.
172171 """
173172 )
174173
175- try :
176- token = getpass ("Token: " )
177- _login (self ._api , token = token )
178-
179- except KeyboardInterrupt :
180- username = input ("\r Username: " )
181- password = getpass ()
182- _login (self ._api , username , password )
174+ token = getpass ("Token: " )
175+ _login (self ._api , token = token )
183176
184177
185178class WhoamiCommand (BaseUserCommand ):
@@ -208,12 +201,6 @@ def run(self):
208201 exit ()
209202 HfFolder .delete_token ()
210203 HfApi .unset_access_token ()
211- try :
212- self ._api .logout (token )
213- except HTTPError as e :
214- # Logging out with an access token will return a client error.
215- if not e .response .status_code == 400 :
216- raise e
217204 print ("Successfully logged out." )
218205
219206
@@ -304,9 +291,7 @@ def run(self):
304291NOTEBOOK_LOGIN_TOKEN_HTML_END = """
305292<b>Pro Tip:</b> If you don't already have one, you can create a dedicated
306293'notebooks' token with 'write' access, that you can then easily reuse for all
307- notebooks. <br> <i>Logging in with your username and password is deprecated and
308- won't be possible anymore in the near future. You can still use them for now by
309- clicking below.</i> </center>"""
294+ notebooks. </center>"""
310295
311296
312297def notebook_login ():
@@ -328,34 +313,18 @@ def notebook_login():
328313
329314 token_widget = widgets .Password (description = "Token:" )
330315 token_finish_button = widgets .Button (description = "Login" )
331- switch_button = widgets .Button (description = "Use password" )
332316
333317 login_token_widget = widgets .VBox (
334318 [
335319 widgets .HTML (NOTEBOOK_LOGIN_TOKEN_HTML_START ),
336320 token_widget ,
337321 token_finish_button ,
338322 widgets .HTML (NOTEBOOK_LOGIN_TOKEN_HTML_END ),
339- switch_button ,
340323 ],
341324 layout = box_layout ,
342325 )
343326 display (login_token_widget )
344327
345- # Deprecated page for login
346- input_widget = widgets .Text (description = "Username:" )
347- password_widget = widgets .Password (description = "Password:" )
348- password_finish_button = widgets .Button (description = "Login" )
349-
350- login_password_widget = widgets .VBox (
351- [
352- widgets .HTML (value = NOTEBOOK_LOGIN_PASSWORD_HTML ),
353- widgets .HBox ([input_widget , password_widget ]),
354- password_finish_button ,
355- ],
356- layout = box_layout ,
357- )
358-
359328 # On click events
360329 def login_token_event (t ):
361330 token = token_widget .value
@@ -366,35 +335,9 @@ def login_token_event(t):
366335
367336 token_finish_button .on_click (login_token_event )
368337
369- def login_password_event (t ):
370- username = input_widget .value
371- password = password_widget .value
372- # Erase password and clear value to make sure it's not saved in the notebook.
373- password_widget .value = ""
374- clear_output ()
375- _login (HfApi (), username = username , password = password )
376-
377- password_finish_button .on_click (login_password_event )
378-
379- def switch_event (t ):
380- clear_output ()
381- display (login_password_widget )
382-
383- switch_button .on_click (switch_event )
384-
385-
386- def _login (hf_api , username = None , password = None , token = None ):
387- if token is None :
388- try :
389- token = hf_api .login (username , password )
390- except HTTPError as e :
391- # probably invalid credentials, display error message.
392- print (e )
393- print (ANSI .red (e .response .text ))
394- exit (1 )
395- else :
396- token , name = hf_api ._validate_or_retrieve_token (token )
397338
339+ def _login (hf_api , token = None ):
340+ token , name = hf_api ._validate_or_retrieve_token (token )
398341 hf_api .set_access_token (token )
399342 HfFolder .save_token (token )
400343 print ("Login successful" )
0 commit comments