Skip to content

Commit

Permalink
Fix the configure script crash when no TTY is allocated (e.g. a conta…
Browse files Browse the repository at this point in the history
…iner) (#2080)

* (config) avoid failure when huggingface token is not set

it is not required for model download, and we are handling the
saving of the token during huggingface authentication phase elsewhere.

* (config) safely print to non-tty terminals where width can not be determined
  • Loading branch information
ebr committed Dec 20, 2022
1 parent 1ba40db commit ab2972f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions scripts/configure_invokeai.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def HfLogin(access_token) -> str:
#-------------------------------Authenticate against Hugging Face
def authenticate(yes_to_all=False):
print('** LICENSE AGREEMENT FOR WEIGHT FILES **')
print("=" * os.get_terminal_size()[0])
print("=" * shutil.get_terminal_size()[0])
print('''
By downloading the Stable Diffusion weight files from the official Hugging Face
repository, you agree to have read and accepted the CreativeML Responsible AI License.
Expand All @@ -221,7 +221,7 @@ def authenticate(yes_to_all=False):
https://huggingface.co/spaces/CompVis/stable-diffusion-license
''')
print("=" * os.get_terminal_size()[0])
print("=" * shutil.get_terminal_size()[0])

if not yes_to_all:
accepted = False
Expand All @@ -237,7 +237,7 @@ def authenticate(yes_to_all=False):
# Authenticate to Huggingface using environment variables.
# If successful, authentication will persist for either interactive or non-interactive use.
# Default env var expected by HuggingFace is HUGGING_FACE_HUB_TOKEN.
print("=" * os.get_terminal_size()[0])
print("=" * shutil.get_terminal_size()[0])
print('Authenticating to Huggingface')
hf_envvars = [ "HUGGING_FACE_HUB_TOKEN", "HUGGINGFACE_TOKEN" ]
if not (access_token := HfFolder.get_token()):
Expand Down Expand Up @@ -294,7 +294,7 @@ def authenticate(yes_to_all=False):
print()
print(f"Re-run the configuration script without '--yes' to set the HuggingFace token interactively, or use one of the environment variables: {', '.join(hf_envvars)}")

print("=" * os.get_terminal_size()[0])
print("=" * shutil.get_terminal_size()[0])

return access_token

Expand Down Expand Up @@ -330,13 +330,10 @@ def download_weight_datasets(models:dict, access_token:str):
successful[mod] = True
if len(successful) < len(models):
print(f'\n\n** There were errors downloading one or more files. **')
print('Please double-check your license agreements, and your access token.')
HfFolder.delete_token()
print('Press any key to try again. Type ^C to quit.\n')
input()
return None

HfFolder.save_token(access_token)
keys = ', '.join(successful.keys())
print(f'Successfully installed {keys}')
return successful
Expand Down

0 comments on commit ab2972f

Please sign in to comment.