TymaaHammouda commited on
Commit
f708fe0
·
1 Parent(s): 7b63e3d

Load one_gram pickle file

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -1,18 +1,34 @@
1
  from fastapi import FastAPI
2
- #from sinatools.DataDownload.downloader import download_folder_from_hf
 
3
  import os
4
 
5
  print("Version 1")
6
  app = FastAPI()
7
 
8
- SINATOOLS_DIR = os.path.expanduser("~/.sinatools")
9
- os.makedirs(SINATOOLS_DIR, exist_ok=True)
10
 
11
- # Destination path
12
- dest_path = os.path.join(SINATOOLS_DIR)
 
13
 
14
- from huggingface_hub import snapshot_download
15
- import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  def download_folder_from_hf(repo_id, folder_name):
18
  """
@@ -34,10 +50,10 @@ print("Start loading")
34
  # Download explicitly to the expected path
35
  download_folder_from_hf("SinaLab/ArabGlossBERT", "bert-base-arabertv02_22_May_2021_00h_allglosses_unused01")
36
  download_folder_from_hf("SinaLab/ArabGlossBERT", "bert-base-arabertv02")
 
37
 
38
  print("Finish loading")
39
 
40
- # download_file(url='https://sina.birzeit.edu/four_grams.pickle', dest_path=dest_path)
41
  from sinatools.wsd.disambiguator import disambiguate
42
 
43
  @app.get("/predict")
 
1
  from fastapi import FastAPI
2
+ from huggingface_hub import snapshot_download
3
+ from huggingface_hub import hf_hub_download
4
  import os
5
 
6
  print("Version 1")
7
  app = FastAPI()
8
 
 
 
9
 
10
+ def download_file_from_hf(repo_id, filename):
11
+ """
12
+ Downloads a single file from a Hugging Face repo into ~/.sinatools
13
 
14
+ Args:
15
+ repo_id (str): Hugging Face repo id, e.g. "SinaLab/ArabGlossBERT"
16
+ filename (str): Path of the file inside the repo, e.g. "config.json"
17
+
18
+ Returns:
19
+ str: Absolute path to the downloaded file
20
+ """
21
+ target_dir = os.path.expanduser("~/.sinatools")
22
+ os.makedirs(target_dir, exist_ok=True)
23
+
24
+ file_path = hf_hub_download(
25
+ repo_id=repo_id,
26
+ filename=filename,
27
+ local_dir=target_dir,
28
+ local_dir_use_symlinks=False
29
+ )
30
+
31
+ return file_path
32
 
33
  def download_folder_from_hf(repo_id, folder_name):
34
  """
 
50
  # Download explicitly to the expected path
51
  download_folder_from_hf("SinaLab/ArabGlossBERT", "bert-base-arabertv02_22_May_2021_00h_allglosses_unused01")
52
  download_folder_from_hf("SinaLab/ArabGlossBERT", "bert-base-arabertv02")
53
+ download_file_from_hf("SinaLab/ArabGlossBERT","one_gram.pickle")
54
 
55
  print("Finish loading")
56
 
 
57
  from sinatools.wsd.disambiguator import disambiguate
58
 
59
  @app.get("/predict")