TymaaHammouda commited on
Commit
a563bdb
·
verified ·
1 Parent(s): 6b7e109

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -12,35 +12,33 @@ from huggingface_hub import snapshot_download, hf_hub_download
12
  import os
13
  import shutil
14
 
15
- from transformers import AutoTokenizer, AutoModel
16
- import inspect
17
- from collections import namedtuple
18
- import json
19
  from pydantic import BaseModel
20
  from fastapi.responses import JSONResponse
21
 
 
22
  app = FastAPI()
23
 
24
- pretrained_path = "aubmindlab/bert-base-arabertv2" # must match training
25
- tokenizer = AutoTokenizer.from_pretrained(pretrained_path)
26
- encoder = AutoModel.from_pretrained(pretrained_path).eval()
27
 
 
 
 
 
 
 
28
 
29
- checkpoint_path = snapshot_download(repo_id="https://huggingface.co/spaces/SinaLab/wojood-api/tree/main/Nested", allow_patterns="checkpoints/")
30
 
31
- args_path = hf_hub_download(
32
- repo_id="https://huggingface.co/spaces/SinaLab/wojood-api/tree/main/Nested",
33
- filename="args.json"
34
- )
35
 
36
- with open(args_path, 'r') as f:
37
- args_data = json.load(f)
38
-
39
- # Load model
40
- with open("https://huggingface.co/spaces/SinaLab/wojood-api/tree/main/Nested/utils/tag_vocab.pkl", "rb") as f:
41
- label_vocab = pickle.load(f)
42
 
43
-
44
 
45
  BASE_DIR = os.path.expanduser("~/.sinatools")
46
 
 
12
  import os
13
  import shutil
14
 
15
+ from fastapi import FastAPI
16
+ from huggingface_hub import hf_hub_download
17
+ import os
 
18
  from pydantic import BaseModel
19
  from fastapi.responses import JSONResponse
20
 
21
+ print("Version ---- 2")
22
  app = FastAPI()
23
 
24
+ def download_file_from_hf(repo_id, filename):
25
+ target_dir = os.path.expanduser("~/.sinatools")
26
+ os.makedirs(target_dir, exist_ok=True)
27
 
28
+ file_path = hf_hub_download(
29
+ repo_id=repo_id,
30
+ filename=filename,
31
+ local_dir=target_dir,
32
+ local_dir_use_symlinks=False
33
+ )
34
 
35
+ return file_path
36
 
37
+ download_file_from_hf("SinaLab/Nested-v1","args.json")
38
+ download_file_from_hf("SinaLab/Nested-v1","tag_vocab.pkl")
 
 
39
 
40
+ snapshot_download(repo_id="SinaLab/Nested", allow_patterns="checkpoints/")
 
 
 
 
 
41
 
 
42
 
43
  BASE_DIR = os.path.expanduser("~/.sinatools")
44