Spaces:
Runtime error
Runtime error
Commit ·
cd76ddf
1
Parent(s): 8f91821
use local cache
Browse files- Dockerfile +11 -10
- app.py +15 -5
Dockerfile
CHANGED
|
@@ -1,18 +1,19 @@
|
|
| 1 |
-
# Dockerfile
|
| 2 |
FROM python:3.10-slim
|
| 3 |
-
|
| 4 |
-
# Create working dir
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
# Install
|
|
|
|
| 8 |
COPY requirements.txt .
|
| 9 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
CMD ["bash",
|
|
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
|
|
|
|
|
|
| 2 |
WORKDIR /app
|
| 3 |
|
| 4 |
+
# 1) Install HF tools + your deps
|
| 5 |
+
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 locally
|
| 10 |
+
RUN python - <<EOF
|
| 11 |
+
from huggingface_hub import snapshot_download
|
| 12 |
+
snapshot_download("numind/NuExtract-1.5-tiny", cache_dir="/app/model_cache")
|
| 13 |
+
EOF
|
| 14 |
|
| 15 |
+
# 3) Copy your code
|
| 16 |
+
COPY . .
|
| 17 |
|
| 18 |
+
ENV PORT=7860
|
| 19 |
+
CMD ["bash","-lc","uvicorn app:app --host 0.0.0.0 --port $PORT"]
|
app.py
CHANGED
|
@@ -14,9 +14,10 @@ from supabase import create_client
|
|
| 14 |
load_dotenv()
|
| 15 |
app = FastAPI()
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
@app.on_event("startup")
|
| 22 |
def startup_supabase():
|
|
@@ -30,10 +31,19 @@ def startup_supabase():
|
|
| 30 |
def load_model():
|
| 31 |
print("Loading model and tokenizer...", flush=True)
|
| 32 |
global model, tokenizer
|
|
|
|
|
|
|
|
|
|
| 33 |
model = AutoModelForCausalLM.from_pretrained(
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
).to(device).eval()
|
| 36 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
print("Model and tokenizer loaded.", flush=True)
|
| 38 |
|
| 39 |
def predict_NuExtract(texts, template, batch_size=10, max_length=5096, max_new_tokens=1024):
|
|
|
|
| 14 |
load_dotenv()
|
| 15 |
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 |
|
| 22 |
@app.on_event("startup")
|
| 23 |
def startup_supabase():
|
|
|
|
| 31 |
def load_model():
|
| 32 |
print("Loading model and tokenizer...", flush=True)
|
| 33 |
global model, tokenizer
|
| 34 |
+
# model = AutoModelForCausalLM.from_pretrained(
|
| 35 |
+
# model_name, torch_dtype=dtype, trust_remote_code=True
|
| 36 |
+
# )
|
| 37 |
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
+
"/app/model_cache/numind/NuExtract-1.5-tiny",
|
| 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 |
+
"/app/model_cache/numind/NuExtract-1.5-tiny",
|
| 45 |
+
trust_remote_code=True
|
| 46 |
+
)
|
| 47 |
print("Model and tokenizer loaded.", flush=True)
|
| 48 |
|
| 49 |
def predict_NuExtract(texts, template, batch_size=10, max_length=5096, max_new_tokens=1024):
|