Text Classification
Transformers
Safetensors
Chinese
spam-detection
advertising-detection
ad-classification
chinese
modernbert
mmbert
multi-task
four-head
Instructions to use x6nux/laya-ad with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use x6nux/laya-ad with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="x6nux/laya-ad")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("x6nux/laya-ad", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download code/laya-server/scripts/entrypoint.py from x6nux/laya-ad: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/x6nux/laya-ad/resolve/main/code/laya-server/scripts/entrypoint.py
- Command line
-
hf download hf://x6nux/laya-ad/code/laya-server/scripts/entrypoint.py
-
curl -L -o entrypoint.py https://huggingface.co/x6nux/laya-ad/resolve/main/code/laya-server/scripts/entrypoint.py
1.67 kB
| #!/usr/bin/env python3 | |
| """镜像入口:镜像不带权重,启动前从 Hugging Face 拉取模型,然后 exec uvicorn。 | |
| - LAYA_MODEL_VERSION:HF tag/分支(默认 v2) | |
| - LAYA_HF_ENDPOINT:模型源(默认 https://huggingface.co,可设 https://hf-mirror.com) | |
| - LAYA_PRELOAD:显式预载精度,如 fp8,int4 | |
| - 未设 LAYA_PRELOAD 且本地无模型时,自动下载 LAYA_MODEL_PRECISION(默认 fp8); | |
| LAYA_AUTO_DOWNLOAD=0 可关闭自动下载(改为管理员经 /internal/models/catalog 手动下载) | |
| """ | |
| import os | |
| import time | |
| from server.model_manager import ModelManager | |
| def main(): | |
| mm = ModelManager(os.environ.get("LAYA_MODEL_DIR", "/data/models/ad-clf"), | |
| os.environ.get("LAYA_DEVICE") or None) | |
| preload = [p.strip() for p in os.environ.get("LAYA_PRELOAD", "").split(",") if p.strip()] | |
| if not preload and not mm.installed() and os.environ.get("LAYA_AUTO_DOWNLOAD", "1") != "0": | |
| preload = [os.environ.get("LAYA_MODEL_PRECISION", "fp8").strip() or "fp8"] | |
| for p in preload: | |
| r = mm.download(p) | |
| print(f"[entrypoint] preload {p}: {r}", flush=True) | |
| if not r.get("accepted"): | |
| continue | |
| while mm.status()["state"] == "downloading": | |
| time.sleep(1) | |
| st = mm.status() | |
| print(f"[entrypoint] preload {p} -> {st['state']}", flush=True) | |
| if st.get("error"): | |
| print(f"[entrypoint] error: {st['error']}", flush=True) | |
| os.execvp("uvicorn", ["uvicorn", "server.main:app", "--host", "0.0.0.0", | |
| "--port", "8080", "--workers", "1", "--proxy-headers"]) | |
| if __name__ == "__main__": | |
| main() | |