-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevbox.py
More file actions
892 lines (756 loc) · 33 KB
/
Copy pathdevbox.py
File metadata and controls
892 lines (756 loc) · 33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
import modal
import random
import platform
from images import (
standard_devbox_image, cuda_devbox_image, doc_processing_image,
assisted_coding_image, llm_playroom_image, llamacpp_cpu_image, rdp_devbox_image, forensic_analysis_image
)
from shared_runtime import run_devbox_shared, run_rdp_devbox_shared
from config import get_resource_config, LLAMACPP_DEVBOX_ARGS, LLAMACPP_GPU_DEVBOX_ARGS, LLAMACPP_IDLE_TIMEOUT
app = modal.App(
name="personal-devbox-launcher",
)
dev_volume = modal.Volume.from_name("my-dev-volume", create_if_missing=True)
juicy_secrets = [modal.Secret.from_name("ssh-public-key"), modal.Secret.from_name("gemini-api-key"), modal.Secret.from_name("exa-api-key")] # Right now, all boxes will be filled with these secrets even if it may not directly be intented.
# Common arguments for the devbox functions loaded from config.py and None values such as secret and volume are filled with values defined above
cpu_devbox_args = get_resource_config("cpu", secrets= juicy_secrets, volume = dev_volume)
cpu_devbox_args_rdp = get_resource_config("cpu", secrets = juicy_secrets, volume = dev_volume, is_rdp = True)
gpu_devbox_args = get_resource_config("gpu", secrets = juicy_secrets, volume = dev_volume, is_rdp = True)
gpu_devbox_args_rdp = get_resource_config("gpu", secrets = juicy_secrets, volume = dev_volume, is_rdp = True)
# llama.cpp Research Center config - fill in secrets and volume
llamacpp_devbox_args = LLAMACPP_DEVBOX_ARGS.copy()
llamacpp_devbox_args["secrets"] = juicy_secrets
llamacpp_devbox_args["volumes"] = {"/data": dev_volume}
# GPU llama.cpp Research Center config - fill in secrets and volume
llamacpp_gpu_devbox_args = LLAMACPP_GPU_DEVBOX_ARGS.copy()
llamacpp_gpu_devbox_args["secrets"] = juicy_secrets
llamacpp_gpu_devbox_args["volumes"] = {"/data": dev_volume}
@app.function(image=standard_devbox_image, **cpu_devbox_args)
def launch_devbox(extra_packages: list[str] | None = None):
"""Launches a non-GPU personal development environment."""
run_devbox_shared(extra_packages, devbox_type="standard_devbox")
@app.function(image=cuda_devbox_image, gpu="t4", **gpu_devbox_args)
def launch_devbox_t4(extra_packages: list[str] | None = None):
"""Launches a T4 GPU-powered personal development environment."""
run_devbox_shared(extra_packages, devbox_type="cuda_devbox_t4")
@app.function(image=cuda_devbox_image, gpu="l4", **gpu_devbox_args)
def launch_devbox_l4(extra_packages: list[str] | None = None):
"""Launches an L4 GPU-powered personal development environment."""
run_devbox_shared(extra_packages, devbox_type="cuda_devbox_l4")
@app.function(image=cuda_devbox_image, gpu="a10g", **gpu_devbox_args)
def launch_devbox_a10g(extra_packages: list[str] | None = None):
"""Launches an A10G GPU-powered personal development environment."""
run_devbox_shared(extra_packages, devbox_type="cuda_devbox_a10g")
@app.function(image=rdp_devbox_image, **cpu_devbox_args_rdp)
def launch_rdp_devbox(extra_packages: list[str] = None):
"""Launches an RDP desktop development environment."""
run_rdp_devbox_shared(extra_packages)
@app.function(image=rdp_devbox_image, gpu="t4", **gpu_devbox_args_rdp)
def launch_rdp_devbox_t4(extra_packages: list[str] = None):
"""Launches an RDP desktop with T4 GPU."""
run_rdp_devbox_shared(extra_packages)
@app.function(image=rdp_devbox_image, gpu="l4", **gpu_devbox_args_rdp)
def launch_rdp_devbox_l4(extra_packages: list[str] = None):
"""Launches an RDP desktop with L4 GPU."""
run_rdp_devbox_shared(extra_packages)
@app.function(image=rdp_devbox_image, gpu="a10g", **gpu_devbox_args_rdp)
def launch_rdp_devbox_a10g(extra_packages: list[str] = None):
"""Launches an RDP desktop with A10G GPU."""
run_rdp_devbox_shared(extra_packages)
@app.function(image=doc_processing_image, **gpu_devbox_args)
def launch_doc_processor():
"""Launches a document processing environment with Pandoc and TeX Live."""
run_devbox_shared(extra_packages=None, devbox_type="doc_processing")
@app.function(image=assisted_coding_image, **cpu_devbox_args)
def launch_assisted_coding():
"""Launches a development environment with Gemini CLI & OpenCode pre-installed."""
run_devbox_shared(extra_packages=None, devbox_type="assisted_coding")
@app.function(image=llm_playroom_image, **gpu_devbox_args_rdp) # Needs review
def launch_llm_playroom():
"""Launches an LLM Playroom environment with Ollama and preloaded models."""
run_devbox_shared(extra_packages=None, devbox_type="llm_playroom") # add model selection here too!
@app.function(image=forensic_analysis_image, **cpu_devbox_args)
def launch_forensics_image():
""" Launches A Forensic Analysis Machine With Volatilty3 pre-installed. """
run_devbox_shared(extra_packages=None, devbox_type="forensic_analysis")
# llama.cpp Research Center - Curated Model Catalog
LLAMACPP_MODELS = {
"1": {
"name": "Qwen3.5-9B-Instruct",
"repo_id": "unsloth/Qwen3.5-9B-GGUF",
"filename": "Qwen3.5-9B-Q4_K_M.gguf",
"size": "5.68GB",
"type": "text",
"description": "Best overall - thinking mode, 256K context",
"function_calling": True,
"settings": {"temp": 0.7, "top_p": 0.8, "top_k": 20}
},
"2": {
"name": "Bonsai-8B",
"repo_id": "prism-ml/Bonsai-8B-gguf",
"filename": "Bonsai-8B-Q1_0.gguf",
"size": "1.15GB",
"type": "text",
"description": "1-bit ultra-lightweight - 14x smaller, 6x faster on GPU",
"function_calling": True,
"settings": {"temp": 0.5, "top_p": 0.85, "top_k": 20}
},
"3": {
"name": "SmolVLM-500M",
"repo_id": "ggml-org/SmolVLM-500M-Instruct-GGUF",
"filename": "ggml-model-mmproj-f16.gguf",
"size": "~1.5GB",
"type": "vision",
"description": "Fast image captioning",
"function_calling": False,
"settings": {"temp": 0.7, "top_p": 0.9, "top_k": 40}
},
"4": {
"name": "Gemma4-26B-A4B",
"repo_id": "unsloth/gemma-4-26b-a4b-it-GGUF",
"filename": "gemma-4-26b-a4b-it-Q4_K_M.gguf",
"size": "~17GB",
"type": "vision",
"description": "Google's latest - MoE (4B active), 256K context, multimodal",
"function_calling": True,
"settings": {"temp": 0.7, "top_p": 0.8, "top_k": 20}
},
"5": {
"name": "Custom Model",
"repo_id": None,
"filename": None,
"size": "User-defined",
"type": "text",
"description": "Any GGUF model from HuggingFace",
"function_calling": True,
"settings": {"temp": 0.7, "top_p": 0.9, "top_k": 40}
},
}
#The models list will be moved to a better /dedicated file
@app.function(image=llamacpp_cpu_image, **llamacpp_devbox_args)
def launch_llamacpp_playroom():
"""llama.cpp Research Center with curated models, WebUI, and EXA Search."""
import os
import shutil
import subprocess
import sys
import modal
import time
import json
import httpx
from utils import inject_ssh_key
from exa_helper import get_exa_api_key, get_tools_for_model
modal.interact() # Enable user input
print("\n🧠 Launching llama.cpp Research Center")
print("💻 CPU-Optimized Inference")
print("🔍 EXA Search Integration")
print("🌐 Built-in WebUI")
# --- Persistence Setup ---
persistent_storage_dir = "/data/.config_persistence"
os.makedirs(persistent_storage_dir, exist_ok=True)
items_to_persist = [
".bash_history", ".bashrc", ".profile", ".viminfo", ".vimrc",
".gitconfig", ".ssh/config", ".ssh/known_hosts",
]
for item in items_to_persist:
home_path = f"/root/{item}"
volume_path = f"{persistent_storage_dir}/{item}"
os.makedirs(os.path.dirname(home_path), exist_ok=True)
os.makedirs(os.path.dirname(volume_path), exist_ok=True)
if os.path.lexists(home_path):
if os.path.isdir(home_path) and not os.path.islink(home_path):
shutil.rmtree(home_path)
else:
os.remove(home_path)
os.symlink(volume_path, home_path)
# --- Model Selection ---
print("\n📦 Model Selection:")
for key, model in LLAMACPP_MODELS.items():
print(f"{key}. {model['name']} - {model['description']}")
print(f" Size: {model['size']} | Type: {model['type']}")
try:
model_choice = input("\nEnter model number (1-7): ").strip()
except EOFError:
model_choice = "1"
if model_choice not in LLAMACPP_MODELS:
print("❌ Invalid choice. Defaulting to Qwen3.5-9B")
model_choice = "1"
selected_model = LLAMACPP_MODELS[model_choice].copy()
# Handle custom model input
if model_choice == "7":
print("\n📝 Custom Model Details:")
repo_id = input("Repo ID (e.g., unsloth/Qwen3.5-9B-GGUF): ").strip()
filename = input("Filename (e.g., model-Q4_K_M.gguf): ").strip()
selected_model["repo_id"] = repo_id
selected_model["filename"] = filename
selected_model["name"] = filename.replace(".gguf", "")
# --- Download Model ---
model_dir = "/data/models"
os.makedirs(model_dir, exist_ok=True)
model_path = f"{model_dir}/{selected_model['filename']}"
if not os.path.exists(model_path):
print(f"\n📦 Downloading {selected_model['repo_id']}/{selected_model['filename']}...")
print(" This may take a few minutes on first run...")
try:
subprocess.run([
"hf", "download",
selected_model["repo_id"],
selected_model["filename"],
"--local-dir", model_dir
], check=True)
print(f"✅ Model downloaded to {model_path}")
except subprocess.CalledProcessError:
print(f"❌ Download failed. Check repo_id and filename.")
print(f" Repo: {selected_model['repo_id']}")
print(f" File: {selected_model['filename']}")
return
else:
print(f"✅ Model already cached: {model_path}")
# --- EXA Search Check ---
exa_key = get_exa_api_key()
if exa_key:
print("✅ EXA Search API key found")
use_exa = True
else:
print("⚠️ EXA Search API key not found. Web search disabled.")
print(" Add 'exa-api-key' secret to Modal to enable.")
use_exa = False
# --- Start llama-server ---
model_settings = selected_model.get('settings', {})
server_cmd = [
"llama-server",
"-m", model_path,
"--host", "0.0.0.0",
"--port", "8080",
"--threads", "2",
"--ctx-size", "4096",
"--batch-size", "512",
"--mlock",
"--jinja", # Enable function calling + WebUI
"--temp", str(model_settings.get('temp', 0.7)),
"--top-p", str(model_settings.get('top_p', 0.9)),
"--top-k", str(model_settings.get('top_k', 40)),
]
print(f"\n🚀 Starting llama-server for {selected_model['name']}...")
print(f" Settings: temp={model_settings.get('temp', 0.7)}, top_p={model_settings.get('top_p', 0.9)}")
# Start server in background
server_process = subprocess.Popen(
server_cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE
)
# Wait for server to be ready
time.sleep(3)
for i in range(30):
try:
resp = httpx.get("http://localhost:8080/health", timeout=1.0)
if resp.status_code == 200:
print("✅ llama-server ready!")
break
except:
pass
time.sleep(1)
else:
print("❌ llama-server failed to start. Check model file.")
server_process.terminate()
return
# --- Start EXA Proxy (if enabled) ---
if use_exa:
from exa_proxy import start_exa_proxy
print(" Starting EXA Search proxy...")
start_exa_proxy(port=8081, target_port=8080)
web_port = 8081
else:
web_port = 8080
# --- SSH Setup ---
inject_ssh_key()
subprocess.run(["/usr/sbin/sshd"])
# --- Port Forwarding ---
with modal.forward(22, unencrypted=True) as ssh_tunnel:
ssh_command = f"ssh root@{ssh_tunnel.host} -p {ssh_tunnel.unencrypted_port}"
with modal.forward(web_port, unencrypted=True) as web_tunnel:
web_url = f"http://{web_tunnel.host}:{web_tunnel.unencrypted_port}"
print("\n" + "="*60)
print("🚀 Your llama.cpp Research Center is ready!")
print("="*60)
print(f"\n🌐 WebUI: {web_url}")
print(f" (Open in browser for chat interface)")
print(f"\n🔐 SSH: {ssh_command}")
print(f"\n🧠 Model: {selected_model['name']} ({selected_model['size']})")
if use_exa:
print(f"🔍 EXA Search: Enabled (function calling)")
print(f"\n⏰ Idle timeout: {LLAMACPP_IDLE_TIMEOUT // 60} minutes")
print("\n" + "="*60)
# --- Idle Monitor ---
idle_time = 0
check_interval = 30
while idle_time < LLAMACPP_IDLE_TIMEOUT:
time.sleep(check_interval)
# Check for active SSH sessions
ssh_result = subprocess.run(
"ps -ef | grep 'sshd: root@' | grep -v grep",
shell=True,
capture_output=True,
)
# Check for active WebUI connections
web_active = False
try:
stats = httpx.get("http://localhost:8080/health", timeout=1.0)
web_active = True # Server is running
except:
pass
if ssh_result.stdout or web_active:
idle_time = 0
else:
idle_time += check_interval
remaining = LLAMACPP_IDLE_TIMEOUT - idle_time
print(f"\r💤 No activity. Shutting down in {remaining // 60}m {remaining % 60}s...", end="", flush=True)
print(f"\n\n⏰ Idle timeout reached ({LLAMACPP_IDLE_TIMEOUT}s). Shutting down.")
server_process.terminate()
@app.function(image=llamacpp_cpu_image, **llamacpp_gpu_devbox_args)
def launch_llamacpp_playroom_gpu():
"""GPU-accelerated llama.cpp Research Center with curated models, WebUI, and EXA Search."""
import os
import shutil
import subprocess
import sys
import modal
import time
import json
import httpx
from utils import inject_ssh_key
from exa_helper import get_exa_api_key, get_tools_for_model
modal.interact()
print("\n🧠 Launching llama.cpp Research Center")
print("🚀 GPU-Accelerated Inference (T4)")
print("🔍 EXA Search Integration")
print("🌐 Built-in WebUI")
# --- Persistence Setup ---
persistent_storage_dir = "/data/.config_persistence"
os.makedirs(persistent_storage_dir, exist_ok=True)
items_to_persist = [
".bash_history", ".bashrc", ".profile", ".viminfo", ".vimrc",
".gitconfig", ".ssh/config", ".ssh/known_hosts",
]
for item in items_to_persist:
home_path = f"/root/{item}"
volume_path = f"{persistent_storage_dir}/{item}"
os.makedirs(os.path.dirname(home_path), exist_ok=True)
os.makedirs(os.path.dirname(volume_path), exist_ok=True)
if os.path.lexists(home_path):
if os.path.isdir(home_path) and not os.path.islink(home_path):
shutil.rmtree(home_path)
else:
os.remove(home_path)
os.symlink(volume_path, home_path)
# --- Model Selection ---
print("\n📦 Model Selection:")
for key, model in LLAMACPP_MODELS.items():
print(f"{key}. {model['name']} - {model['description']}")
print(f" Size: {model['size']} | Type: {model['type']}")
try:
model_choice = input("\nEnter model number (1-7): ").strip()
except EOFError:
model_choice = "1"
if model_choice not in LLAMACPP_MODELS:
print("❌ Invalid choice. Defaulting to Qwen3.5-9B")
model_choice = "1"
selected_model = LLAMACPP_MODELS[model_choice].copy()
# Handle custom model input
if model_choice == "7":
print("\n📝 Custom Model Details:")
repo_id = input("Repo ID (e.g., unsloth/Qwen3.5-9B-GGUF): ").strip()
filename = input("Filename (e.g., model-Q4_K_M.gguf): ").strip()
selected_model["repo_id"] = repo_id
selected_model["filename"] = filename
selected_model["name"] = filename.replace(".gguf", "")
# --- Download Model ---
model_dir = "/data/models"
os.makedirs(model_dir, exist_ok=True)
model_path = f"{model_dir}/{selected_model['filename']}"
if not os.path.exists(model_path):
print(f"\n📦 Downloading {selected_model['repo_id']}/{selected_model['filename']}...")
print(" This may take a few minutes on first run...")
try:
subprocess.run([
"hf", "download",
selected_model["repo_id"],
selected_model["filename"],
"--local-dir", model_dir
], check=True)
print(f"✅ Model downloaded to {model_path}")
except subprocess.CalledProcessError:
print(f"❌ Download failed. Check repo_id and filename.")
print(f" Repo: {selected_model['repo_id']}")
print(f" File: {selected_model['filename']}")
return
else:
print(f"✅ Model already cached: {model_path}")
# --- EXA Search Check ---
exa_key = get_exa_api_key()
if exa_key:
print("✅ EXA Search API key found")
use_exa = True
else:
print("⚠️ EXA Search API key not found. Web search disabled.")
print(" Add 'exa-api-key' secret to Modal to enable.")
use_exa = False
# --- Start llama-server with GPU optimizations ---
model_settings = selected_model.get('settings', {})
server_cmd = [
"llama-server",
"-m", model_path,
"--host", "0.0.0.0",
"--port", "8080",
"--ctx-size", "32768",
"--batch-size", "512",
"-ngl", "99", # Offload all layers to GPU
"-fa", "on", # Flash Attention
"-ctk", "q8_0", # Key cache quantization
"-ctv", "q8_0", # Value cache quantization
"--jinja",
"--temp", str(model_settings.get('temp', 0.7)),
"--top-p", str(model_settings.get('top_p', 0.9)),
"--top-k", str(model_settings.get('top_k', 40)),
]
print(f"\n🚀 Starting GPU-accelerated llama-server for {selected_model['name']}...")
print(f" GPU: T4 (all layers offloaded)")
print(f" Settings: temp={model_settings.get('temp', 0.7)}, top_p={model_settings.get('top_p', 0.9)}")
print(f" Context: 32K with KV cache quantization")
# Start server in background
server_process = subprocess.Popen(
server_cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE
)
# Wait for server to be ready
time.sleep(3)
for i in range(30):
try:
resp = httpx.get("http://localhost:8080/health", timeout=1.0)
if resp.status_code == 200:
print("✅ llama-server ready!")
break
except:
pass
time.sleep(1)
else:
print("❌ llama-server failed to start. Check model file.")
server_process.terminate()
return
# --- Start EXA Proxy (if enabled) ---
if use_exa:
from exa_proxy import start_exa_proxy
print(" Starting EXA Search proxy...")
start_exa_proxy(port=8081, target_port=8080)
web_port = 8081
else:
web_port = 8080
# --- SSH Setup ---
inject_ssh_key()
subprocess.run(["/usr/sbin/sshd"])
# --- Port Forwarding ---
with modal.forward(22, unencrypted=True) as ssh_tunnel:
ssh_command = f"ssh root@{ssh_tunnel.host} -p {ssh_tunnel.unencrypted_port}"
with modal.forward(web_port, unencrypted=True) as web_tunnel:
web_url = f"http://{web_tunnel.host}:{web_tunnel.unencrypted_port}"
print("\n" + "="*60)
print("🚀 Your GPU llama.cpp Research Center is ready!")
print("="*60)
print(f"\n🌐 WebUI: {web_url}")
print(f" (Open in browser for chat interface)")
print(f"\n🔐 SSH: {ssh_command}")
print(f"\n🧠 Model: {selected_model['name']} ({selected_model['size']})")
print(f"🎮 GPU: T4 (all layers offloaded)")
if use_exa:
print(f"🔍 EXA Search: Enabled (function calling)")
print(f"\n⏰ Idle timeout: {LLAMACPP_IDLE_TIMEOUT // 60} minutes")
print("\n" + "="*60)
# --- Idle Monitor ---
idle_time = 0
check_interval = 30
while idle_time < LLAMACPP_IDLE_TIMEOUT:
time.sleep(check_interval)
# Check for active SSH sessions
ssh_result = subprocess.run(
"ps -ef | grep 'sshd: root@' | grep -v grep",
shell=True,
capture_output=True,
)
# Check for active WebUI connections
web_active = False
try:
stats = httpx.get("http://localhost:8080/health", timeout=1.0)
web_active = True
except:
pass
if ssh_result.stdout or web_active:
idle_time = 0
else:
idle_time += check_interval
remaining = LLAMACPP_IDLE_TIMEOUT - idle_time
print(f"\r💤 No activity. Shutting down in {remaining // 60}m {remaining % 60}s...", end="", flush=True)
print(f"\n\n⏰ Idle timeout reached ({LLAMACPP_IDLE_TIMEOUT}s). Shutting down.")
server_process.terminate()
# Menu-driven local entrypoint.
@app.local_entrypoint()
def main():
from ui_utils import create_box, show_spinner
from quotes_loader import get_random_quote, format_quote
from utils import inject_ssh_key, display_system_info
from config import IDLE_TIMEOUT_SECONDS
from gpu_utils import get_gpu_config, get_available_gpus
banner = """
╔══════════════════════════════════════════════════════════╗
║ ║
║ 🚀 DEVBOX LAUNCHER 🚀 ║
║ ║
║ " Potatoes Taste Nice 🤔 " ║
║ ║
╚══════════════════════════════════════════════════════════╝
"""
print(banner)
quote = get_random_quote()
quote_box = format_quote(quote)
create_box(quote_box, "💭 Programming Wisdom")
display_system_info()
menu_box = """
🎯 Choose your DevBox Config:
1. 🛠️ Standard DevBox general purpose development environment with optional extra packages
2. 📄 Document Processing Box
Pandoc + Full TeX Live for document work
3. 🤖 AI Assistants Box
Includes OpenCode and Gemini CLI
4. 🧠 LLM Playroom
Ollama for AI experimentation
5. 🖥️ RDP Desktop Box Full graphical desktop with XFCE and RDP access
6. 🔬 llama.cpp Research Center (CPU)
Curated models + WebUI + EXA Search + Multimodal
7. 🔍 Forensics Analysis
Analysis Machine using Volatilty3 and other tools
8. 🚀 llama.cpp Research Center (GPU)
GPU-accelerated inference + 32K context + T4 GPU
"""
create_box(menu_box, "🚀 LAUNCH OPTIONS")
try:
choice = input("Enter your choice (1-8): ").strip()
except EOFError:
print("\nNo input received. Exiting.")
return
print(choice)
if choice == "1": #remember to adjust subsequent indents at package_selction
package_box = """
📦 Want to install additional tools?
Examples: htop tmux git neovim curl wget
(leave empty for default setup)
"""
create_box(package_box, "🛠️ EXTRA PACKAGES")
try:
tools_input = input("Enter tools (space-separated): ").strip()
except EOFError:
tools_input = ""
package_list = tools_input.split() if tools_input else []
if package_list:
print(f"✅ Requesting with additional tools: {', '.join(package_list)}")
else:
print("✅ No extra tools requested.")
gpu_box = """
🎮 Add GPU acceleration?
• T4: Cost-effective, good for inference
• L4: More Performant than T4
• A10G: Higher performance, more VRAM
(Enter 'y' To Attach a GPU, anything else for CPU-only)
⚠️ GPU usage incurs charges on your Modal account.
See modal.com/pricing for current rates.
"""
create_box(gpu_box, "⚡ GPU ACCELERATION")
try:
gpu_choice = input("Attach GPU? (y/n): ").lower().strip()
except EOFError:
gpu_choice = "n"
if gpu_choice == "y":
gpu_menu = """
1. 🎯 T4 GPU (Cost-effective, good for inference)
2. 🚀 L4 GPU (More Performant than T4)
3. 💪 A10G GPU (Higher performance, more VRAM)
"""
create_box(gpu_menu, "🎮 SELECT GPU TYPE")
try:
gpu_type_choice = input("Choose GPU (1-3): ").strip()
except EOFError:
print("\nNo input received. Exiting.")
return
gpu_types = {
"1": ("T4", launch_devbox_t4),
"2": ("L4", launch_devbox_l4),
"3": ("A10G", launch_devbox_a10g),
}
if gpu_type_choice in gpu_types:
gpu_name, launch_func = gpu_types[gpu_type_choice]
gpu_launch_box = f"🎯 Launching with {gpu_name} GPU... Silicon Dust 🔥"
create_box(gpu_launch_box, f"🚀 {gpu_name} POWERED")
show_spinner("Initializing GPU environment", 2)
launch_func.remote(extra_packages=package_list)
else:
print("❌ Invalid GPU choice. Please run again.")
return
else:
cpu_box = """🖥️ Launching CPU-only environment...
Potatoes Have High Carbohydrates Content 😉
"""
create_box(cpu_box, "🚀 STANDARD DEVBOX")
show_spinner("Preparing your DevBox", 2)
launch_devbox.remote(extra_packages=package_list)
elif choice == "2":
doc_box = """
📄 Launching Document Processing Box...
📚 Pandoc + Full TeX Live Distribution
"""
create_box(doc_box, "📄 DOCUMENT PROCESSING")
show_spinner("Setting up document tools", 2)
launch_doc_processor.remote()
elif choice == "3":
assistants_box = """
🤖 Launching AI Assistants Box...
🧠 Includes OpenCode and Gemini CLI
🚀 Let's build something amazing together!
"""
create_box(assistants_box, "🤖 AI ASSISTANTS")
show_spinner("Initializing AI assistants", 2)
launch_assisted_coding.remote()
elif choice == "4":
llm_box = """
🧠 Launching LLM Playroom...
🤖 Ollama with DeepSeek R1 (8B distilled)
🚀 Ready for AI experimentation!
"""
create_box(llm_box, "🧠 LLM PLAYROOM")
show_spinner("Initializing LLM environment", 2)
launch_llm_playroom.remote()
elif choice == "5":
rdp_box = """
🖥️ Launching RDP Desktop Box...
🖼️ XFCE Desktop Environment + RDP access
"""
create_box(rdp_box, "🖥️ RDP DESKTOP")
show_spinner("Setting up desktop environment", 2)
package_box = """
📦 Want to install additional desktop tools?
Examples: firefox gedit vscode libreoffice(leave empty for default XFCE setup)
"""
create_box(package_box, "🖥️ EXTRA DESKTOP PACKAGES")
try:
tools_input = input("Enter desktop tools(space-separated): ").strip()
except EOFError:
tools_input = ""
package_list = tools_input.split() if tools_input else []
if package_list:
print(f"✅ Requesting with additional tools: {', '.join(package_list)}")
else:
print("✅ No extra desktop tools requested.")
gpu_box = """
🎮 Add GPU acceleration for desktop?
• T4: Cost-effective, good for graphics
• L4: Newer, more performant than T4
• A10G: Higher performance, more VRAM
(Enter 'y' for GPU options, anything else for CPU-only)
⚠️ GPU usage incurs charges on your Modal account.
See modal.com/pricing for current rates.
"""
create_box(gpu_box, "⚡ GPU ACCELERATION")
try:
gpu_choice = input("Attach GPU? (y/n): ").lower().strip()
except EOFError:
gpu_choice = "n"
if gpu_choice == "y":
gpu_menu = """
1. 🎯 T4 GPU (Cost-effective, good for graphics)
2. 🚀 L4 GPU (Newer, more performant than T4)
3. 💪 A10G GPU (Higher performance, more VRAM)
"""
create_box(gpu_menu, "🎮 SELECT GPU TYPE")
try:
gpu_type_choice = input("Choose GPU (1-3): ").strip()
except EOFError:
print("\nNo input received. Exiting.")
return
gpu_types = {
"1": ("T4", launch_rdp_devbox_t4),
"2": ("L4", launch_rdp_devbox_l4),
"3": ("A10G", launch_rdp_devbox_a10g),
}
if gpu_type_choice in gpu_types:
gpu_name, launch_func = gpu_types[gpu_type_choice]
gpu_launch_box = f"""
🎯 Launching RDP Desktop with {gpu_name} GPU...
"""
create_box(gpu_launch_box, f"🚀 {gpu_name} POWERED RDP")
show_spinner("Initializing GPU RDP environment", 2)
launch_func.remote(extra_packages=package_list)
else:
print("❌ Invalid GPU choice. Please run again.")
return
else:
cpu_box = """
🖥️ Launching RDP Desktop (CPU-only)...
"""
create_box(cpu_box, "🚀 RDP DESKTOP")
show_spinner("Preparing your RDP Desktop", 2)
launch_rdp_devbox.remote(extra_packages=package_list)
elif choice == "6":
research_box = """
🔬 Launching llama.cpp Research Center...
Models available:
• Qwen3.5-9B (General reasoning)
• Bonsai-8B (1-bit ultra-lightweight)
• SmolVLM-500M (Image captioning)
• Gemma4-26B-A4B (Multimodal)
• Custom (Any HuggingFace GGUF)
Features:
• Built-in WebUI (browser chat)
• EXA Search integration
• Function calling support
"""
create_box(research_box, "🔬 LLAMA.CPP RESEARCH CENTER")
show_spinner("Preparing research environment", 3)
launch_llamacpp_playroom.remote()
elif choice == "7":
forensics_box = """
Immerse Yourself Into The Bits.... 01101010101010100101
"""
create_box(forensics_box, "Forensics Machine")
show_spinner("Interleaving Bits... Hold On Tight!", 3)
launch_forensics_image.remote()
elif choice == "8":
research_gpu_box = """
🚀 Launching GPU llama.cpp Research Center...
Models available:
• Qwen3.5-9B (General reasoning)
• Bonsai-8B (1-bit ultra-lightweight)
• SmolVLM-500M (Image captioning)
• Gemma4-26B-A4B (Multimodal)
• Custom (Any HuggingFace GGUF)
GPU Features:
• T4 GPU with all layers offloaded
• 32K context with KV cache quantization
• Flash Attention for faster inference
• Built-in WebUI (browser chat)
• EXA Search integration
"""
create_box(research_gpu_box, "🚀 GPU LLAMA.CPP RESEARCH CENTER")
show_spinner("Preparing GPU-accelerated environment", 3)
launch_llamacpp_playroom_gpu.remote()
else:
error_box = """
❌ Invalid choice selected.
Please run the launcher again and choose:
• 1 for Standard DevBox
• 2 for Document Processing
• 3 for AI Assistants Box
• 4 for LLM Playroom
• 5 for RDP Desktop Box
• 6 for llama.cpp Research Center (CPU)
• 7 for Forensics Machine
• 8 for llama.cpp Research Center (GPU)
"""
create_box(error_box, "❌ ERROR")