Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,42 +9,48 @@ import json
|
|
| 9 |
print("Version ---- 1")
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
-
from huggingface_hub import snapshot_download
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# Path expected by sinatools
|
| 15 |
BASE_DIR = os.path.expanduser("~/.sinatools")
|
| 16 |
-
MODEL_DIR = os.path.join(BASE_DIR, "relation_model")
|
| 17 |
|
| 18 |
-
#
|
|
|
|
|
|
|
|
|
|
| 19 |
os.makedirs(BASE_DIR, exist_ok=True)
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
snapshot_download(
|
| 24 |
repo_id="aaljabari/arabic-relation-extraction-model",
|
| 25 |
-
local_dir=
|
| 26 |
local_dir_use_symlinks=False
|
| 27 |
)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
filename="args.json"
|
| 40 |
-
)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# Load model
|
| 46 |
-
with open("Nested/utils/tag_vocab.pkl", "rb") as f:
|
| 47 |
-
label_vocab = pickle.load(f)
|
| 48 |
|
| 49 |
|
| 50 |
from sinatools.relations.relation_extractor import relation_extraction
|
|
|
|
| 9 |
print("Version ---- 1")
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
+
from huggingface_hub import snapshot_download, hf_hub_download
|
| 13 |
+
import os
|
| 14 |
+
import shutil
|
| 15 |
|
|
|
|
| 16 |
BASE_DIR = os.path.expanduser("~/.sinatools")
|
|
|
|
| 17 |
|
| 18 |
+
# Paths expected by sinatools
|
| 19 |
+
RELATION_MODEL_DIR = os.path.join(BASE_DIR, "relation_model")
|
| 20 |
+
NER_DIR = os.path.join(BASE_DIR, "Wj27012000.tar")
|
| 21 |
+
|
| 22 |
os.makedirs(BASE_DIR, exist_ok=True)
|
| 23 |
|
| 24 |
+
# -------------------------
|
| 25 |
+
# 1. Download relation model
|
| 26 |
+
# -------------------------
|
| 27 |
+
if not os.path.exists(RELATION_MODEL_DIR) or not os.listdir(RELATION_MODEL_DIR):
|
| 28 |
snapshot_download(
|
| 29 |
repo_id="aaljabari/arabic-relation-extraction-model",
|
| 30 |
+
local_dir=RELATION_MODEL_DIR,
|
| 31 |
local_dir_use_symlinks=False
|
| 32 |
)
|
| 33 |
|
| 34 |
+
# -------------------------
|
| 35 |
+
# 2. Download NER resources
|
| 36 |
+
# -------------------------
|
| 37 |
+
if not os.path.exists(NER_DIR):
|
| 38 |
+
os.makedirs(NER_DIR, exist_ok=True)
|
| 39 |
|
| 40 |
+
nested_repo_path = snapshot_download(
|
| 41 |
+
repo_id="SinaLab/Nested"
|
| 42 |
+
)
|
|
|
|
| 43 |
|
| 44 |
+
# Copy tag_vocab.pkl to expected location
|
| 45 |
+
src_vocab = os.path.join(nested_repo_path, "Nested", "utils", "tag_vocab.pkl")
|
| 46 |
+
dst_vocab = os.path.join(NER_DIR, "tag_vocab.pkl")
|
| 47 |
|
| 48 |
+
if os.path.exists(src_vocab):
|
| 49 |
+
shutil.copy(src_vocab, dst_vocab)
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Optional debug
|
| 52 |
+
print("sinatools dir:", os.listdir(BASE_DIR))
|
| 53 |
+
print("NER dir:", os.listdir(NER_DIR))
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
from sinatools.relations.relation_extractor import relation_extraction
|