Spaces:
Running
Running
Commit
·
06611cb
1
Parent(s):
249049b
Load model from HF Hub
Browse files- Dockerfile +5 -11
- app.py +20 -3
- requirements.txt +4 -1
Dockerfile
CHANGED
|
@@ -1,16 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
# you will also find guides on how best to write your Dockerfile
|
| 3 |
-
|
| 4 |
-
FROM python:3.9
|
| 5 |
-
|
| 6 |
-
RUN useradd -m -u 1000 user
|
| 7 |
-
USER user
|
| 8 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
-
COPY
|
| 13 |
-
RUN pip install --no-cache-dir
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
COPY --chown=user . /app
|
| 16 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
|
|
|
|
| 10 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,7 +1,24 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
import torch
|
| 3 |
+
import pickle
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
# Download files from model repo
|
| 9 |
+
tag_vocab_path = hf_hub_download(
|
| 10 |
+
repo_id="SinaLab/Nested",
|
| 11 |
+
filename="tag_vocab.pkl"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
checkpoint_path = hf_hub_download(
|
| 15 |
+
repo_id="SinaLab/Nested",
|
| 16 |
+
filename="checkpoints/checkpoint_2.pt"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Load model
|
| 20 |
+
with open(tag_vocab_path, "rb") as f:
|
| 21 |
+
id2label = pickle.load(f)
|
| 22 |
+
|
| 23 |
+
model = torch.load(checkpoint_path, map_location="cpu")
|
| 24 |
+
model.eval()
|
requirements.txt
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
|
|
| 1 |
fastapi
|
| 2 |
-
uvicorn
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
fastapi
|
| 3 |
+
uvicorn
|
| 4 |
+
numpy
|
| 5 |
+
huggingface_hub
|