import os
import subprocess
import sys

def run_cmd(cmd):
    print(f"\n[EXEC] {cmd}")
    subprocess.run(cmd, shell=True, check=True)

def main():
    print("=== AI Node Setup & Launcher for GTX 1070 (Windows) ===")

    # 1. Setup Python Virtual Environment for utilities/bridges if needed
    if not os.path.exists("venv"):
        run_cmd("python -m venv venv")

    # Activate venv syntax check or direct pip execution via venv path
    pip_path = os.path.join("venv", "Scripts", "pip")
    python_path = os.path.join("venv", "Scripts", "python")

    run_cmd(f"{pip_path} install --upgrade pip requests")

    print("\n--- Model Backend Instructions ---")
    print("1. OLLAMA (Text Models):")
    print("   Make sure Ollama is installed on Windows (from ollama.com).")
    print("   To allow your Linux server to access it, set environment variable OLLAMA_HOST=0.0.0.0:11434")
    print("   Pull a lightweight 8GB-friendly model via CMD: ollama run qwen2.5:7b-instruct-q4_K_M")

    print("\n2. STABLE DIFFUSION (AUTOMATIC1111 / Forge):")
    print("   Launch your WebUI batch file with flags for your GTX 1070:")
    print("   webui-user.bat --medvram --api --listen")
    print("   (--listen opens it to your LAN; --api enables the endpoint for PHP)")

if __name__ == "__main__":
    main()
