alfredplpl commited on
Commit
3dbf11a
·
verified ·
1 Parent(s): 3a0e13b

Fail fast with clear message when HF_TOKEN missing

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -22,8 +22,12 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
22
 
23
  # private model access: authenticate with HF_TOKEN (Space secret)
24
  HF_TOKEN = os.environ.get("HF_TOKEN")
25
- if HF_TOKEN:
26
- login(token=HF_TOKEN, add_to_git_credential=False)
 
 
 
 
27
 
28
  _tok = AutoTokenizer.from_pretrained(INPUT_MODEL, token=HF_TOKEN)
29
  _model = AutoModelForSequenceClassification.from_pretrained(
 
22
 
23
  # private model access: authenticate with HF_TOKEN (Space secret)
24
  HF_TOKEN = os.environ.get("HF_TOKEN")
25
+ if not HF_TOKEN:
26
+ raise RuntimeError(
27
+ "HF_TOKEN is not set. Add it as a Space secret "
28
+ "(Settings -> Variables and secrets) to pull the private model."
29
+ )
30
+ login(token=HF_TOKEN, add_to_git_credential=False)
31
 
32
  _tok = AutoTokenizer.from_pretrained(INPUT_MODEL, token=HF_TOKEN)
33
  _model = AutoModelForSequenceClassification.from_pretrained(