Spaces:
Sleeping
Sleeping
Rename DockerfileBAK to Dockerfile
Browse files- DockerfileBAK → Dockerfile +133 -28
DockerfileBAK → Dockerfile
RENAMED
|
@@ -40,7 +40,7 @@ USER user
|
|
| 40 |
ENV HOME=/home/user \
|
| 41 |
PATH=/home/user/.local/bin:$PATH
|
| 42 |
|
| 43 |
-
# 6. Write the
|
| 44 |
COPY --chown=user <<'EOF' app.py
|
| 45 |
import sys, os, io, base64, json, warnings, time
|
| 46 |
import torch
|
|
@@ -57,13 +57,14 @@ from diffusers import StableDiffusionPipeline, AutoencoderTiny, LCMScheduler
|
|
| 57 |
warnings.filterwarnings("ignore")
|
| 58 |
|
| 59 |
# ============================================================================
|
| 60 |
-
# 1. FRONTEND (React Desktop)
|
| 61 |
# ============================================================================
|
| 62 |
HTML_TEMPLATE = r"""
|
| 63 |
<!DOCTYPE html>
|
| 64 |
<html lang="en">
|
| 65 |
<head>
|
| 66 |
<meta charset="UTF-8">
|
|
|
|
| 67 |
<title>LiteWin XP - Neural OS Desktop</title>
|
| 68 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 69 |
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
|
@@ -71,27 +72,85 @@ HTML_TEMPLATE = r"""
|
|
| 71 |
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
| 72 |
<link href="https://fonts.googleapis.com/css2?family=Tahoma:wght@400;700&family=Fira+Code:wght@300;500&display=swap" rel="stylesheet">
|
| 73 |
<style>
|
| 74 |
-
body {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
.canvas-viewport {
|
| 76 |
-
position: absolute;
|
| 77 |
-
|
|
|
|
| 78 |
image-rendering: pixelated;
|
| 79 |
}
|
| 80 |
-
.canvas-viewport img { width: 100%; height: 100%; }
|
|
|
|
| 81 |
.taskbar {
|
| 82 |
-
position: absolute; bottom: 0; left: 0; right: 0; height:
|
| 83 |
background: linear-gradient(to bottom, #1F4788 0%, #1A3E6F 50%, #0E2950 100%);
|
| 84 |
-
border-top:
|
|
|
|
|
|
|
| 85 |
}
|
|
|
|
| 86 |
.start-btn {
|
| 87 |
background: linear-gradient(to bottom, #3F8B3F 0%, #2F6B2F 100%);
|
| 88 |
-
border:
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
.console-log {
|
| 92 |
-
position:
|
| 93 |
-
background: rgba(0,0,0,0.
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
</style>
|
| 97 |
</head>
|
|
@@ -99,14 +158,38 @@ HTML_TEMPLATE = r"""
|
|
| 99 |
<div id="root"></div>
|
| 100 |
<script type="text/babel">
|
| 101 |
const { useState, useEffect, useRef } = React;
|
|
|
|
| 102 |
function App() {
|
| 103 |
const [desktopImage, setDesktopImage] = useState(null);
|
| 104 |
-
const [logs, setLogs] = useState(["Neural Bios v9.
|
|
|
|
|
|
|
| 105 |
const socketRef = useRef(null);
|
| 106 |
-
const
|
| 107 |
|
| 108 |
-
const addLog = (msg) => setLogs(prev => [...prev.slice(-
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
useEffect(() => {
|
| 111 |
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';
|
| 112 |
const ws = new WebSocket(`${proto}://${window.location.host}/kernel`);
|
|
@@ -122,23 +205,40 @@ HTML_TEMPLATE = r"""
|
|
| 122 |
}, []);
|
| 123 |
|
| 124 |
const handleClick = (e) => {
|
| 125 |
-
if (!
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
const
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
};
|
| 131 |
|
| 132 |
return (
|
| 133 |
-
<div
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
</div>
|
|
|
|
| 137 |
<div className="taskbar">
|
| 138 |
<div className="start-btn">start</div>
|
| 139 |
</div>
|
|
|
|
| 140 |
<div className="console-log">
|
| 141 |
-
{logs.map((l, i) => <div key={i}>{l}</div>)}
|
| 142 |
</div>
|
| 143 |
</div>
|
| 144 |
);
|
|
@@ -232,6 +332,7 @@ class OSKernel:
|
|
| 232 |
self.processes[pid].z_order = max_z + 1
|
| 233 |
|
| 234 |
def handle_click(self, x: int, y: int) -> Dict:
|
|
|
|
| 235 |
sorted_procs = sorted(self.processes.values(), key=lambda p: p.z_order, reverse=True)
|
| 236 |
for proc in sorted_procs:
|
| 237 |
px, py = proc.position
|
|
@@ -243,6 +344,7 @@ class OSKernel:
|
|
| 243 |
return {"action": "close", "pid": proc.pid, "name": proc.name}
|
| 244 |
return {"action": "focus", "pid": proc.pid, "name": proc.name}
|
| 245 |
|
|
|
|
| 246 |
for icon in self.desktop_icons:
|
| 247 |
ix, iy = icon['x'], icon['y']
|
| 248 |
if ix <= x < ix+8 and iy <= y < iy+8:
|
|
@@ -261,6 +363,7 @@ class NeuralSystem:
|
|
| 261 |
self.dt = torch.float16 if self.device == "cuda" else torch.float32
|
| 262 |
print(f"[*] System Device: {self.device} | Type: {self.dt}")
|
| 263 |
|
|
|
|
| 264 |
print("[*] Loading Neural GPU...")
|
| 265 |
self.pipe = StableDiffusionPipeline.from_pretrained(
|
| 266 |
"runwayml/stable-diffusion-v1-5",
|
|
@@ -275,17 +378,18 @@ class NeuralSystem:
|
|
| 275 |
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
| 276 |
self.pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", torch_dtype=self.dt).to(self.device)
|
| 277 |
|
|
|
|
| 278 |
print("[*] Loading Qwen 2.5...")
|
| 279 |
self.model_id = "Qwen/Qwen2.5-Coder-0.5B-Instruct"
|
| 280 |
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id)
|
| 281 |
if self.tokenizer.pad_token_id is None:
|
| 282 |
self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
|
| 283 |
|
| 284 |
-
#
|
| 285 |
-
#
|
| 286 |
self.llm = AutoModelForCausalLM.from_pretrained(
|
| 287 |
self.model_id,
|
| 288 |
-
|
| 289 |
).to(self.device)
|
| 290 |
|
| 291 |
print("[*] Systems Online.")
|
|
@@ -349,6 +453,7 @@ class NeuralSystem:
|
|
| 349 |
output_type="latent"
|
| 350 |
).images
|
| 351 |
|
|
|
|
| 352 |
img_latents[:, 1, 0:4, :] = 1.5
|
| 353 |
img_latents[:, 0, 0:4, :] = -0.5
|
| 354 |
proc.latent_state = img_latents
|
|
|
|
| 40 |
ENV HOME=/home/user \
|
| 41 |
PATH=/home/user/.local/bin:$PATH
|
| 42 |
|
| 43 |
+
# 6. Write the Application
|
| 44 |
COPY --chown=user <<'EOF' app.py
|
| 45 |
import sys, os, io, base64, json, warnings, time
|
| 46 |
import torch
|
|
|
|
| 57 |
warnings.filterwarnings("ignore")
|
| 58 |
|
| 59 |
# ============================================================================
|
| 60 |
+
# 1. FRONTEND (Responsive React Desktop)
|
| 61 |
# ============================================================================
|
| 62 |
HTML_TEMPLATE = r"""
|
| 63 |
<!DOCTYPE html>
|
| 64 |
<html lang="en">
|
| 65 |
<head>
|
| 66 |
<meta charset="UTF-8">
|
| 67 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
| 68 |
<title>LiteWin XP - Neural OS Desktop</title>
|
| 69 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 70 |
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
|
|
|
| 72 |
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
| 73 |
<link href="https://fonts.googleapis.com/css2?family=Tahoma:wght@400;700&family=Fira+Code:wght@300;500&display=swap" rel="stylesheet">
|
| 74 |
<style>
|
| 75 |
+
body {
|
| 76 |
+
background: #111;
|
| 77 |
+
color: #e2e2e2;
|
| 78 |
+
margin: 0;
|
| 79 |
+
overflow: hidden;
|
| 80 |
+
font-family: 'Tahoma', sans-serif;
|
| 81 |
+
display: flex;
|
| 82 |
+
align-items: center;
|
| 83 |
+
justify-content: center;
|
| 84 |
+
height: 100vh;
|
| 85 |
+
width: 100vw;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/* container for scaling */
|
| 89 |
+
#desktop-container {
|
| 90 |
+
position: relative;
|
| 91 |
+
width: 1024px;
|
| 92 |
+
height: 1024px;
|
| 93 |
+
transform-origin: center center;
|
| 94 |
+
box-shadow: 0 0 50px rgba(0,0,0,0.5);
|
| 95 |
+
background: #3A6EA5;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
.canvas-viewport {
|
| 99 |
+
position: absolute;
|
| 100 |
+
top: 0; left: 0;
|
| 101 |
+
width: 100%; height: 100%;
|
| 102 |
image-rendering: pixelated;
|
| 103 |
}
|
| 104 |
+
.canvas-viewport img { width: 100%; height: 100%; display: block; }
|
| 105 |
+
|
| 106 |
.taskbar {
|
| 107 |
+
position: absolute; bottom: 0; left: 0; right: 0; height: 60px; /* Taller for mobile */
|
| 108 |
background: linear-gradient(to bottom, #1F4788 0%, #1A3E6F 50%, #0E2950 100%);
|
| 109 |
+
border-top: 3px solid #4D7DB5;
|
| 110 |
+
display: flex; align-items: center; padding: 0 8px; gap: 8px;
|
| 111 |
+
z-index: 50;
|
| 112 |
}
|
| 113 |
+
|
| 114 |
.start-btn {
|
| 115 |
background: linear-gradient(to bottom, #3F8B3F 0%, #2F6B2F 100%);
|
| 116 |
+
border: 3px outset #5FAF5F;
|
| 117 |
+
color: white;
|
| 118 |
+
font-weight: bold;
|
| 119 |
+
padding: 6px 18px;
|
| 120 |
+
border-radius: 4px;
|
| 121 |
+
cursor: pointer;
|
| 122 |
+
font-size: 20px; /* Larger text */
|
| 123 |
+
font-style: italic;
|
| 124 |
+
text-shadow: 1px 1px 1px #000;
|
| 125 |
+
display: flex; align-items: center; gap: 8px;
|
| 126 |
}
|
| 127 |
+
|
| 128 |
+
.start-btn::before {
|
| 129 |
+
content: "❖"; /* Windows-ish icon */
|
| 130 |
+
font-style: normal;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
.console-log {
|
| 134 |
+
position: absolute; top: 20px; right: 20px; width: 350px; height: 200px;
|
| 135 |
+
background: rgba(0,0,0,0.85);
|
| 136 |
+
color: #0f0;
|
| 137 |
+
font-family: 'Fira Code', monospace;
|
| 138 |
+
font-size: 14px; /* Readable text */
|
| 139 |
+
line-height: 1.4;
|
| 140 |
+
padding: 15px;
|
| 141 |
+
border: 2px solid #333;
|
| 142 |
+
border-radius: 4px;
|
| 143 |
+
overflow-y: auto;
|
| 144 |
+
z-index: 1000;
|
| 145 |
+
pointer-events: none;
|
| 146 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.5);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/* Mobile Overlay for logs when very small */
|
| 150 |
+
@media (max-width: 600px) {
|
| 151 |
+
.console-log {
|
| 152 |
+
top: auto; bottom: 80px; left: 10px; right: 10px; width: auto; height: 120px;
|
| 153 |
+
}
|
| 154 |
}
|
| 155 |
</style>
|
| 156 |
</head>
|
|
|
|
| 158 |
<div id="root"></div>
|
| 159 |
<script type="text/babel">
|
| 160 |
const { useState, useEffect, useRef } = React;
|
| 161 |
+
|
| 162 |
function App() {
|
| 163 |
const [desktopImage, setDesktopImage] = useState(null);
|
| 164 |
+
const [logs, setLogs] = useState(["Neural Bios v9.7", "Booting Kernel..."]);
|
| 165 |
+
const [scale, setScale] = useState(1);
|
| 166 |
+
|
| 167 |
const socketRef = useRef(null);
|
| 168 |
+
const containerRef = useRef(null);
|
| 169 |
|
| 170 |
+
const addLog = (msg) => setLogs(prev => [...prev.slice(-8), msg]);
|
| 171 |
|
| 172 |
+
// Resize Logic
|
| 173 |
+
useEffect(() => {
|
| 174 |
+
const handleResize = () => {
|
| 175 |
+
const padding = 20; // px
|
| 176 |
+
const availableWidth = window.innerWidth - padding;
|
| 177 |
+
const availableHeight = window.innerHeight - padding;
|
| 178 |
+
|
| 179 |
+
const scaleW = availableWidth / 1024;
|
| 180 |
+
const scaleH = availableHeight / 1024;
|
| 181 |
+
|
| 182 |
+
// Fit contain
|
| 183 |
+
const newScale = Math.min(scaleW, scaleH, 1.0); // Max scale 1.0 (crisp)
|
| 184 |
+
setScale(newScale);
|
| 185 |
+
};
|
| 186 |
+
|
| 187 |
+
window.addEventListener('resize', handleResize);
|
| 188 |
+
handleResize(); // Initial calc
|
| 189 |
+
return () => window.removeEventListener('resize', handleResize);
|
| 190 |
+
}, []);
|
| 191 |
+
|
| 192 |
+
// Websocket Logic
|
| 193 |
useEffect(() => {
|
| 194 |
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';
|
| 195 |
const ws = new WebSocket(`${proto}://${window.location.host}/kernel`);
|
|
|
|
| 205 |
}, []);
|
| 206 |
|
| 207 |
const handleClick = (e) => {
|
| 208 |
+
if (!containerRef.current) return;
|
| 209 |
+
|
| 210 |
+
// Get click coordinates relative to the scaled container
|
| 211 |
+
const rect = containerRef.current.getBoundingClientRect();
|
| 212 |
+
|
| 213 |
+
// Calculate position (0-1024)
|
| 214 |
+
const clickX = (e.clientX - rect.left) / scale;
|
| 215 |
+
const clickY = (e.clientY - rect.top) / scale;
|
| 216 |
+
|
| 217 |
+
// Convert to Neural Grid (0-128)
|
| 218 |
+
const gridX = Math.floor((clickX / 1024) * 128);
|
| 219 |
+
const gridY = Math.floor((clickY / 1024) * 128);
|
| 220 |
+
|
| 221 |
+
if(gridX >= 0 && gridX <= 128 && gridY >= 0 && gridY <= 128) {
|
| 222 |
+
socketRef.current?.send(JSON.stringify({ type: 'click', x: gridX, y: gridY }));
|
| 223 |
+
}
|
| 224 |
};
|
| 225 |
|
| 226 |
return (
|
| 227 |
+
<div
|
| 228 |
+
id="desktop-container"
|
| 229 |
+
ref={containerRef}
|
| 230 |
+
style={{ transform: `scale(${scale})` }}
|
| 231 |
+
>
|
| 232 |
+
<div className="canvas-viewport" onClick={handleClick}>
|
| 233 |
+
{desktopImage && <img src={`data:image/png;base64,${desktopImage}`} draggable="false" />}
|
| 234 |
</div>
|
| 235 |
+
|
| 236 |
<div className="taskbar">
|
| 237 |
<div className="start-btn">start</div>
|
| 238 |
</div>
|
| 239 |
+
|
| 240 |
<div className="console-log">
|
| 241 |
+
{logs.map((l, i) => <div key={i}>> {l}</div>)}
|
| 242 |
</div>
|
| 243 |
</div>
|
| 244 |
);
|
|
|
|
| 332 |
self.processes[pid].z_order = max_z + 1
|
| 333 |
|
| 334 |
def handle_click(self, x: int, y: int) -> Dict:
|
| 335 |
+
# Check Windows (Reverse Z)
|
| 336 |
sorted_procs = sorted(self.processes.values(), key=lambda p: p.z_order, reverse=True)
|
| 337 |
for proc in sorted_procs:
|
| 338 |
px, py = proc.position
|
|
|
|
| 344 |
return {"action": "close", "pid": proc.pid, "name": proc.name}
|
| 345 |
return {"action": "focus", "pid": proc.pid, "name": proc.name}
|
| 346 |
|
| 347 |
+
# Check Icons
|
| 348 |
for icon in self.desktop_icons:
|
| 349 |
ix, iy = icon['x'], icon['y']
|
| 350 |
if ix <= x < ix+8 and iy <= y < iy+8:
|
|
|
|
| 363 |
self.dt = torch.float16 if self.device == "cuda" else torch.float32
|
| 364 |
print(f"[*] System Device: {self.device} | Type: {self.dt}")
|
| 365 |
|
| 366 |
+
# A. LOAD DIFFUSION
|
| 367 |
print("[*] Loading Neural GPU...")
|
| 368 |
self.pipe = StableDiffusionPipeline.from_pretrained(
|
| 369 |
"runwayml/stable-diffusion-v1-5",
|
|
|
|
| 378 |
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
| 379 |
self.pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", torch_dtype=self.dt).to(self.device)
|
| 380 |
|
| 381 |
+
# B. LOAD QWEN
|
| 382 |
print("[*] Loading Qwen 2.5...")
|
| 383 |
self.model_id = "Qwen/Qwen2.5-Coder-0.5B-Instruct"
|
| 384 |
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id)
|
| 385 |
if self.tokenizer.pad_token_id is None:
|
| 386 |
self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
|
| 387 |
|
| 388 |
+
# FIX: Using 'dtype' instead of 'torch_dtype' to silence deprecation warning
|
| 389 |
+
# FIX: Removed device_map to prevent meta-tensor error on CPU
|
| 390 |
self.llm = AutoModelForCausalLM.from_pretrained(
|
| 391 |
self.model_id,
|
| 392 |
+
dtype=self.dt
|
| 393 |
).to(self.device)
|
| 394 |
|
| 395 |
print("[*] Systems Online.")
|
|
|
|
| 453 |
output_type="latent"
|
| 454 |
).images
|
| 455 |
|
| 456 |
+
# Simple Title Bar Injection
|
| 457 |
img_latents[:, 1, 0:4, :] = 1.5
|
| 458 |
img_latents[:, 0, 0:4, :] = -0.5
|
| 459 |
proc.latent_state = img_latents
|