Spaces:
Runtime error
Runtime error
Commit ·
8bbfcd3
1
Parent(s): e7f7cda
feat: Initial production inference engine setup
Browse files- Dockerfile +1 -1
- registry/download_model.py +58 -0
Dockerfile
CHANGED
|
@@ -9,4 +9,4 @@ COPY . .
|
|
| 9 |
# Expose port 7860 (Hugging Face default)
|
| 10 |
EXPOSE 7860
|
| 11 |
|
| 12 |
-
CMD ["uvicorn", "
|
|
|
|
| 9 |
# Expose port 7860 (Hugging Face default)
|
| 10 |
EXPOSE 7860
|
| 11 |
|
| 12 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
registry/download_model.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Model Downloader for Hugging Face Spaces / Inference.
|
| 3 |
+
|
| 4 |
+
Downloads the ONNX model and its required artifacts from the Hugging Face Model Hub.
|
| 5 |
+
Only downloads files that do not already exist locally to minimize startup time.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
python registry/download_model.py
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
from huggingface_hub import hf_hub_download
|
| 14 |
+
|
| 15 |
+
# Configuration
|
| 16 |
+
REPO_ID = "YOUR_HF_USERNAME/cropguard-models" # TODO: Update with actual HF Model repo ID
|
| 17 |
+
VERSION = "v1.0"
|
| 18 |
+
TARGET_DIR = Path(__file__).parent / f"cropguard_{VERSION}"
|
| 19 |
+
|
| 20 |
+
FILES_TO_DOWNLOAD = [
|
| 21 |
+
f"cropguard_{VERSION}.onnx",
|
| 22 |
+
"classifier_weights.npy",
|
| 23 |
+
"temperature.json",
|
| 24 |
+
f"cropguard_{VERSION}.json",
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def download_artifacts():
|
| 29 |
+
print(f"📥 Checking model artifacts for {VERSION} in {TARGET_DIR}...")
|
| 30 |
+
TARGET_DIR.mkdir(parents=True, exist_ok=True)
|
| 31 |
+
|
| 32 |
+
for filename in FILES_TO_DOWNLOAD:
|
| 33 |
+
local_path = TARGET_DIR / filename
|
| 34 |
+
|
| 35 |
+
if local_path.exists():
|
| 36 |
+
print(f" ✅ {filename} already exists. Skipping download.")
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
print(f" ⬇️ Downloading {filename} from HF Hub...")
|
| 40 |
+
try:
|
| 41 |
+
# Download directly into the target directory
|
| 42 |
+
hf_hub_download(
|
| 43 |
+
repo_id=REPO_ID,
|
| 44 |
+
filename=filename,
|
| 45 |
+
local_dir=str(TARGET_DIR),
|
| 46 |
+
local_dir_use_symlinks=False, # We want the actual files, not symlinks in HF cache
|
| 47 |
+
)
|
| 48 |
+
print(f" ✅ Successfully downloaded {filename}")
|
| 49 |
+
except Exception as e:
|
| 50 |
+
print(f" ❌ Failed to download {filename}: {e}")
|
| 51 |
+
print(f" Please ensure the repository {REPO_ID} exists and is public,")
|
| 52 |
+
print(f" or you have set HF_TOKEN if it is a private repository.")
|
| 53 |
+
|
| 54 |
+
print("🎉 Artifact check complete. Ready for inference!")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
download_artifacts()
|