Spaces:
Sleeping
Sleeping
v2: Alpine base + runtime /admin/load (deepseek defaults + template kept)
Browse filesFiles changed (3)
- Dockerfile+13-33
- main.py+101-216
- requirements.txt+8-7
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152# ── GGUF LLM API — Hugging Face Spaces (Docker SDK), CPU tier by default ───────# Builds llama-cpp-python from source, so the C/C++ toolchain is installed first.FROM python:3.11-slim# 1) Build toolchain required to compile llama-cpp-python.# build-essential = gcc + g++ + make; cmake is what its build backend invokes.RUN apt-get update && apt-get install -y --no-install-recommends \build-essential \gcc \g++ \make \cmake \git \&& rm -rf /var/lib/apt/lists/*# 2) Hugging Face Spaces runs the container as a non-root user (uid 1000).# Create it and put ALL writable paths under its home so model downloads work.RUN useradd -m -u 1000 userUSER userENV HOME=/home/user \PATH=/home/user/.local/bin:$PATH \# HF_HOME is where huggingface_hub caches the downloaded .gguf at startup.# It MUST be writable by uid 1000 — /home/user is, /root and /app often are not.HF_HOME=/home/user/.cache/huggingface \# HF CPU-basic = 2 vCPUs. Pin llama.cpp + BLAS to 2 threads so they don't# over-subscribe the host's core count and thrash. Raise these (or set the# N_THREADS Space variable) if you move to bigger CPU/GPU hardware.N_THREADS=2 \OMP_NUM_THREADS=2WORKDIR /home/user/app# 3) Install Python deps first (better layer caching than copying everything).# The --extra-index-url hosts PREBUILT CPU wheels for llama-cpp-python, so pip# installs a wheel instead of compiling from source. This avoids the #1 cause# of failed HF CPU builds: the source compile running out of memory. The gcc/# cmake toolchain above stays only as a fallback if no wheel matches.COPY --chown=user requirements.txt ./RUN pip install --no-cache-dir --upgrade pip \&& pip install --no-cache-dir -r requirements.txt \--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu# 4) Copy the (lightweight) application code. No model file is baked in — it is# pulled from the HF model repo on startup.COPY --chown=user . ./# 5) Hugging Face Spaces routes public traffic to port 7860.EXPOSE 7860# 6) Single worker: llama.cpp holds one non-thread-safe context; the app serialises# calls internally. Do NOT add --workers > 1 (each would reload the whole model).CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]1234567891011121314151617181920212223242526272829303132# ── GGUF LLM API — HF Spaces (Docker SDK), Alpine base ────────────────────────# Alpine (musl libc) is REQUIRED here: the prebuilt llama-cpp-python CPU wheels# on abetlen's index are musl builds, and compiling from source exceeds HF's# build-job timeout on the free builder. With the wheel, the build is minutes.FROM python:3.11-alpine# Runtime libraries the llama.cpp shared objects need (C++/OpenMP), plus a# compiler-free environment — no gcc/cmake on purpose: wheels only.RUN apk add --no-cache libstdc++ libgomp curl# HF Spaces runs containers as uid 1000 with writable paths under its home.RUN adduser -D -u 1000 userUSER userENV HOME=/home/user \PATH=/home/user/.local/bin:$PATH \HF_HOME=/home/user/.cache/huggingface \N_THREADS=2 \OMP_NUM_THREADS=2WORKDIR /home/user/appCOPY --chown=user requirements.txt ./# --only-binary: fail loudly if any dependency would need a compiler instead of# silently hitting the build timeout again.RUN pip install --no-cache-dir --upgrade pip \&& pip install --no-cache-dir --only-binary=:all: -r requirements.txt \--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpuCOPY --chown=user . ./EXPOSE 7860CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
123456789101112131415161718192021222324252612 unmodified lines3940414243444546478 unmodified lines56575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541556 unmodified lines162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325"""GGUF LLM API for Hugging Face Spaces (Docker SDK) — "Download on Startup".On boot this app downloads a .gguf model from a Hugging Face **Model** repo withhuggingface_hub, loads it once with llama-cpp-python, and serves it behind anOpenAI-compatible chat endpoint plus a simple /generate endpoint.Nothing here is model-specific: which repo/file to pull is chosen entirely byenvironment variables, so you redeploy a new model by changing a variable in theSpace settings — no code edits.Environment variables----------------------REPO_ID (required) HF model repo, e.g. "your-username/my-gguf-models"FILENAME (required) the .gguf file inside that repo,e.g. "mistral-7b-instruct-v0.2.Q4_K_M.gguf"HF_TOKEN (optional) a READ token — ONLY needed if the model repo is PRIVATEMODEL_ID (optional) name reported to clients (default: FILENAME)N_CTX (optional) context window in tokens (default 4096)N_THREADS (optional) CPU threads for inference (default: all cores)N_GPU_LAYERS (optional) layers to offload to GPU (default 0 = CPU only)CHAT_FORMAT (optional) e.g. "llama-3", "chatml", "mistral-instruct"DEFAULT_MAX_TOKENS (optional) fallback max_tokens per request (default 512)"""import osimport time12 unmodified lineslogging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")log = logging.getLogger("gguf-api")# DeepSeek-LLM chat template — NOT built into llama-cpp-python (and TheBloke's# 2023 GGUFs predate embedded chat_template metadata), so register it ourselves.# Official format: [system\n\n]User: {msg}\n\nAssistant: {reply}<eos>...Assistant:@llama_chat_format.register_chat_format("deepseek")def _format_deepseek(messages, **kwargs) -> llama_chat_format.ChatFormatterResponse:prompt = ""8 unmodified linesprompt += "Assistant:"return llama_chat_format.ChatFormatterResponse(prompt=prompt, stop=["User:"])# ── Configuration (all via environment) ───────────────────────────────────────# Defaults point at DeepSeek-LLM-7B-CHAT (Q4_K_M), a PUBLIC GGUF — so the Space# runs with zero setup. Override REPO_ID/FILENAME in the Space settings to swap# models without touching the code.REPO_ID = os.getenv("REPO_ID", "TheBloke/deepseek-llm-7B-chat-GGUF").strip()FILENAME = os.getenv("FILENAME", "deepseek-llm-7b-chat.Q4_K_M.gguf").strip()HF_TOKEN = os.getenv("HF_TOKEN") or None # None => anonymous (public repo)MODEL_ID = os.getenv("MODEL_ID", "") or "deepseek-7b-chat" # name reported to clientsN_CTX = int(os.getenv("N_CTX", "4096"))# Default to the number of *usable* CPUs (respects cgroup cpuset), NOT os.cpu_count()# which over-reports the host's cores inside a container and causes thread thrash._USABLE_CPUS = len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else (os.cpu_count() or 4)N_THREADS = int(os.getenv("N_THREADS", str(_USABLE_CPUS)))N_GPU_LAYERS = int(os.getenv("N_GPU_LAYERS", "0")) # 0 = CPU only; -1 = all layers on GPU# "deepseek" = the custom template registered above, matching the default chat# model. Set to "" (empty) when running a BASE model — the endpoints then bypass# chat templating and use raw text completion instead.CHAT_FORMAT = os.getenv("CHAT_FORMAT", "deepseek").strip()DEFAULT_MAX_TOKENS = int(os.getenv("DEFAULT_MAX_TOKENS", "512"))# The loaded model lives here. It is None until startup finishes (or if it failed).# llama-cpp is NOT thread-safe for concurrent generation on one context, so every# call into the model is serialised behind this lock._llm: Optional[Llama] = None_llm_lock = threading.Lock()_load_error: Optional[str] = Nonedef _download_and_load() -> None:"""Download the .gguf from the HF model repo, then load it with llama-cpp."""global _llm, _load_errorif not REPO_ID or not FILENAME:_load_error = ("REPO_ID and FILENAME must both be set. In your Space go to ""Settings -> Variables and secrets and add REPO_ID (e.g. ""'your-username/my-gguf-models') and FILENAME (e.g. 'model.Q4_K_M.gguf').")log.error(_load_error)returntry:log.info("Downloading model '%s' from repo '%s' ...", FILENAME, REPO_ID)t0 = time.time()# hf_hub_download caches under HF_HOME and returns the local file path.# Re-runs are instant once the file is cached in the container layer.model_path = hf_hub_download(repo_id=REPO_ID,filename=FILENAME,token=HF_TOKEN, # ignored for public repos, required for private)log.info("Model downloaded to %s (%.1fs)", model_path, time.time() - t0)kwargs: Dict[str, Any] = dict(model_path=model_path,n_ctx=N_CTX,n_threads=N_THREADS,n_gpu_layers=N_GPU_LAYERS,verbose=False,)if CHAT_FORMAT:kwargs["chat_format"] = CHAT_FORMATlog.info("Loading model into memory (n_ctx=%d, n_gpu_layers=%d) ...", N_CTX, N_GPU_LAYERS)t0 = time.time()_llm = Llama(**kwargs)log.info("Model ready (%.1fs).", time.time() - t0)except Exception as exc: # keep the server up so /health can report the reason_load_error = f"Failed to download/load model: {exc}"log.exception(_load_error)@asynccontextmanagerasync def lifespan(app: FastAPI):"""Start loading the model in a BACKGROUND thread so the HTTP port opensimmediately.Hugging Face marks a Space "in error" if port 7860 doesn't open within itsstartup window. Downloading a ~2 GB model and loading it *before* the serverbinds would blow past that window (this is exactly what crashes naive Spaces).Loading off-thread lets uvicorn bind 7860 in seconds; /health reports"loading_or_error" until the model is ready, and inference endpoints return aclear 503 until then instead of failing the whole container."""threading.Thread(target=_download_and_load, name="model-loader", daemon=True).start()yield# (nothing to clean up: process exit releases the model)app = FastAPI(title="GGUF LLM API (HF Spaces)", version="1.0.0", lifespan=lifespan)# ── Request/response schemas ──────────────────────────────────────────────────class ChatMessage(BaseModel):role: strcontent: str = ""6 unmodified linestop_p: float = 0.95max_tokens: Optional[int] = Nonestop: Optional[List[str]] = None# OpenAI JSON mode: {"type":"json_object"} -> llama.cpp grammar-constrains the# reply to VALID JSON. Essential for small models, which otherwise emit# unbalanced brackets (e.g. a stray "]" after each array element).response_format: Optional[Dict[str, Any]] = Noneclass GenerateRequest(BaseModel):prompt: str = Field(..., description="Plain text prompt for the model.",examples=["State Newton's second law of motion in one sentence."])max_tokens: int = Field(DEFAULT_MAX_TOKENS, description="Max tokens to generate.")temperature: float = Field(0.7, description="Sampling temperature (0 = deterministic).")def _require_model() -> Llama:"""Return the loaded model or raise 503 with a helpful message."""if _llm is None:raise HTTPException(status_code=503,detail=_load_error or "Model is still loading, try again in a few seconds.",)return _llmdef _messages_to_raw_prompt(messages: List["ChatMessage"]) -> str:"""Flatten chat messages into a plain-text prompt for BASE (non-chat) models.A base model was never trained on a chat template — wrapping its input inone (e.g. llama-2 [INST] tags) makes it emit only <s>/</s> tokens. Insteadwe join the message contents into plain text and let the model continue it."""parts = [m.content.strip() for m in messages if m.content and m.content.strip()]return "\n\n".join(parts)def _raw_chat_completion(llm: Llama, req: "ChatCompletionRequest") -> Dict[str, Any]:"""Text-completion path used when CHAT_FORMAT is empty (base model)."""prompt = _messages_to_raw_prompt(req.messages)result = llm.create_completion(prompt=prompt,temperature=req.temperature,top_p=req.top_p,max_tokens=req.max_tokens if req.max_tokens is not None else DEFAULT_MAX_TOKENS,stop=req.stop,)text = result["choices"][0]["text"]# Re-shape the completion result into an OpenAI chat-completion response so# clients (which always call /v1/chat/completions) need no changes.return {"id": f"chatcmpl-{uuid.uuid4().hex}","object": "chat.completion","created": int(time.time()),"model": MODEL_ID,"choices": [{"index": 0,"message": {"role": "assistant", "content": text},"finish_reason": result["choices"][0].get("finish_reason", "stop"),}],"usage": result.get("usage", {}),}# ── Endpoints ─────────────────────────────────────────────────────────────────@app.get("/health")def health() -> Dict[str, Any]:"""Liveness probe. status='ok' only once the model is loaded and ready."""# Report the CPU picture so thread over-subscription (the #1 cause of slow# CPU generation) is visible: if cpu_count >> usable cores, llama.cpp threads# thrash. N_THREADS is what we actually hand to llama.cpp.usable = len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else Nonereturn {"status": "ok" if _llm is not None else "loading_or_error","model": MODEL_ID,"repo_id": REPO_ID,"filename": FILENAME,"n_ctx": N_CTX,"n_gpu_layers": N_GPU_LAYERS,"n_threads": N_THREADS,"cpu_count": os.cpu_count(),"usable_cpus": usable,"error": _load_error,}@app.get("/v1/models")def list_models() -> Dict[str, Any]:"""OpenAI-shaped model list (a single loaded model)."""return {"object": "list", "data": [{"id": MODEL_ID, "object": "model", "owned_by": "local"}]}@app.post("/v1/chat/completions")def chat_completions(req: ChatCompletionRequest) -> Dict[str, Any]:"""OpenAI-compatible chat completion (non-streaming)."""llm = _require_model()if not req.messages:raise HTTPException(status_code=400, detail="`messages` must not be empty.")# Base model (no chat template): use raw text completion instead of a chat# template the model was never trained on.if not CHAT_FORMAT:try:with _llm_lock:return _raw_chat_completion(llm, req)except Exception as exc:raise HTTPException(status_code=500, detail=f"generation failed: {exc}") from exckwargs: Dict[str, Any] = dict(messages=[m.model_dump() for m in req.messages],temperature=req.temperature,top_p=req.top_p,max_tokens=req.max_tokens if req.max_tokens is not None else DEFAULT_MAX_TOKENS,stop=req.stop,)# Honour OpenAI JSON mode -> llama.cpp constrains generation to valid JSON.if req.response_format and req.response_format.get("type") == "json_object":kwargs["response_format"] = {"type": "json_object"}try:with _llm_lock: # serialise access to the single llama.cpp contextresult = llm.create_chat_completion(**kwargs)except Exception as exc:raise HTTPException(status_code=500, detail=f"generation failed: {exc}") from exc# llama-cpp already returns an OpenAI-shaped dict; normalise id/model/created.result["id"] = result.get("id") or f"chatcmpl-{uuid.uuid4().hex}"result["model"] = MODEL_IDresult["created"] = result.get("created") or int(time.time())return result@app.post("/generate")def generate(req: GenerateRequest) -> Dict[str, Any]:"""Simplified endpoint: one prompt in, generated text out (plus timing)."""llm = _require_model()t0 = time.time()try:with _llm_lock:if not CHAT_FORMAT: # base model -> raw continuation of the promptraw = llm.create_completion(prompt=req.prompt,temperature=req.temperature,max_tokens=req.max_tokens)result = {"choices": [{"message": {"content": raw["choices"][0]["text"]}}],"usage": raw.get("usage", {}),}else:result = llm.create_chat_completion(messages=[{"role": "user", "content": req.prompt}],temperature=req.temperature,max_tokens=req.max_tokens,)except Exception as exc:raise HTTPException(status_code=500, detail=f"generation failed: {exc}") from excusage = result.get("usage", {}) or {}return {"prompt": req.prompt,"response": result["choices"][0]["message"]["content"],"model": MODEL_ID,"time_seconds": round(time.time() - t0, 2),"output_tokens": usage.get("completion_tokens"),}1234567891011121312 unmodified lines262728293031323334358 unmodified lines44454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071086 unmodified lines115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210"""GGUF LLM API for Hugging Face Spaces (Docker SDK) — runtime-swappable models.Downloads a .gguf from a HF model repo, loads it with llama-cpp-python andserves an OpenAI-compatible API. The initial model comes from environmentvariables; afterwards a NEW model can be loaded at runtime via POST /admin/load— no Space variable change, therefore NO image rebuild.Environment variables (initial model only):REPO_ID, FILENAME, HF_TOKEN, MODEL_ID, N_CTX, N_THREADS, N_GPU_LAYERS,CHAT_FORMAT ("" = auto from GGUF metadata), DEFAULT_MAX_TOKENS"""import osimport time12 unmodified lineslogging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")log = logging.getLogger("gguf-api")# DeepSeek-LLM chat template — not built into llama-cpp-python, and TheBloke's# 2023 GGUFs predate embedded chat_template metadata. Registered here so this# Space can keep serving deepseek-7b-chat (its default model).@llama_chat_format.register_chat_format("deepseek")def _format_deepseek(messages, **kwargs) -> llama_chat_format.ChatFormatterResponse:prompt = ""8 unmodified linesprompt += "Assistant:"return llama_chat_format.ChatFormatterResponse(prompt=prompt, stop=["User:"])HF_TOKEN = os.getenv("HF_TOKEN") or NoneN_CTX = int(os.getenv("N_CTX", "4096"))_USABLE = len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else (os.cpu_count() or 4)N_THREADS = int(os.getenv("N_THREADS", str(_USABLE)))N_GPU_LAYERS = int(os.getenv("N_GPU_LAYERS", "0"))DEFAULT_MAX_TOKENS = int(os.getenv("DEFAULT_MAX_TOKENS", "512"))# Current model state (mutable at runtime via /admin/load)._llm: Optional[Llama] = None_llm_lock = threading.Lock()_load_error: Optional[str] = None_loading: bool = False_cfg: Dict[str, str] = {"repo_id": os.getenv("REPO_ID", "TheBloke/deepseek-llm-7B-chat-GGUF").strip(),"filename": os.getenv("FILENAME", "deepseek-llm-7b-chat.Q4_K_M.gguf").strip(),"model_id": (os.getenv("MODEL_ID", "") or "deepseek-7b-chat").strip(),"chat_format": os.getenv("CHAT_FORMAT", "deepseek").strip(),}def _download_and_load(cfg: Dict[str, str]) -> None:"""Download cfg's .gguf and load it, replacing the current model."""global _llm, _load_error, _loading, _cfg_loading = True_load_error = Nonetry:log.info("Downloading %s from %s ...", cfg["filename"], cfg["repo_id"])t0 = time.time()path = hf_hub_download(repo_id=cfg["repo_id"], filename=cfg["filename"],token=HF_TOKEN)log.info("Downloaded in %.1fs; loading ...", time.time() - t0)kwargs: Dict[str, Any] = dict(model_path=path, n_ctx=N_CTX,n_threads=N_THREADS, n_gpu_layers=N_GPU_LAYERS,verbose=False)if cfg["chat_format"]:kwargs["chat_format"] = cfg["chat_format"]new_llm = Llama(**kwargs)with _llm_lock: # swap atomically; old model is freed_llm = new_llm_cfg = dict(cfg)log.info("Model '%s' ready.", cfg["model_id"])except Exception as exc:_load_error = f"Failed to load {cfg['model_id']}: {exc}"log.exception(_load_error)finally:_loading = False@asynccontextmanagerasync def lifespan(app: FastAPI):# Load the initial model in the background so port 7860 opens immediately.threading.Thread(target=_download_and_load, args=(dict(_cfg),),name="model-loader", daemon=True).start()yieldapp = FastAPI(title="GGUF LLM API (runtime-swappable)", version="2.0.0", lifespan=lifespan)class ChatMessage(BaseModel):role: strcontent: str = ""6 unmodified linestop_p: float = 0.95max_tokens: Optional[int] = Nonestop: Optional[List[str]] = Noneresponse_format: Optional[Dict[str, Any]] = Noneclass GenerateRequest(BaseModel):prompt: strmax_tokens: int = Field(default=512)temperature: float = 0.7class LoadRequest(BaseModel):repo_id: strfilename: strmodel_id: strchat_format: str = "" # "" = auto from GGUF metadatadef _require_model() -> Llama:if _llm is None or _loading:raise HTTPException(503, _load_error or "Model is loading, try again shortly.")return _llm@app.get("/health")def health() -> Dict[str, Any]:return {"status": "ok" if (_llm is not None and not _loading) else "loading_or_error","model": _cfg["model_id"], "repo_id": _cfg["repo_id"],"filename": _cfg["filename"], "chat_format": _cfg["chat_format"],"loading": _loading, "n_ctx": N_CTX, "n_threads": N_THREADS,"n_gpu_layers": N_GPU_LAYERS, "error": _load_error,}@app.post("/admin/load")def admin_load(req: LoadRequest) -> Dict[str, Any]:"""Load a different GGUF at runtime (async; poll /health until status ok)."""global _loadingif _loading:raise HTTPException(409, "another model is already loading")cfg = {"repo_id": req.repo_id.strip(), "filename": req.filename.strip(),"model_id": req.model_id.strip(), "chat_format": req.chat_format.strip()}threading.Thread(target=_download_and_load, args=(cfg,),name="model-loader", daemon=True).start()return {"status": "loading", "model": cfg["model_id"]}@app.get("/v1/models")def list_models() -> Dict[str, Any]:return {"object": "list","data": [{"id": _cfg["model_id"], "object": "model", "owned_by": "local"}]}@app.post("/v1/chat/completions")def chat_completions(req: ChatCompletionRequest) -> Dict[str, Any]:llm = _require_model()if not req.messages:raise HTTPException(400, "`messages` must not be empty.")kwargs: Dict[str, Any] = dict(messages=[m.model_dump() for m in req.messages],temperature=req.temperature, top_p=req.top_p,max_tokens=req.max_tokens if req.max_tokens is not None else DEFAULT_MAX_TOKENS,stop=req.stop,)if req.response_format and req.response_format.get("type") == "json_object":kwargs["response_format"] = {"type": "json_object"}try:with _llm_lock:result = llm.create_chat_completion(**kwargs)except Exception as exc:raise HTTPException(500, f"generation failed: {exc}") from excresult["id"] = result.get("id") or f"chatcmpl-{uuid.uuid4().hex}"result["model"] = _cfg["model_id"]result["created"] = result.get("created") or int(time.time())return result@app.post("/generate")def generate(req: GenerateRequest) -> Dict[str, Any]:llm = _require_model()t0 = time.time()try:with _llm_lock:result = llm.create_chat_completion(messages=[{"role": "user", "content": req.prompt}],temperature=req.temperature, max_tokens=req.max_tokens)except Exception as exc:raise HTTPException(500, f"generation failed: {exc}") from excusage = result.get("usage", {}) or {}return {"prompt": req.prompt,"response": result["choices"][0]["message"]["content"],"model": _cfg["model_id"],"time_seconds": round(time.time() - t0, 2),"output_tokens": usage.get("completion_tokens")}
123456789101112# Pinned for reproducible Hugging Face Space builds.# Bump these only deliberately — a floating llama-cpp-python version is the most# common cause of a Space that built yesterday and fails to build today.fastapi==0.115.6uvicorn[standard]==0.34.0pydantic==2.10.4huggingface_hub==0.27.1# llama-cpp-python is compiled from source in the Dockerfile (needs gcc/g++/make/cmake).# 0.3.x ships the current llama.cpp; CPU-only build is the default.llama-cpp-python==0.3.712345678910111213# Pinned for reproducible builds. ALL packages must install as prebuilt wheels# (the Alpine image ships no compiler - see Dockerfile --only-binary).fastapi==0.115.6# plain uvicorn (not [standard]): avoids uvloop/httptools, which may lack# musllinux wheels for this pin - h11 worker is fine for a single-model server.uvicorn==0.34.0pydantic==2.10.4huggingface_hub==0.27.1# musl (Alpine) prebuilt CPU wheel from abetlen's index - 2025 llama.cpp with# qwen3 / gemma3 / granite architecture support.llama-cpp-python==0.3.19
Dockerfile+13-33
main.py+101-216
requirements.txt+8-7