Deadmon commited on
Commit
d9c42b2
·
verified ·
1 Parent(s): 0fea6b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -8,19 +8,29 @@ import time
8
  import base64
9
  import google.auth
10
  import google.auth.transport.requests
11
- from huggingface_hub import login
 
12
 
13
  # --- 1. Configuration and Authentication (Unchanged) ---
14
  GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID")
15
  GCP_LOCATION = os.environ.get("GCP_LOCATION")
16
 
17
  # --- Authentication and Sanity Checks Block (Unchanged) ---
18
- hf_token = os.environ.get("HF_TOKEN")
19
- if hf_token:
20
- print("Hugging Face token found. Logging in.")
21
- login(token=hf_token)
22
- else:
23
- print("WARNING: Hugging Face token ('HF_TOKEN') not found.")
 
 
 
 
 
 
 
 
 
24
 
25
  creds_json_str = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS_JSON")
26
 
 
8
  import base64
9
  import google.auth
10
  import google.auth.transport.requests
11
+ import spaces
12
+ from huggingface_hub import login, hf_hub_download
13
 
14
  # --- 1. Configuration and Authentication (Unchanged) ---
15
  GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID")
16
  GCP_LOCATION = os.environ.get("GCP_LOCATION")
17
 
18
  # --- Authentication and Sanity Checks Block (Unchanged) ---
19
+
20
+
21
+ # Set up HF_TOKEN for Hugging Face Hub authentication
22
+ HF_TOKEN = os.getenv("HF_TOKEN")
23
+ if not HF_TOKEN:
24
+ raise EnvironmentError(
25
+ "HF_TOKEN environment variable not found. Please set it in the Hugging Face Space secrets"
26
+ )
27
+
28
+ try:
29
+ login(token=HF_TOKEN)
30
+ except Exception as e:
31
+ raise EnvironmentError(
32
+ f"Failed to authenticate with HF_TOKEN. Ensure the token has read access."
33
+ )
34
 
35
  creds_json_str = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS_JSON")
36