Update app.py
Browse files
app.py
CHANGED
@@ -20,8 +20,35 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
20 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
21 |
#notebook_login()
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
|
27 |
|
|
|
20 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
21 |
#notebook_login()
|
22 |
|
23 |
+
|
24 |
+
import os
|
25 |
+
from transformers.hf_api import HfApi
|
26 |
+
|
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}/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 |
|
53 |
|
54 |
|