LeafCat79 commited on
Commit
c6ca8f0
·
verified ·
1 Parent(s): b7edb34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -1,9 +1,9 @@
1
  """
2
  Text-to-Game Generator - Local GGUF Edition
3
- - Code : Qwen/Qwen2.5-Coder-7B-Instruct-GGUF Q4_K_M (~4.5GB, CPU via llama-cpp-python)
4
- - Images: unsloth/Z-Image-Turbo-GGUF Q2_K (~3.6GB, GPU via ZeroGPU + diffusers)
5
 
6
- Total disk usage: ~8GB — fits within HF free Space 16GB storage limit.
7
  Space hardware : set to ZeroGPU (free) in Space settings.
8
 
9
  Models are downloaded on first startup and cached — subsequent starts are instant.
@@ -25,22 +25,24 @@ from PIL import Image
25
  # Model paths — downloaded once at startup, cached in /tmp
26
  # ---------------------------------------------------------------------------
27
 
28
- GGUF_DIR = Path("/tmp/models")
29
- CODE_GGUF_PATH = GGUF_DIR / "qwen2.5-coder-7b-q4_k_m.gguf"
30
- IMAGE_GGUF_PATH = GGUF_DIR / "z-image-turbo-Q2_K.gguf"
31
 
32
  GGUF_DIR.mkdir(parents=True, exist_ok=True)
33
 
34
- # Download code model GGUF (Q4_K_M ~4.5GB, good quality/speed balance on CPU)
 
 
 
 
35
  if not CODE_GGUF_PATH.exists():
36
- print("Downloading Qwen2.5-Coder-7B Q4_K_M GGUF...")
37
  hf_hub_download(
38
- repo_id="Qwen/Qwen2.5-Coder-7B-Instruct-GGUF",
39
- filename="qwen2.5-coder-7b-instruct-q4_k_m.gguf",
40
  local_dir=str(GGUF_DIR),
41
  local_dir_use_symlinks=False,
42
  )
43
- (GGUF_DIR / "qwen2.5-coder-7b-instruct-q4_k_m.gguf").rename(CODE_GGUF_PATH)
44
  print("Code model downloaded.")
45
 
46
  # Download image model GGUF (Q2_K ~3.6GB, smallest that still works)
@@ -58,14 +60,15 @@ if not IMAGE_GGUF_PATH.exists():
58
  # Load code model (llama-cpp-python, CPU, loaded once at startup)
59
  # ---------------------------------------------------------------------------
60
 
61
- print("Loading Qwen2.5-Coder-7B into llama-cpp...")
62
  from llama_cpp import Llama
63
 
64
- code_llm = Llama(
65
- model_path=str(CODE_GGUF_PATH),
66
- n_ctx=4096, # context window
67
- n_threads=4, # CPU threads
68
- n_gpu_layers=0, # CPU only
 
69
  verbose=False,
70
  )
71
  print("Code model ready.")
@@ -291,7 +294,7 @@ def generate_game_code(game_type: str, theme: str, temperature: float, max_new_t
291
  )
292
 
293
  try:
294
- # Step 1: Generate HTML via Qwen2.5-Coder-7B (llama-cpp, CPU)
295
  response = code_llm.create_chat_completion(
296
  messages=[
297
  {"role": "system", "content": system_msg},
@@ -390,7 +393,7 @@ def build_ui():
390
 
391
  gr.Markdown(
392
  "# Game Generator (Local GGUF)\n"
393
- "**Qwen2.5-Coder-7B Q4** generates the game code (CPU). "
394
  "**Z-Image-Turbo Q2** generates sprites (ZeroGPU).\n"
395
  "Both models run locally — no API quota, no credits needed.\n\n"
396
  "> First generation takes a few minutes while models download and load. "
@@ -467,7 +470,7 @@ def build_ui():
467
 
468
  gr.Markdown(
469
  "---\n"
470
- "**Code:** Qwen2.5-Coder-7B-Instruct Q4_K_M GGUF (~4.5GB) via llama-cpp on CPU. "
471
  "**Images:** Z-Image-Turbo Q2_K GGUF (~3.6GB) via diffusers on ZeroGPU. "
472
  "Total disk: ~8GB of the 16GB free limit. No API calls, no quota."
473
  )
 
1
  """
