import os import subprocess import time import shutil print("==================================================") print("🚀 Starting Cloudix Linux Desktop on Hugging Face") print("==================================================") # ZeroGPU initialization try: import spaces @spaces.GPU def gpu_init(): return "GPU ready" except Exception as e: pass os.environ["DISPLAY"] = ":1" # 1. Start Xvfb (Virtual Screen Display) print("[1/4] Starting Xvfb virtual display (:1)...") subprocess.Popen(["Xvfb", ":1", "-screen", "0", "1280x720x24"]) time.sleep(1.5) # 2. Start XFCE4 Desktop Session print("[2/4] Starting XFCE4 Desktop Session...") subprocess.Popen(["dbus-launch", "xfce4-session"]) time.sleep(2) # 3. Start x11vnc server print("[3/4] Starting x11vnc server on port 5900...") subprocess.Popen([ "x11vnc", "-display", ":1", "-nopw", "-listen", "127.0.0.1", "-xkb", "-forever", "-shared", "-noxdamage" ]) time.sleep(1.5) # 4. Prepare noVNC directory & autoconnect index novnc_dir = "/usr/share/novnc" target_dir = "/tmp/novnc_web" if os.path.exists(target_dir): shutil.rmtree(target_dir) if os.path.exists(novnc_dir): shutil.copytree(novnc_dir, target_dir) else: os.makedirs(target_dir, exist_ok=True) vnc_html_path = os.path.join(target_dir, "vnc.html") index_html_path = os.path.join(target_dir, "index.html") if os.path.exists(vnc_html_path): with open(vnc_html_path, "r", encoding="utf-8") as f: content = f.read() content = content.replace("
", '') with open(index_html_path, "w", encoding="utf-8") as f: f.write(content) print("[4/4] Starting WebSockify Gateway on port 7860...") cmd = [ "websockify", f"--web={target_dir}", "7860", "127.0.0.1:5900" ] print("==================================================") print("✅ Cloudix Linux Desktop Ready on Port 7860!") print("==================================================") subprocess.run(cmd)