Spaces:
Runtime error
Runtime error
Commit ·
6ac2280
1
Parent(s): cd76ddf
Force local cache path
Browse files- Dockerfile +7 -2
- app.py +10 -2
Dockerfile
CHANGED
|
@@ -6,10 +6,15 @@ RUN pip install --no-cache-dir huggingface_hub
|
|
| 6 |
COPY requirements.txt .
|
| 7 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
|
| 9 |
-
# 2) Snapshot the model
|
| 10 |
RUN python - <<EOF
|
| 11 |
from huggingface_hub import snapshot_download
|
| 12 |
-
snapshot_download(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
EOF
|
| 14 |
|
| 15 |
# 3) Copy your code
|
|
|
|
| 6 |
COPY requirements.txt .
|
| 7 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
|
| 9 |
+
# 2) Snapshot the model into /app/model_cache
|
| 10 |
RUN python - <<EOF
|
| 11 |
from huggingface_hub import snapshot_download
|
| 12 |
+
snapshot_download(
|
| 13 |
+
repo_id="numind/NuExtract-1.5-tiny",
|
| 14 |
+
cache_dir="/app/model_cache",
|
| 15 |
+
local_dir="numind/NuExtract-1.5-tiny",
|
| 16 |
+
local_dir_use_symlinks=False
|
| 17 |
+
)
|
| 18 |
EOF
|
| 19 |
|
| 20 |
# 3) Copy your code
|
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import os
|
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
import tempfile
|
| 11 |
from supabase import create_client
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
load_dotenv()
|
|
@@ -16,6 +17,11 @@ app = FastAPI()
|
|
| 16 |
|
| 17 |
|
| 18 |
model_name = "numind/NuExtract-1.5-tiny"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
device = "gpu" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
| 20 |
dtype = torch.float16 if device in ("mps", "gpu") else torch.float32
|
| 21 |
|
|
@@ -35,13 +41,15 @@ def load_model():
|
|
| 35 |
# model_name, torch_dtype=dtype, trust_remote_code=True
|
| 36 |
# )
|
| 37 |
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
-
|
|
|
|
| 39 |
torch_dtype=dtype,
|
| 40 |
trust_remote_code=True
|
| 41 |
).to(device).eval()
|
| 42 |
# tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 43 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 44 |
-
|
|
|
|
| 45 |
trust_remote_code=True
|
| 46 |
)
|
| 47 |
print("Model and tokenizer loaded.", flush=True)
|
|
|
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
import tempfile
|
| 11 |
from supabase import create_client
|
| 12 |
+
from huggingface_hub import snapshot_download
|
| 13 |
|
| 14 |
|
| 15 |
load_dotenv()
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
model_name = "numind/NuExtract-1.5-tiny"
|
| 20 |
+
MODEL_CACHE_DIR = "/app/model_cache"
|
| 21 |
+
model_cache_path = snapshot_download(
|
| 22 |
+
repo_id="numind/NuExtract-1.5-tiny",
|
| 23 |
+
cache_dir=MODEL_CACHE_DIR
|
| 24 |
+
)
|
| 25 |
device = "gpu" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
| 26 |
dtype = torch.float16 if device in ("mps", "gpu") else torch.float32
|
| 27 |
|
|
|
|
| 41 |
# model_name, torch_dtype=dtype, trust_remote_code=True
|
| 42 |
# )
|
| 43 |
model = AutoModelForCausalLM.from_pretrained(
|
| 44 |
+
model_cache_path,
|
| 45 |
+
local_files_only=True,
|
| 46 |
torch_dtype=dtype,
|
| 47 |
trust_remote_code=True
|
| 48 |
).to(device).eval()
|
| 49 |
# tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 50 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 51 |
+
model_cache_path,
|
| 52 |
+
local_files_only=True,
|
| 53 |
trust_remote_code=True
|
| 54 |
)
|
| 55 |
print("Model and tokenizer loaded.", flush=True)
|