Spaces:
Runtime error
Runtime error
Add CheXbert: clone repo in Docker, download weights from HF Hub at startup
Browse files- Dockerfile +9 -0
- main.py +17 -0
Dockerfile
CHANGED
|
@@ -16,11 +16,20 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 16 |
|
| 17 |
RUN python -c "import nltk; nltk.download('punkt'); nltk.download('punkt_tab')"
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
COPY inference/ ./inference/
|
| 20 |
COPY main.py .
|
| 21 |
|
| 22 |
RUN mkdir -p /tmp/results
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
EXPOSE 7860
|
| 25 |
|
| 26 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 16 |
|
| 17 |
RUN python -c "import nltk; nltk.download('punkt'); nltk.download('punkt_tab')"
|
| 18 |
|
| 19 |
+
# Clone Stanford CheXbert (public repo — only source code, no weights)
|
| 20 |
+
RUN git clone --depth 1 https://github.com/stanfordmlgroup/CheXbert.git /app/CheXbert
|
| 21 |
+
|
| 22 |
+
# Install CheXbert's own dependencies
|
| 23 |
+
RUN pip install --no-cache-dir scikit-learn tqdm || true
|
| 24 |
+
|
| 25 |
COPY inference/ ./inference/
|
| 26 |
COPY main.py .
|
| 27 |
|
| 28 |
RUN mkdir -p /tmp/results
|
| 29 |
|
| 30 |
+
ENV CHEXBERT_DIR=/app/CheXbert
|
| 31 |
+
ENV CHEXBERT_CKPT=/app/CheXbert/src/chexbert.pth
|
| 32 |
+
|
| 33 |
EXPOSE 7860
|
| 34 |
|
| 35 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
CHANGED
|
@@ -38,6 +38,23 @@ app.add_middleware(
|
|
| 38 |
|
| 39 |
@app.on_event("startup")
|
| 40 |
async def load_model():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
from inference.model import get_model, get_tokenizer
|
| 42 |
get_model()
|
| 43 |
get_tokenizer()
|
|
|
|
| 38 |
|
| 39 |
@app.on_event("startup")
|
| 40 |
async def load_model():
|
| 41 |
+
import os
|
| 42 |
+
from huggingface_hub import hf_hub_download
|
| 43 |
+
|
| 44 |
+
# Download chexbert.pth if not already present
|
| 45 |
+
chexbert_ckpt = os.environ.get("CHEXBERT_CKPT", "/app/CheXbert/src/chexbert.pth")
|
| 46 |
+
if not os.path.exists(chexbert_ckpt):
|
| 47 |
+
print("📥 Downloading chexbert.pth from HuggingFace Hub...")
|
| 48 |
+
os.makedirs(os.path.dirname(chexbert_ckpt), exist_ok=True)
|
| 49 |
+
hf_hub_download(
|
| 50 |
+
repo_id="alyrraza/radguard-v11",
|
| 51 |
+
filename="chexbert.pth",
|
| 52 |
+
local_dir=os.path.dirname(chexbert_ckpt),
|
| 53 |
+
)
|
| 54 |
+
print("✅ chexbert.pth downloaded")
|
| 55 |
+
else:
|
| 56 |
+
print("✅ chexbert.pth already present")
|
| 57 |
+
|
| 58 |
from inference.model import get_model, get_tokenizer
|
| 59 |
get_model()
|
| 60 |
get_tokenizer()
|