islasher commited on
Commit
e573dd2
·
verified ·
1 Parent(s): 03ab5e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -27,26 +27,31 @@ from huggingface_hub import HfApi
27
 
28
  username = 'islasher'
29
 
30
- api_token_secret_name = "HF_API_TOKEN" # Name of your secret on Hugging Face
31
- api_secret_url = f"https://huggingface.co/api/users/{username}/pract9/secrets/{api_token_secret_name}"
 
 
 
 
 
32
 
33
- # Retrieve the API token from the Hugging Face API
34
- response = requests.get(api_secret_url)
35
- response.raise_for_status() # Raise an exception for any HTTP error
36
 
37
- # Extract the API token from the response
38
- api_token = response.json()["value"]
39
 
40
  # Check if the API token is set
41
  if api_token is None:
42
- raise ValueError(f"Failed to retrieve API token from the Hugging Face API for {api_token_secret_name}")
43
 
44
  # Authenticate with Hugging Face using the API token
45
- api = HfApi()
46
  api.login(token=api_token)
47
 
48
 
49
 
 
50
  #token_access = HF_API_TOKEN
51
  #headers = {"Authorization": f"Bearer {token_access}"}
52
 
 
27
 
28
  username = 'islasher'
29
 
30
+ import os
31
+ from transformers.hf_api import HfApi
32
+
33
+
34
+ # Authenticate with Hugging Face
35
+ api = HfApi()
36
+ api.login()
37
 
38
+ # Fetch the API token secret
39
+ secret_name = "HF_API_TOKEN"
40
+ secret_value = api.secrets.get(username, secret_name)
41
 
42
+ # Retrieve the API token
43
+ api_token = secret_value["value"]
44
 
45
  # Check if the API token is set
46
  if api_token is None:
47
+ raise ValueError(f"Failed to retrieve API token from Hugging Face secret {secret_name}")
48
 
49
  # Authenticate with Hugging Face using the API token
 
50
  api.login(token=api_token)
51
 
52
 
53
 
54
+
55
  #token_access = HF_API_TOKEN
56
  #headers = {"Authorization": f"Bearer {token_access}"}
57