2
  Text-to-Game Generator - Local GGUF Edition
3
+ - Code : WithinUsAI/Opus4.7-GODs.Ghost.Codex-4B.GGuF (~2-3GB, CPU via llama-cpp-python)
4
+ - Images: unsloth/Z-Image-Turbo-GGUF Q2_K (~3.6GB, GPU via ZeroGPU + diffusers)
5
 
6
+ Total disk usage: ~6GB — well within HF free Space 16GB storage limit.
7
  Space hardware : set to ZeroGPU (free) in Space settings.
8
 
9
  Models are downloaded on first startup and cached — subsequent starts are instant.
 
25
  # Model paths — downloaded once at startup, cached in /tmp
26
  # ---------------------------------------------------------------------------
27
 
28
+ GGUF_DIR = Path("/tmp/models")
29
+ IMAGE_GGUF_PATH = GGUF_DIR / "z-image-turbo-Q2_K.gguf"
 
30
 
31
  GGUF_DIR.mkdir(parents=True, exist_ok=True)
32
 
33
+ # Download code model — auto-detect filename from repo
34
+ CODE_REPO = "WithinUsAI/Opus4.7-GODs.Ghost.Codex-4B.GGuF"
35
+ CODE_FILENAME = "Opus4.7-Distill-GODsGhost-Codex-4B-Q4_K_M.gguf"
36
+ CODE_GGUF_PATH = GGUF_DIR / CODE_FILENAME
37
+
38
  if not CODE_GGUF_PATH.exists():
39
+ print("Downloading Opus4.7-GODs.Ghost.Codex-4B Q4_K_M GGUF...")
40
  hf_hub_download(
41
+ repo_id=CODE_REPO,
42
+ filename=CODE_FILENAME,
43
  local_dir=str(GGUF_DIR),
44
  local_dir_use_symlinks=False,
45
  )
 
46
  print("Code model downloaded.")
47
 
48
  # Download image model GGUF (Q2_K ~3.6GB, smallest that still works)
 
60
  # Load code model (llama-cpp-python, CPU, loaded once at startup)
61
  # ---------------------------------------------------------------------------
62
 
63
+ print("Loading Opus4.7-GODs.Ghost.Codex-4B into llama-cpp...")
64
  from llama_cpp import Llama
65
 
66
+ code_llm = Llama.from_pretrained(
67
+ repo_id=CODE_REPO,
68
+ filename=CODE_FILENAME,
69
+ n_ctx=4096,
70
+ n_threads=4,
71
+ n_gpu_layers=0,
72
  verbose=False,
73
  )
74
  print("Code model ready.")
 
294
  )
295
 
296
  try:
297
+ # Step 1: Generate HTML via Opus4.7-GODs.Ghost.Codex-4B (llama-cpp, CPU)
298
  response = code_llm.create_chat_completion(
299
  messages=[
300
  {"role": "system", "content": system_msg},
 
393
 
394
  gr.Markdown(
395
  "# Game Generator (Local GGUF)\n"
396
+ "**Opus4.7-GODs.Ghost.Codex-4B** generates the game code (CPU). "
397
  "**Z-Image-Turbo Q2** generates sprites (ZeroGPU).\n"
398
  "Both models run locally — no API quota, no credits needed.\n\n"
399
  "> First generation takes a few minutes while models download and load. "
 
470
 
471
  gr.Markdown(
472
  "---\n"
473
+ "**Code:** Opus4.7-GODs.Ghost.Codex-4B GGUF (~2-3GB) via llama-cpp on CPU. "
474
  "**Images:** Z-Image-Turbo Q2_K GGUF (~3.6GB) via diffusers on ZeroGPU. "
475
  "Total disk: ~8GB of the 16GB free limit. No API calls, no quota."
476
  )