Spaces:
Runtime error
Runtime error
Commit ·
01966be
1
Parent(s): 77c8eed
dfdaf
Browse files
app.py
CHANGED
|
@@ -25,13 +25,15 @@ model_name = "numind/NuExtract-1.5-tiny"
|
|
| 25 |
|
| 26 |
|
| 27 |
# MODEL_PATH = "/app/model_cache"
|
| 28 |
-
model_cache_path = snapshot_download(
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
)
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
device = "gpu" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
| 37 |
dtype = torch.float16 if device in ("mps", "gpu") else torch.float32
|
|
@@ -52,18 +54,18 @@ def load_model():
|
|
| 52 |
# model_name, torch_dtype=dtype, trust_remote_code=True
|
| 53 |
# )
|
| 54 |
model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
-
|
| 56 |
local_files_only=True,
|
| 57 |
torch_dtype=dtype,
|
| 58 |
trust_remote_code=True
|
| 59 |
).to(device).eval()
|
| 60 |
# tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 61 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 62 |
-
|
| 63 |
local_files_only=True,
|
| 64 |
trust_remote_code=True
|
| 65 |
)
|
| 66 |
-
print("✅ Model and tokenizer loaded from",
|
| 67 |
|
| 68 |
def predict_NuExtract(texts, template, batch_size=10, max_length=5096, max_new_tokens=1024):
|
| 69 |
print("Starting NuExtract prediction...", flush=True)
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
# MODEL_PATH = "/app/model_cache"
|
| 28 |
+
# model_cache_path = snapshot_download(
|
| 29 |
+
# repo_id="numind/NuExtract-1.5-tiny",
|
| 30 |
+
# local_dir="/app/model_cache", # <-- direct destination
|
| 31 |
+
# cache_dir="/app/model_cache/hf_cache"
|
| 32 |
+
# )
|
| 33 |
|
| 34 |
+
MODEL_CACHE = "/home/user/app/model_cache"
|
| 35 |
+
|
| 36 |
+
print(">>> MODEL CACHE PATH:", MODEL_CACHE, os.listdir(MODEL_CACHE))
|
| 37 |
|
| 38 |
device = "gpu" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
| 39 |
dtype = torch.float16 if device in ("mps", "gpu") else torch.float32
|
|
|
|
| 54 |
# model_name, torch_dtype=dtype, trust_remote_code=True
|
| 55 |
# )
|
| 56 |
model = AutoModelForCausalLM.from_pretrained(
|
| 57 |
+
MODEL_CACHE,
|
| 58 |
local_files_only=True,
|
| 59 |
torch_dtype=dtype,
|
| 60 |
trust_remote_code=True
|
| 61 |
).to(device).eval()
|
| 62 |
# tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 63 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 64 |
+
MODEL_CACHE,
|
| 65 |
local_files_only=True,
|
| 66 |
trust_remote_code=True
|
| 67 |
)
|
| 68 |
+
print("✅ Model and tokenizer loaded from", MODEL_CACHE)
|
| 69 |
|
| 70 |
def predict_NuExtract(texts, template, batch_size=10, max_length=5096, max_new_tokens=1024):
|
| 71 |
print("Starting NuExtract prediction...", flush=True)
|