Spaces:
Runtime error
Runtime error
Commit Β·
175b600
1
Parent(s): 3bce6e3
Update Cell 1 & 2 with user-verified working versions
Browse filesCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- colab/train_colab.py +31 -47
colab/train_colab.py
CHANGED
|
@@ -18,90 +18,74 @@
|
|
| 18 |
# ============================================================
|
| 19 |
import subprocess, os, sys
|
| 20 |
|
| 21 |
-
print(f"Python {sys.version}
|
| 22 |
|
| 23 |
-
# ββ Install packages βββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
-
# audioop-lts is only for Python 3.13+ (Colab uses 3.12)
|
| 25 |
packages = [
|
| 26 |
"openenv", "stable-baselines3", "sb3-contrib", "gymnasium",
|
| 27 |
"sentence-transformers", "openai", "pyyaml", "trl",
|
| 28 |
-
"transformers", "datasets", "torch", "matplotlib",
|
|
|
|
| 29 |
]
|
| 30 |
if sys.version_info >= (3, 13):
|
| 31 |
packages.append("audioop-lts")
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
if result.returncode != 0:
|
| 37 |
-
print(result.stdout[-3000:])
|
| 38 |
print(result.stderr[-3000:])
|
| 39 |
-
raise RuntimeError("pip install failed
|
| 40 |
-
print("Packages OK
|
| 41 |
|
| 42 |
-
# ββ Clone or update repo βββββββββββββββββββββββββββββββββββββ
|
| 43 |
-
# The GitHub repo IS the spindleflow-rl project root.
|
| 44 |
-
# It clones to /content/kuchbhi/ β that IS the working directory.
|
| 45 |
REPO = "/content/kuchbhi"
|
| 46 |
GIT_URL = "https://github.com/garvitsachdevaa/kuchbhi.git"
|
| 47 |
|
| 48 |
if not os.path.isdir(os.path.join(REPO, ".git")):
|
| 49 |
-
|
| 50 |
-
subprocess.run(["rm", "-rf", REPO]) # remove partial clone if any
|
| 51 |
-
subprocess.run(["git", "clone", GIT_URL], cwd="/content", check=True)
|
| 52 |
print("Repo cloned")
|
| 53 |
else:
|
| 54 |
-
# Already cloned β pull latest
|
| 55 |
subprocess.run(["git", "pull"], cwd=REPO, check=True)
|
| 56 |
print("Repo updated")
|
| 57 |
|
| 58 |
-
# ββ Set working directory ββββββββββββββββββββββββββββββββββββ
|
| 59 |
os.chdir(REPO)
|
| 60 |
-
|
| 61 |
-
sys.path.insert(0, ".")
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
os.makedirs(
|
| 66 |
-
os.makedirs("/content/logs", exist_ok=True)
|
| 67 |
|
| 68 |
-
|
| 69 |
-
print(
|
| 70 |
-
print(f"CWD : {os.getcwd()}")
|
| 71 |
-
print("\nCELL 1 done β")
|
| 72 |
|
| 73 |
|
| 74 |
# ============================================================
|
| 75 |
-
# CELL 2 β Load secrets
|
| 76 |
# ============================================================
|
| 77 |
import os
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
HF_TOKEN = userdata.get("HF_TOKEN")
|
| 81 |
-
OPENAI_API_KEY = userdata.get("OPENAI_API_KEY")
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
if not HF_TOKEN:
|
| 84 |
raise RuntimeError(
|
| 85 |
-
"HF_TOKEN
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
-
" Value: hf_xxxx (write token from hf.co/settings/tokens)\n"
|
| 89 |
-
" Toggle Notebook access ON"
|
| 90 |
)
|
| 91 |
if not OPENAI_API_KEY:
|
| 92 |
-
|
| 93 |
-
"OPENAI_API_KEY missing.\n"
|
| 94 |
-
"Key icon (left sidebar) β Add secret\n"
|
| 95 |
-
" Name: OPENAI_API_KEY\n"
|
| 96 |
-
" Value: sk-xxxx\n"
|
| 97 |
-
" Toggle Notebook access ON"
|
| 98 |
-
)
|
| 99 |
|
|
|
|
| 100 |
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
| 101 |
|
| 102 |
print(f"HF_TOKEN : {HF_TOKEN[:8]}...{HF_TOKEN[-4:]}")
|
| 103 |
-
print(f"OPENAI_API_KEY : {OPENAI_API_KEY
|
| 104 |
-
print("
|
| 105 |
|
| 106 |
|
| 107 |
# ============================================================
|
|
|
|
| 18 |
# ============================================================
|
| 19 |
import subprocess, os, sys
|
| 20 |
|
| 21 |
+
print(f"Python {sys.version}")
|
| 22 |
|
|
|
|
|
|
|
| 23 |
packages = [
|
| 24 |
"openenv", "stable-baselines3", "sb3-contrib", "gymnasium",
|
| 25 |
"sentence-transformers", "openai", "pyyaml", "trl",
|
| 26 |
+
"transformers", "datasets", "torch", "matplotlib",
|
| 27 |
+
"huggingface_hub", "python-dotenv",
|
| 28 |
]
|
| 29 |
if sys.version_info >= (3, 13):
|
| 30 |
packages.append("audioop-lts")
|
| 31 |
|
| 32 |
+
result = subprocess.run(
|
| 33 |
+
["pip", "install", "-q"] + packages,
|
| 34 |
+
capture_output=True, text=True
|
| 35 |
+
)
|
| 36 |
if result.returncode != 0:
|
|
|
|
| 37 |
print(result.stderr[-3000:])
|
| 38 |
+
raise RuntimeError("pip install failed")
|
| 39 |
+
print("Packages OK")
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
REPO = "/content/kuchbhi"
|
| 42 |
GIT_URL = "https://github.com/garvitsachdevaa/kuchbhi.git"
|
| 43 |
|
| 44 |
if not os.path.isdir(os.path.join(REPO, ".git")):
|
| 45 |
+
subprocess.run(["git", "clone", "--depth=1", GIT_URL], cwd="/content", check=True)
|
|
|
|
|
|
|
| 46 |
print("Repo cloned")
|
| 47 |
else:
|
|
|
|
| 48 |
subprocess.run(["git", "pull"], cwd=REPO, check=True)
|
| 49 |
print("Repo updated")
|
| 50 |
|
|
|
|
| 51 |
os.chdir(REPO)
|
| 52 |
+
sys.path.insert(0, REPO)
|
|
|
|
| 53 |
|
| 54 |
+
for d in ["/content/demo/assets", "/content/data",
|
| 55 |
+
"/content/checkpoints", "/content/logs"]:
|
| 56 |
+
os.makedirs(d, exist_ok=True)
|
|
|
|
| 57 |
|
| 58 |
+
print(f"CWD: {os.getcwd()}")
|
| 59 |
+
print("CELL 1 done β")
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
# ============================================================
|
| 63 |
+
# CELL 2 β Load secrets (with clear error messages)
|
| 64 |
# ============================================================
|
| 65 |
import os
|
| 66 |
+
try:
|
| 67 |
+
from google.colab import userdata
|
| 68 |
+
HF_TOKEN = userdata.get("HF_TOKEN")
|
| 69 |
+
OPENAI_API_KEY = userdata.get("OPENAI_API_KEY")
|
| 70 |
+
except Exception:
|
| 71 |
+
HF_TOKEN = ""
|
| 72 |
+
OPENAI_API_KEY = ""
|
| 73 |
|
| 74 |
if not HF_TOKEN:
|
| 75 |
raise RuntimeError(
|
| 76 |
+
"HF_TOKEN not found.\n"
|
| 77 |
+
"Click the π icon β Add secret β Name: HF_TOKEN β toggle Notebook access ON\n"
|
| 78 |
+
"Then Runtime β Restart and run all."
|
|
|
|
|
|
|
| 79 |
)
|
| 80 |
if not OPENAI_API_KEY:
|
| 81 |
+
print("β οΈ No OPENAI_API_KEY β simulation mode (no LLM calls, faster training)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
os.environ["HF_TOKEN"] = HF_TOKEN
|
| 84 |
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
| 85 |
|
| 86 |
print(f"HF_TOKEN : {HF_TOKEN[:8]}...{HF_TOKEN[-4:]}")
|
| 87 |
+
print(f"OPENAI_API_KEY : {'set' if OPENAI_API_KEY else 'NOT SET β simulation mode'}")
|
| 88 |
+
print("CELL 2 done β")
|
| 89 |
|
| 90 |
|
| 91 |
# ============================================================
|