Remove dependency on system variables
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import logging
|
2 |
-
import os
|
3 |
import subprocess
|
4 |
import sys
|
5 |
from dataclasses import dataclass
|
@@ -8,7 +7,7 @@ from typing import Optional, Tuple
|
|
8 |
from urllib.request import urlopen, urlretrieve
|
9 |
|
10 |
import streamlit as st
|
11 |
-
from huggingface_hub import
|
12 |
|
13 |
logging.basicConfig(level=logging.INFO)
|
14 |
logger = logging.getLogger(__name__)
|
@@ -30,11 +29,11 @@ class Config:
|
|
30 |
@classmethod
|
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 |
hf_username = (
|
36 |
whoami(token=user_token)["name"]
|
37 |
-
or
|
38 |
or whoami(token=system_token)["name"]
|
39 |
)
|
40 |
hf_token = user_token or system_token
|
|
|
1 |
import logging
|
|
|
2 |
import subprocess
|
3 |
import sys
|
4 |
from dataclasses import dataclass
|
|
|
7 |
from urllib.request import urlopen, urlretrieve
|
8 |
|
9 |
import streamlit as st
|
10 |
+
from huggingface_hub import HfApi, whoami
|
11 |
|
12 |
logging.basicConfig(level=logging.INFO)
|
13 |
logger = logging.getLogger(__name__)
|
|
|
29 |
@classmethod
|
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
|