uripper commited on
Commit
d78b29e
·
1 Parent(s): 27bf46d
Files changed (1) hide show
  1. app/download_models.py +15 -5
app/download_models.py CHANGED
@@ -1,6 +1,9 @@
1
  import os
2
  from huggingface_hub import hf_hub_download
3
 
 
 
 
4
 
5
  def create_directory(dir_path):
6
  """
@@ -13,15 +16,17 @@ def create_directory(dir_path):
13
  print(f"Directory {dir_path} already exists.")
14
 
15
 
16
- def download_model(repo_id, filename, destination_dir):
17
  """
18
  Download the model from Hugging Face and move it to the destination directory.
19
  """
20
  # Create destination directory if it doesn't exist
21
  create_directory(destination_dir)
22
 
23
- # Download the file from the Hugging Face Hub
24
- model_path = hf_hub_download(repo_id=repo_id, filename=filename)
 
 
25
 
26
  # Move the downloaded file to the destination directory
27
  destination_path = os.path.join(destination_dir, filename)
@@ -47,11 +52,16 @@ if __name__ == "__main__":
47
  oracle_cards_graph_dir = "./data/oracle_cards_graph"
48
 
49
  # Download the card_graph.pkl from uripper/magic-gnn
50
- card_graph_path = download_model(magic_gnn_repo, card_graph_file, card_graph_dir)
 
 
51
 
52
  # Download the oracle_cards_graph.pkl from uripper/oracle_cards_graph
53
  oracle_cards_graph_path = download_model(
54
- oracle_cards_graph_repo, oracle_cards_graph_file, oracle_cards_graph_dir
 
 
 
55
  )
56
 
57
  # Print final message with full paths
 
1
  import os
2
  from huggingface_hub import hf_hub_download
3
 
4
+ # Get the Hugging Face token from environment variable (automatically provided from the secret)
5
+ HUGGINGFACE_TOKEN = os.getenv("key")
6
+
7
 
8
  def create_directory(dir_path):
9
  """
 
16
  print(f"Directory {dir_path} already exists.")
17
 
18
 
19
+ def download_model(repo_id, filename, destination_dir, token):
20
  """
21
  Download the model from Hugging Face and move it to the destination directory.
22
  """
23
  # Create destination directory if it doesn't exist
24
  create_directory(destination_dir)
25
 
26
+ # Download the file from the Hugging Face Hub using the token
27
+ model_path = hf_hub_download(
28
+ repo_id=repo_id, filename=filename, use_auth_token=token
29
+ )
30
 
31
  # Move the downloaded file to the destination directory
32
  destination_path = os.path.join(destination_dir, filename)
 
52
  oracle_cards_graph_dir = "./data/oracle_cards_graph"
53
 
54
  # Download the card_graph.pkl from uripper/magic-gnn
55
+ card_graph_path = download_model(
56
+ magic_gnn_repo, card_graph_file, card_graph_dir, HUGGINGFACE_TOKEN
57
+ )
58
 
59
  # Download the oracle_cards_graph.pkl from uripper/oracle_cards_graph
60
  oracle_cards_graph_path = download_model(
61
+ oracle_cards_graph_repo,
62
+ oracle_cards_graph_file,
63
+ oracle_cards_graph_dir,
64
+ HUGGINGFACE_TOKEN,
65
  )
66
 
67
  # Print final message with full paths