TymaaHammouda commited on
Commit
bfb7b0e
·
1 Parent(s): 03a5442

Create download_folder_from_hf function

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -1,5 +1,5 @@
1
  from fastapi import FastAPI
2
- from sinatools.DataDownload.downloader import download_folder_from_hf
3
  from sinatools.wsd.disambiguator import disambiguate
4
  import os
5
 
@@ -11,6 +11,26 @@ os.makedirs(SINATOOLS_DIR, exist_ok=True)
11
  # Destination path
12
  dest_path = os.path.join(SINATOOLS_DIR)
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  print("Start loading")
15
  # Download explicitly to the expected path
16
  download_folder_from_hf("SinaLab/ArabGlossBERT", "bert-base-arabertv02_22_May_2021_00h_allglosses_unused01")
 
1
  from fastapi import FastAPI
2
+ #from sinatools.DataDownload.downloader import download_folder_from_hf
3
  from sinatools.wsd.disambiguator import disambiguate
4
  import os
5
 
 
11
  # Destination path
12
  dest_path = os.path.join(SINATOOLS_DIR)
13
 
14
+
15
+ from huggingface_hub import snapshot_download
16
+ import os
17
+
18
+ def download_folder_from_hf(repo_id, folder_name):
19
+ """
20
+ Downloads a folder from a Hugging Face model repo into ~/.sinatools
21
+ """
22
+ target_dir = os.path.expanduser("~/.sinatools")
23
+
24
+ local_path = snapshot_download(
25
+ repo_id=repo_id,
26
+ allow_patterns=f"{folder_name}/**",
27
+ local_dir=target_dir,
28
+ local_dir_use_symlinks=False
29
+ )
30
+
31
+ return os.path.join(local_path, folder_name)
32
+
33
+
34
  print("Start loading")
35
  # Download explicitly to the expected path
36
  download_folder_from_hf("SinaLab/ArabGlossBERT", "bert-base-arabertv02_22_May_2021_00h_allglosses_unused01")