LuillY3 commited on
Commit
dba2d6c
Β·
verified Β·
1 Parent(s): 201c700

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +45 -0
  2. README.md +70 -0
  3. entrypoint.sh +61 -0
Dockerfile ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ──────────────────────────────────────────────
2
+ # GLM-4.6V-Flash API β€” Hugging Face Spaces
3
+ # Expone endpoint OpenAI-compatible en :7860
4
+ # ──────────────────────────────────────────────
5
+ FROM ubuntu:22.04
6
+
7
+ ENV DEBIAN_FRONTEND=noninteractive
8
+
9
+ # 1. Dependencias del sistema
10
+ RUN apt-get update && apt-get install -y \
11
+ build-essential cmake git curl wget \
12
+ python3-pip libgomp1 ca-certificates \
13
+ && rm -rf /var/lib/apt/lists/*
14
+
15
+ # 2. Instalar huggingface_hub CLI
16
+ RUN pip3 install --no-cache-dir "huggingface_hub[cli]>=0.26"
17
+
18
+ # 3. Compilar llama.cpp optimizado para CPU
19
+ RUN git clone --depth 1 https://github.com/ggerganov/llama.cpp /llama.cpp && \
20
+ cd /llama.cpp && \
21
+ cmake -B build \
22
+ -DGGML_NATIVE=OFF \
23
+ -DGGML_AVX2=ON \
24
+ -DGGML_F16C=ON \
25
+ -DGGML_FMA=ON \
26
+ -DLLAMA_BUILD_SERVER=ON && \
27
+ cmake --build build --config Release -j$(nproc) && \
28
+ cp build/bin/llama-server /usr/local/bin/llama-server && \
29
+ rm -rf /llama.cpp
30
+
31
+ # 4. Directorio de modelos
32
+ RUN mkdir -p /models
33
+
34
+ # 5. Scripts de arranque
35
+ COPY entrypoint.sh /entrypoint.sh
36
+ RUN chmod +x /entrypoint.sh
37
+
38
+ # Puerto requerido por Hugging Face Spaces
39
+ EXPOSE 7860
40
+
41
+ # Usuario no-root (obligatorio en HF Spaces)
42
+ RUN useradd -m -u 1000 hfuser && chown -R hfuser /models
43
+ USER hfuser
44
+
45
+ ENTRYPOINT ["/entrypoint.sh"]
README.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: GLM-4.6V-Flash API
3
+ emoji: πŸ€–
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ pinned: false
8
+ app_port: 7860
9
+ ---
10
+
11
+ # GLM-4.6V-Flash β€” OpenAI-Compatible API
12
+
13
+ Modelo **GLM-4.6V-Flash 9B** corriendo en CPU con soporte de **visiΓ³n nativa**,
14
+ **128K contexto** y **tool calling** multimodal.
15
+
16
+ ## Endpoint
17
+
18
+ ```
19
+ POST https://<tu-user>-glm-46v-flash-api.hf.space/v1/chat/completions
20
+ ```
21
+
22
+ ## Ejemplo con curl
23
+
24
+ ```bash
25
+ curl https://<tu-user>-glm-46v-flash-api.hf.space/v1/chat/completions \
26
+ -H "Content-Type: application/json" \
27
+ -d '{
28
+ "model": "GLM-4.6V-Flash",
29
+ "messages": [{"role": "user", "content": "Hola, ΒΏcΓ³mo estΓ‘s?"}],
30
+ "max_tokens": 512,
31
+ "temperature": 0.7
32
+ }'
33
+ ```
34
+
35
+ ## Variables de entorno configurables
36
+
37
+ | Variable | Default | DescripciΓ³n |
38
+ |---|---|---|
39
+ | `CONTEXT_SIZE` | `8192` | Tokens de contexto (mΓ‘x 128K, pero limitar en CPU) |
40
+ | `NUM_THREADS` | `2` | Hilos de CPU (HF free tier tiene 2 vCPU) |
41
+ | `MAX_TOKENS` | `1024` | MΓ‘ximo de tokens generados por respuesta |
42
+
43
+ ## Uso con imagen (visiΓ³n)
44
+
45
+ ```json
46
+ {
47
+ "model": "GLM-4.6V-Flash",
48
+ "messages": [{
49
+ "role": "user",
50
+ "content": [
51
+ {"type": "text", "text": "ΒΏQuΓ© hay en esta imagen?"},
52
+ {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
53
+ ]
54
+ }]
55
+ }
56
+ ```
57
+
58
+ ## Uso desde n8n
59
+
60
+ En el nodo **HTTP Request**:
61
+ - Method: `POST`
62
+ - URL: `https://<tu-user>-glm-46v-flash-api.hf.space/v1/chat/completions`
63
+ - Body: JSON con el formato OpenAI estΓ‘ndar
64
+
65
+ ## Notas
66
+
67
+ - ⚠️ El primer arranque descarga ~8 GB (modelo + mmproj). Esperar ~10-15 min.
68
+ - ⚠️ El disco de HF Spaces no es persistente: si el Space se reinicia, descarga nuevamente.
69
+ - πŸ’‘ Para evitar reinicios, hacer un ping cada 10 min desde n8n al endpoint `/health`.
70
+ - πŸ”’ Agregar `HF_TOKEN` como secret si querΓ©s acceder a modelos privados.
entrypoint.sh ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ MODEL_DIR="/models"
5
+ MODEL_FILE="$MODEL_DIR/GLM-4.6V-Flash-Q4_K_M.gguf"
6
+ MMPROJ_FILE="$MODEL_DIR/mmproj-GLM-4.6V-Flash-f16.gguf"
7
+
8
+ # ConfiguraciΓ³n via variables de entorno
9
+ CONTEXT="${CONTEXT_SIZE:-8192}"
10
+ THREADS="${NUM_THREADS:-2}"
11
+ MAX_TOKENS="${MAX_TOKENS:-1024}"
12
+ PORT=7860
13
+
14
+ echo "═══════════════════════════════════════════"
15
+ echo " GLM-4.6V-Flash β€” Hugging Face Space"
16
+ echo " Puerto: $PORT | Contexto: $CONTEXT | Threads: $THREADS"
17
+ echo "═══════════════════════════════════════════"
18
+
19
+ # ── Descargar modelo principal si no existe ──
20
+ if [ ! -f "$MODEL_FILE" ]; then
21
+ echo "⬇️ Descargando GLM-4.6V-Flash Q4_K_M (~6.2 GB)..."
22
+ huggingface-cli download \
23
+ bartowski/zai-org_GLM-4.6V-Flash-GGUF \
24
+ "GLM-4.6V-Flash-Q4_K_M.gguf" \
25
+ --local-dir "$MODEL_DIR" \
26
+ --local-dir-use-symlinks False
27
+ echo "βœ… Modelo descargado"
28
+ else
29
+ echo "βœ… Modelo ya existe, saltando descarga"
30
+ fi
31
+
32
+ # ── Descargar mmproj (proyector de visiΓ³n) si no existe ──
33
+ if [ ! -f "$MMPROJ_FILE" ]; then
34
+ echo "⬇️ Descargando mmproj de visiΓ³n (~1.9 GB)..."
35
+ huggingface-cli download \
36
+ bartowski/zai-org_GLM-4.6V-Flash-GGUF \
37
+ "mmproj-GLM-4.6V-Flash-f16.gguf" \
38
+ --local-dir "$MODEL_DIR" \
39
+ --local-dir-use-symlinks False
40
+ echo "βœ… mmproj descargado"
41
+ else
42
+ echo "βœ… mmproj ya existe, saltando descarga"
43
+ fi
44
+
45
+ echo ""
46
+ echo "πŸš€ Iniciando servidor llama.cpp..."
47
+ echo "πŸ“‘ Endpoint: http://0.0.0.0:$PORT/v1/chat/completions"
48
+ echo ""
49
+
50
+ exec llama-server \
51
+ --model "$MODEL_FILE" \
52
+ --mmproj "$MMPROJ_FILE" \
53
+ --host 0.0.0.0 \
54
+ --port $PORT \
55
+ --ctx-size $CONTEXT \
56
+ --threads $THREADS \
57
+ --n-predict $MAX_TOKENS \
58
+ --chat-template chatml \
59
+ --metrics \
60
+ --log-disable \
61
+ --parallel 1