Felladrin commited on
Commit
5a87d26
·
1 Parent(s): 8fbbd7f

Fix the fallback logic for getting the `SPACE_AUTHOR_NAME` when `user_hf_token` is not set

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import logging
2
  import subprocess
 
3
  import sys
4
  from dataclasses import dataclass
5
  from pathlib import Path
@@ -30,12 +31,13 @@ class Config:
30
  def from_env(cls) -> "Config":
31
  """Create config from environment variables and secrets."""
32
  system_token = st.secrets.get("HF_TOKEN")
33
- user_token = st.session_state.get("user_hf_token", "")
34
- hf_username = (
35
- whoami(token=user_token)["name"]
36
- or st.secrets.get("SPACE_AUTHOR_NAME")
37
- or whoami(token=system_token)["name"]
38
- )
 
39
  hf_token = user_token or system_token
40
 
41
  if not hf_token:
 
1
  import logging
2
  import subprocess
3
+ import os
4
  import sys
5
  from dataclasses import dataclass
6
  from pathlib import Path
 
31
  def from_env(cls) -> "Config":
32
  """Create config from environment variables and secrets."""
33
  system_token = st.secrets.get("HF_TOKEN")
34
+ user_token = st.session_state.get("user_hf_token")
35
+ if user_token:
36
+ hf_username = whoami(token=user_token)["name"]
37
+ else:
38
+ hf_username = (
39
+ os.getenv("SPACE_AUTHOR_NAME") or whoami(token=system_token)["name"]
40
+ )
41
  hf_token = user_token or system_token
42
 
43
  if not hf_token: