Spaces:
Paused
Paused
fix: bake GGUF model into Docker image during build
Browse files- Dockerfile +7 -0
- app.py +9 -21
Dockerfile
CHANGED
|
@@ -15,6 +15,13 @@ RUN curl -sL https://github.com/ggml-org/llama.cpp/releases/download/b9208/llama
|
|
| 15 |
ldconfig && \
|
| 16 |
rm /tmp/llama.tar.gz
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
COPY requirements.txt .
|
| 19 |
RUN pip install -r requirements.txt --no-cache-dir
|
| 20 |
|
|
|
|
| 15 |
ldconfig && \
|
| 16 |
rm /tmp/llama.tar.gz
|
| 17 |
|
| 18 |
+
# 下载 GGUF 多模态模型(构建时下载,约 1.7GB)
|
| 19 |
+
RUN mkdir -p /app/models && \
|
| 20 |
+
curl -sL -o /app/models/MiniCPM-V-4.6-Q4_K_M.gguf \
|
| 21 |
+
"https://huggingface.co/ggml-org/MiniCPM-V-4.6-GGUF/resolve/main/MiniCPM-V-4.6-Q4_K_M.gguf" && \
|
| 22 |
+
curl -sL -o /app/models/mmproj-MiniCPM-V-4.6-Q8_0.gguf \
|
| 23 |
+
"https://huggingface.co/ggml-org/MiniCPM-V-4.6-GGUF/resolve/main/mmproj-MiniCPM-V-4.6-Q8_0.gguf"
|
| 24 |
+
|
| 25 |
COPY requirements.txt .
|
| 26 |
RUN pip install -r requirements.txt --no-cache-dir
|
| 27 |
|
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
"""
|
| 2 |
OpenWolf 视觉 Space — llama-server 二进制驱动(GGUF / MiniCPM-V / 多模态)
|
|
|
|
| 3 |
"""
|
| 4 |
import os, time, threading, subprocess, requests, uuid
|
| 5 |
-
from pathlib import Path
|
| 6 |
from fastapi import FastAPI, Request, HTTPException
|
| 7 |
from fastapi.responses import JSONResponse
|
| 8 |
-
from huggingface_hub import hf_hub_download
|
| 9 |
|
| 10 |
app = FastAPI(title="OpenWolf Vision")
|
| 11 |
|
|
@@ -13,10 +12,8 @@ LLAMA_PORT = 8081
|
|
| 13 |
_ready = False
|
| 14 |
_llama_proc = None
|
| 15 |
_tasks = {}
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
MODEL_FILE = "MiniCPM-V-4.6-Q4_K_M.gguf"
|
| 19 |
-
MMPROJ_FILE = "mmproj-MiniCPM-V-4.6-Q8_0.gguf"
|
| 20 |
|
| 21 |
|
| 22 |
@app.on_event("startup")
|
|
@@ -26,25 +23,16 @@ async def startup():
|
|
| 26 |
|
| 27 |
def _startup():
|
| 28 |
global _ready, _llama_proc
|
| 29 |
-
os.makedirs("/app/models", exist_ok=True)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
try:
|
| 34 |
-
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, local_dir="/app/models")
|
| 35 |
-
mmproj_path = hf_hub_download(repo_id=MODEL_REPO, filename=MMPROJ_FILE, local_dir="/app/models")
|
| 36 |
-
print(f"[startup] 下载完成 ({time.time()-t0:.1f}s)")
|
| 37 |
-
except Exception as e:
|
| 38 |
-
print(f"[startup] 下载失败: {e}")
|
| 39 |
return
|
| 40 |
|
| 41 |
print("[startup] 启动 llama-server (多模态)...")
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
"--n-gpu-layers", "0", "--threads", "2", "--ctx-size", "4096",
|
| 47 |
-
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 48 |
|
| 49 |
for _ in range(60):
|
| 50 |
time.sleep(2)
|
|
|
|
| 1 |
"""
|
| 2 |
OpenWolf 视觉 Space — llama-server 二进制驱动(GGUF / MiniCPM-V / 多模态)
|
| 3 |
+
模型已内置在 Docker 镜像中
|
| 4 |
"""
|
| 5 |
import os, time, threading, subprocess, requests, uuid
|
|
|
|
| 6 |
from fastapi import FastAPI, Request, HTTPException
|
| 7 |
from fastapi.responses import JSONResponse
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI(title="OpenWolf Vision")
|
| 10 |
|
|
|
|
| 12 |
_ready = False
|
| 13 |
_llama_proc = None
|
| 14 |
_tasks = {}
|
| 15 |
+
MODEL_PATH = "/app/models/MiniCPM-V-4.6-Q4_K_M.gguf"
|
| 16 |
+
MMPROJ_PATH = "/app/models/mmproj-MiniCPM-V-4.6-Q8_0.gguf"
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
@app.on_event("startup")
|
|
|
|
| 23 |
|
| 24 |
def _startup():
|
| 25 |
global _ready, _llama_proc
|
|
|
|
| 26 |
|
| 27 |
+
if not os.path.exists(MODEL_PATH):
|
| 28 |
+
print(f"[startup] 模型文件不存在: {MODEL_PATH}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return
|
| 30 |
|
| 31 |
print("[startup] 启动 llama-server (多模态)...")
|
| 32 |
+
args = ["llama-server", "--model", MODEL_PATH, "--mmproj", MMPROJ_PATH,
|
| 33 |
+
"--host", "127.0.0.1", "--port", str(LLAMA_PORT),
|
| 34 |
+
"--n-gpu-layers", "0", "--threads", "2", "--ctx-size", "4096"]
|
| 35 |
+
_llama_proc = subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
|
|
|
| 36 |
|
| 37 |
for _ in range(60):
|
| 38 |
time.sleep(2)
|