vhr1007 commited on
Commit
6682130
1 Parent(s): 412adbb
Files changed (2) hide show
  1. app.py +13 -0
  2. utils/embedding_utils.py +4 -4
app.py CHANGED
@@ -12,9 +12,22 @@ import logging
12
  import time
13
  import os
14
  from dotenv import load_dotenv
 
15
 
16
  #load_dotenv()
17
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  # Retrieve the API key from the environment
19
  API_KEY = os.getenv('X_API_KEY')
20
  bucket_name = os.getenv('bucket_name')
 
12
  import time
13
  import os
14
  from dotenv import load_dotenv
15
+ from huggingface_hub import HfApi, HfFolder
16
 
17
  #load_dotenv()
18
 
19
+ # Set the HF_HOME directory programmatically to a writable directory
20
+ os.environ["HF_HOME"] = "/app/.cache/huggingface"
21
+ os.makedirs(os.environ["HF_HOME"], exist_ok=True)
22
+
23
+ # Initialize Hugging Face API
24
+ huggingface_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
25
+ if huggingface_token:
26
+ HfFolder.save_token(huggingface_token)
27
+ else:
28
+ raise ValueError("Hugging Face token is not set. Please set the HUGGINGFACE_HUB_TOKEN environment variable.")
29
+
30
+
31
  # Retrieve the API key from the environment
32
  API_KEY = os.getenv('X_API_KEY')
33
  bucket_name = os.getenv('bucket_name')
utils/embedding_utils.py CHANGED
@@ -2,7 +2,7 @@
2
 
3
  from sentence_transformers import SentenceTransformer
4
  from llama_index.core import SimpleDirectoryReader
5
- from huggingface_hub import login
6
  from typing import List, Tuple
7
  from dotenv import load_dotenv
8
  import numpy as np
@@ -12,7 +12,7 @@ from docx import Document
12
  import tempfile
13
  import os
14
  import logging
15
-
16
 
17
  # Load environment variables from .env file
18
  #load_dotenv()
@@ -20,9 +20,9 @@ import logging
20
  # Load Hugging Face token from environment variable
21
  huggingface_token = os.getenv('HUGGINGFACE_HUB_TOKEN')
22
 
23
-
24
  if huggingface_token:
25
- login(token=huggingface_token, add_to_git_credential=True)
26
  else:
27
  raise ValueError("Hugging Face token is not set. Please set the HUGGINGFACE_HUB_TOKEN environment variable.")
28
 
 
2
 
3
  from sentence_transformers import SentenceTransformer
4
  from llama_index.core import SimpleDirectoryReader
5
+
6
  from typing import List, Tuple
7
  from dotenv import load_dotenv
8
  import numpy as np
 
12
  import tempfile
13
  import os
14
  import logging
15
+ from huggingface_hub import HfFolder
16
 
17
  # Load environment variables from .env file
18
  #load_dotenv()
 
20
  # Load Hugging Face token from environment variable
21
  huggingface_token = os.getenv('HUGGINGFACE_HUB_TOKEN')
22
 
23
+ # Save the Hugging Face token securely
24
  if huggingface_token:
25
+ HfFolder.save_token(huggingface_token)
26
  else:
27
  raise ValueError("Hugging Face token is not set. Please set the HUGGINGFACE_HUB_TOKEN environment variable.")
28