Upload temp_files.py
Browse files- scripts/temp_files.py +55 -0
scripts/temp_files.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# temp_files.py
|
| 3 |
+
import os
|
| 4 |
+
import subprocess
|
| 5 |
+
import pickle
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
# -------------- configuración --------------
|
| 9 |
+
STORE_FILE = Path.home() / ".civitai_token.pkl"
|
| 10 |
+
TOKEN_CIVITAI = "" # valor por defecto
|
| 11 |
+
# -------------------------------------------
|
| 12 |
+
|
| 13 |
+
def leer_token() -> str:
|
| 14 |
+
"""Devuelve el token en este orden:
|
| 15 |
+
1) archivo pickle, 2) env-var, 3) valor por defecto."""
|
| 16 |
+
if STORE_FILE.exists():
|
| 17 |
+
return pickle.loads(STORE_FILE.read_bytes())
|
| 18 |
+
return os.getenv("CIVITAI_TOKEN", TOKEN_CIVITAI)
|
| 19 |
+
|
| 20 |
+
def guardar_token(val: str) -> None:
|
| 21 |
+
"""Persiste el token."""
|
| 22 |
+
if not val.strip():
|
| 23 |
+
print("⚠️ No se ingresó token.")
|
| 24 |
+
return
|
| 25 |
+
STORE_FILE.write_bytes(pickle.dumps(val))
|
| 26 |
+
print(f"✅ Token guardado en {STORE_FILE}")
|
| 27 |
+
|
| 28 |
+
def _run(cmd: str) -> None:
|
| 29 |
+
print(f"+ {cmd}")
|
| 30 |
+
subprocess.run(cmd, shell=True, check=False)
|
| 31 |
+
|
| 32 |
+
def preparar():
|
| 33 |
+
"""Prepara enlaces para sd-webui-forge-classic."""
|
| 34 |
+
token = leer_token()
|
| 35 |
+
guardar_token(token) # lo re-escribe (por si acaso)
|
| 36 |
+
|
| 37 |
+
cmds = [
|
| 38 |
+
"rm -rf /teamspace/studios/this_studio/tmp ~/tmp",
|
| 39 |
+
"ln -vs /tmp ~/tmp",
|
| 40 |
+
"rm -rf /teamspace/studios/this_studio/sd-webui-forge-classic/models/Stable-diffusion/tmp_models",
|
| 41 |
+
"mkdir -p /tmp/models",
|
| 42 |
+
"ln -vs /tmp/models /teamspace/studios/this_studio/sd-webui-forge-classic/models/Stable-diffusion/tmp_models",
|
| 43 |
+
"rm -rf /teamspace/studios/this_studio/sd-webui-forge-classic/models/Lora/tmp_lora",
|
| 44 |
+
"mkdir -p /tmp/lora",
|
| 45 |
+
"ln -vs /tmp/lora /teamspace/studios/this_studio/sd-webui-forge-classic/models/Lora/tmp_lora",
|
| 46 |
+
"rm -rf /teamspace/studios/this_studio/sd-webui-forge-classic/models/ControlNet",
|
| 47 |
+
"mkdir -p /tmp/controlnet",
|
| 48 |
+
"ln -vs /tmp/controlnet /teamspace/studios/this_studio/sd-webui-forge-classic/models/ControlNet",
|
| 49 |
+
]
|
| 50 |
+
for c in cmds:
|
| 51 |
+
_run(c)
|
| 52 |
+
print("🎉 Entorno Forge listo.")
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
preparar()
|