Arshit Malik commited on
Commit
7509dd0
·
0 Parent(s):

initial: OpenClaw + custom 70B IQ2_XS + Telegram

Browse files
Files changed (3) hide show
  1. Dockerfile +18 -0
  2. SOUL.md +27 -0
  3. start.sh +157 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim-bookworm
2
+
3
+ RUN apt-get update && apt-get install -y \
4
+ curl nginx cron procps git \
5
+ && rm -rf /var/lib/apt/lists/*
6
+
7
+ RUN curl -fsSL https://ollama.com/install.sh | sh
8
+
9
+ RUN pip install --no-cache-dir openclaw huggingface_hub
10
+
11
+ RUN printf 'server {\n listen 7860;\n location / {\n proxy_pass http://127.0.0.1:8080;\n proxy_http_version 1.1;\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection "upgrade";\n proxy_set_header Host $host;\n }\n}\n' > /etc/nginx/sites-available/default
12
+
13
+ WORKDIR /app
14
+ COPY . .
15
+ RUN chmod +x start.sh
16
+
17
+ EXPOSE 7860
18
+ CMD ["/app/start.sh"]
SOUL.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # YT Pipeline Assistant
2
+
3
+ You are the AI assistant for a YouTube Shorts automation pipeline. You run on a Hugging Face Space with DeepSeek R1 Distill Llama 70B via Ollama.
4
+
5
+ ## Your Environment
6
+ - **You**: OpenClaw on HF Space `yt-claw`
7
+ - **Pipeline**: HF Space `yt-flow` (automation.py orchestrates Kaggle kernels)
8
+ - **Codebase for editing**: `/app/yt-flow/` — git-enabled, you can commit and push
9
+ - **State backup**: `~/.openclaw/` synced to HF Dataset every 15 min
10
+
11
+ ## Pipeline Steps
12
+ 1. CONTENT — Kaggle kernel with DeepSeek-R1-32B GGUF
13
+ 2. FLUX — Kaggle kernel generates images
14
+ 3. TTS — Kaggle kernel with StyleTTS2 + Whisper
15
+
16
+ ## Your Capabilities
17
+ - Read pipeline logs at `https://arshitmalik-yt-flow.hf.space`
18
+ - Edit code in `/app/yt-flow/` and push (git add → commit → push)
19
+ - HF auto-rebuilds yt-flow on push
20
+ - Debug Kaggle kernel failures by analyzing kernel output
21
+ - Monitor topic/fact history to avoid repetition
22
+
23
+ ## Common Bugs You Can Fix
24
+ - Kaggle 429 → increase time.sleep between kernel pushes
25
+ - llama-cpp build failure → use --only-binary :all: in pip install
26
+ - Space paused → check Ollama memory, reduce context if needed
27
+ - YouTube auth expired → remind user to run auth_youtube.py from Mac
start.sh ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "[boot] Creating 10 GB swap..."
5
+ fallocate -l 10G /swapfile 2>/dev/null || dd if=/dev/zero of=/swapfile bs=1M count=10240 2>/dev/null
6
+ chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
7
+
8
+ echo "[boot] Pulling OpenClaw state..."
9
+ python3 -c "
10
+ import sys, os; sys.path.insert(0, '/app')
11
+ HF_TOKEN = os.environ.get('HF_TOKEN', '')
12
+ DATASET_REPO = os.environ.get('OPENCLAW_DATASET_REPO', '')
13
+ if HF_TOKEN and DATASET_REPO:
14
+ from huggingface_hub import hf_hub_download
15
+ from huggingface_hub.utils import EntryNotFoundError
16
+ for fname in ['openclaw.json', 'SOUL.md']:
17
+ try:
18
+ hf_hub_download(repo_id=DATASET_REPO, filename=f'openclaw/{fname}',
19
+ repo_type='dataset', token=HF_TOKEN,
20
+ local_dir='/root', local_dir_use_symlinks=False)
21
+ except EntryNotFoundError: pass
22
+ except Exception as e: print(f' {e}')
23
+ "
24
+
25
+ echo "[boot] Configuring OpenClaw..."
26
+ mkdir -p ~/.openclaw
27
+ cat > ~/.openclaw/openclaw.json << JSONEOF
28
+ {
29
+ "gateway": {"port": 8080, "bind": "0.0.0.0"},
30
+ "identity": {"name": "YT Pipeline Assistant"},
31
+ "channels": {
32
+ "telegram": {
33
+ "enabled": true,
34
+ "botToken": "${TELEGRAM_BOT_TOKEN}",
35
+ "dmPolicy": "pairing"
36
+ }
37
+ },
38
+ "models": {
39
+ "providers": {
40
+ "ollama": {
41
+ "baseUrl": "http://127.0.0.1:11434/v1",
42
+ "apiKey": "ollama-local",
43
+ "api": "openai-chat",
44
+ "models": [
45
+ {
46
+ "id": "deepseek-r1-70b",
47
+ "name": "DeepSeek R1 Distill Llama 70B IQ2_XS",
48
+ "contextWindow": 131072,
49
+ "maxTokens": 8192
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ },
55
+ "agents": {
56
+ "defaults": {
57
+ "model": {"primary": "ollama/deepseek-r1-70b"},
58
+ "workspace": "/app/yt-flow"
59
+ }
60
+ }
61
+ }
62
+ JSONEOF
63
+
64
+ [ -f /app/SOUL.md ] && cp /app/SOUL.md ~/.openclaw/SOUL.md
65
+
66
+ git config --global user.name "YT Pipeline Bot"
67
+ git config --global user.email "yt-pipe-bot@hf.space"
68
+ git clone https://arshitmalik:${HF_TOKEN}@huggingface.co/spaces/arshitmalik/yt-flow /app/yt-flow 2>/dev/null || true
69
+
70
+ # Backup cron
71
+ cat > /tmp/backup.sh << 'CRONEOF'
72
+ #!/bin/bash
73
+ python3 -c "
74
+ import os, sys; sys.path.insert(0, '/app')
75
+ HF_TOKEN = os.environ.get('HF_TOKEN', '')
76
+ DATASET_REPO = os.environ.get('OPENCLAW_DATASET_REPO', '')
77
+ if not HF_TOKEN or not DATASET_REPO: sys.exit(0)
78
+ from huggingface_hub import HfApi
79
+ api = HfApi(token=HF_TOKEN)
80
+ from pathlib import Path
81
+ for f in Path('/root/.openclaw').glob('*'):
82
+ if f.is_file():
83
+ try:
84
+ api.upload_file(
85
+ path_or_fileobj=str(f),
86
+ path_in_repo=f'openclaw/{f.name}',
87
+ repo_id=DATASET_REPO,
88
+ repo_type='dataset'
89
+ )
90
+ except Exception as e: pass
91
+ " 2>/dev/null
92
+ CRONEOF
93
+ chmod +x /tmp/backup.sh
94
+ echo "*/15 * * * * /tmp/backup.sh" | crontab -
95
+
96
+ # Temporary health server (keeps Space alive during setup)
97
+ python3 -c "
98
+ from http.server import HTTPServer, BaseHTTPRequestHandler
99
+ class H(BaseHTTPRequestHandler):
100
+ def do_GET(self):
101
+ self.send_response(200); self.end_headers(); self.wfile.write(b'ok')
102
+ HTTPServer(('0.0.0.0', 8080), H).serve_forever()
103
+ " &
104
+ HEALTH_PID=$!
105
+
106
+ echo "[boot] Starting nginx..."
107
+ nginx
108
+
109
+ echo "[boot] Starting Ollama..."
110
+ export OLLAMA_FLASH_ATTENTION=1
111
+ export OLLAMA_KV_CACHE_TYPE=q4_0
112
+ OLLAMA_HOST=127.0.0.1 OLLAMA_NUM_PARALLEL=1 OLLAMA_MAX_LOADED_MODELS=1 ollama serve &
113
+
114
+ for i in $(seq 1 30); do
115
+ if curl -sf http://127.0.0.1:11434/api/tags > /dev/null 2>&1; then
116
+ echo "[boot] Ollama ready after ${i}s"; break
117
+ fi
118
+ sleep 2
119
+ done
120
+
121
+ echo "[boot] Building custom 70B IQ2_XS model (~3 min)..."
122
+ python3 << PYEOF
123
+ import subprocess, sys, os
124
+ from pathlib import Path
125
+ from huggingface_hub import hf_hub_download
126
+
127
+ gguf_path = hf_hub_download(
128
+ repo_id="bartowski/DeepSeek-R1-Distill-Llama-70B-GGUF",
129
+ filename="DeepSeek-R1-Distill-Llama-70B-IQ2_XS.gguf",
130
+ local_dir="/tmp/gguf",
131
+ resume_download=True,
132
+ token=os.environ.get("HF_TOKEN", None)
133
+ )
134
+ modelfile = f"""FROM {gguf_path}
135
+ TEMPLATE \"\"\"<|begin▁of▁sentence|>{{ .System }}
136
+
137
+ {{ .Prompt }}<|end▁of▁sentence|>
138
+ <|begin▁of▁sentence|>assistant
139
+ \"\"\"
140
+ PARAMETER stop "<|begin▁of▁sentence|>"
141
+ PARAMETER stop "<|end▁of▁sentence|>"
142
+ PARAMETER num_ctx 131072
143
+ PARAMETER num_predict 8192
144
+ """
145
+ (Path("/tmp") / "Modelfile").write_text(modelfile)
146
+ subprocess.run(["ollama", "create", "deepseek-r1-70b", "-f", "/tmp/Modelfile"], check=True)
147
+ Path(gguf_path).unlink()
148
+ PYEOF
149
+
150
+ # Kill temp health server, start OpenClaw
151
+ kill $HEALTH_PID 2>/dev/null
152
+ echo "[boot] Starting OpenClaw gateway..."
153
+ openclaw gateway &
154
+ OPENCLAW_PID=$!
155
+ echo "[boot] Deployment complete. PID: $OPENCLAW_PID"
156
+ wait $OPENCLAW_PID 2>/dev/null
157
+ sleep infinity