Upload 2 files
Browse files- Swarmui_Lightning/on_start.sh +22 -0
- Swarmui_Lightning/symb.py +62 -0
Swarmui_Lightning/on_start.sh
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# This script runs every time your Studio starts, from your home directory.
|
| 4 |
+
echo "Preparando carpetas temporales..."
|
| 5 |
+
python ~/symb.py
|
| 6 |
+
|
| 7 |
+
# Logs from previous runs can be found in ~/.lightning_studio/logs/
|
| 8 |
+
|
| 9 |
+
# aseg\u00farate de que la ruta sea correcta desde la ra\u00edz de tu studio
|
| 10 |
+
|
| 11 |
+
# LD_PRELOAD se establece para esta \u00fanica ejecuci\u00f3n, y el '&' lo env\u00eda al fondo.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# List files under fast_load that need to load quickly on start (e.g. model checkpoints).
|
| 15 |
+
#
|
| 16 |
+
# ! fast_load
|
| 17 |
+
# <your file here>
|
| 18 |
+
|
| 19 |
+
# Add your startup commands below.
|
| 20 |
+
#
|
| 21 |
+
# Example: streamlit run my_app.py
|
| 22 |
+
# Example: gradio my_app.py
|
Swarmui_Lightning/symb.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# setup_civitai.py
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
# ---------- configuración ----------
|
| 7 |
+
TOKEN_CIVITAI = "4487c60c8a71cbfe100a7a03ad9e6ae9"
|
| 8 |
+
STORE_FILE = Path.home() / ".civitai_token.pkl" # sustituto de %store
|
| 9 |
+
# -----------------------------------
|
| 10 |
+
|
| 11 |
+
def _store(var: str, val: str) -> None:
|
| 12 |
+
"""Simula %store var val (persistente entre kernels)."""
|
| 13 |
+
import pickle, builtins
|
| 14 |
+
# escribe en el archivo
|
| 15 |
+
data = {var: val}
|
| 16 |
+
STORE_FILE.write_bytes(pickle.dumps(data))
|
| 17 |
+
# opcional: también lo deja disponible en builtins para este kernel
|
| 18 |
+
setattr(builtins, var, val)
|
| 19 |
+
print(f"✅ Variable '{var}' guardada en {STORE_FILE} (persistente).")
|
| 20 |
+
|
| 21 |
+
def _run(cmd: str) -> None:
|
| 22 |
+
"""Ejecuta un comando shell y muestra la salida."""
|
| 23 |
+
print(f"+ {cmd}")
|
| 24 |
+
subprocess.run(cmd, shell=True, check=False)
|
| 25 |
+
|
| 26 |
+
def preparar():
|
| 27 |
+
"""Función principal: guarda el token y crea enlaces."""
|
| 28 |
+
if not TOKEN_CIVITAI.strip():
|
| 29 |
+
print("⚠️ No se ingresó token.")
|
| 30 |
+
return
|
| 31 |
+
_store("token_civitai", TOKEN_CIVITAI)
|
| 32 |
+
|
| 33 |
+
# limpieza y enlaces
|
| 34 |
+
cmds = [
|
| 35 |
+
"rm -rf /teamspace/studios/this_studio/.cache",
|
| 36 |
+
"rm -rf /teamspace/studios/this_studio/tmp ~/tmp",
|
| 37 |
+
"ln -vs /tmp ~/tmp",
|
| 38 |
+
"rm -rf /teamspace/studios/this_studio/SwarmUI/Models/Stable-Diffusion/tmp_models",
|
| 39 |
+
"mkdir -p /tmp/models",
|
| 40 |
+
"ln -vs /tmp/models /teamspace/studios/this_studio/SwarmUI/Models/Stable-Diffusion/tmp_models",
|
| 41 |
+
"rm -rf /teamspace/studios/this_studio/SwarmUI/Models/Lora/tmp_lora",
|
| 42 |
+
"mkdir -p /tmp/lora",
|
| 43 |
+
"ln -vs /tmp/lora /teamspace/studios/this_studio/SwarmUI/Models/Lora/tmp_lora",
|
| 44 |
+
"rm -rf /teamspace/studios/this_studio/SwarmUI/Models/diffusion_models",
|
| 45 |
+
"mkdir -p /tmp/diffusion_models",
|
| 46 |
+
"ln -vs /tmp/diffusion_models /teamspace/studios/this_studio/SwarmUI/Models/diffusion_models",
|
| 47 |
+
"rm -rf /teamspace/studios/this_studio/SwarmUI/Models/text_encoders",
|
| 48 |
+
"mkdir -p /tmp/text_encoders",
|
| 49 |
+
"ln -vs /tmp/text_encoders /teamspace/studios/this_studio/SwarmUI/Models/text_encoders",
|
| 50 |
+
"rm -rf /teamspace/studios/this_studio/SwarmUI/Models/unet",
|
| 51 |
+
"mkdir -p /tmp/unet",
|
| 52 |
+
"ln -vs /tmp/unet /teamspace/studios/this_studio/SwarmUI/Models/unet",
|
| 53 |
+
"rm -rf /teamspace/studios/this_studio/SwarmUI/Models/controlnet",
|
| 54 |
+
"mkdir -p /tmp/controlnet",
|
| 55 |
+
"ln -vs /tmp/controlnet /teamspace/studios/this_studio/SwarmUI/Models/controlnet",
|
| 56 |
+
]
|
| 57 |
+
for c in cmds:
|
| 58 |
+
_run(c)
|
| 59 |
+
print("🎉 Entorno listo.")
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
preparar()
|