Drakkarious commited on
Commit
399b95d
·
verified ·
1 Parent(s): b7bb791

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -6,44 +6,45 @@ from llama_cpp import Llama
6
  # 1. Faster downloads
7
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
8
 
9
- # 2. Define local paths
10
  CACHE_DIR = os.path.join(os.getcwd(), "model_cache")
11
 
12
- print("--- Starting AI Sandbox ---")
 
13
  try:
14
- print("--- Downloading 26B Model (16.7GB) to local cache ---")
15
  model_path = hf_hub_download(
16
  repo_id="BugTraceAI/BugTraceAI-Apex-G4-26B-Q4",
17
  filename="BugTraceAI-Apex-G4-26B-Q4.gguf",
18
  cache_dir=CACHE_DIR
19
  )
20
 
21
- print(f"--- Loading Model: {model_path} ---")
22
- # Low-RAM configuration for Free Tier
23
  llm = Llama(
24
  model_path=model_path,
25
  n_ctx=2048,
26
  n_threads=2,
27
- use_mmap=True, # Critical for large models on 16GB RAM
28
- n_gpu_layers=0 # CPU Only
29
  )
30
 
31
- def chat(prompt):
 
 
 
 
 
 
 
 
 
32
  output = llm(
33
- f"User: {prompt}\nAssistant:",
34
  max_tokens=256,
35
  stop=["User:", "\n"],
36
  echo=False
37
  )
38
- return output["choices"][0]["text"]
39
-
40
- print("\n✅ Sandbox Ready!")
41
- print("To chat, use the logs terminal or call: chat('your prompt')")
42
-
43
- # Keeps the container alive and interactive
44
- import IPython
45
- IPython.embed()
46
 
47
  except Exception as e:
48
- print(f"❌ Error during startup: {e}")
49
  sys.exit(1)
 
6
  # 1. Faster downloads
7
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
8
 
 
9
  CACHE_DIR = os.path.join(os.getcwd(), "model_cache")
10
 
11
+ print("--- Initializing AI Sandbox ---")
12
+
13
  try:
14
+ print("--- Downloading Model (16.7GB)... This will take a moment. ---")
15
  model_path = hf_hub_download(
16
  repo_id="BugTraceAI/BugTraceAI-Apex-G4-26B-Q4",
17
  filename="BugTraceAI-Apex-G4-26B-Q4.gguf",
18
  cache_dir=CACHE_DIR
19
  )
20
 
21
+ print(f"--- Loading Model into RAM (mmap enabled) ---")
 
22
  llm = Llama(
23
  model_path=model_path,
24
  n_ctx=2048,
25
  n_threads=2,
26
+ use_mmap=True,
27
+ n_gpu_layers=0
28
  )
29
 
30
+ print("\n✅ SANDBOX READY")
31
+ print("------------------------------------------")
32
+ print("Enter your prompt below. Type 'exit' to quit.")
33
+
34
+ # Standard terminal loop (Stable for Docker Logs)
35
+ while True:
36
+ user_input = input("\n[Terminal] User: ")
37
+ if user_input.lower() in ["exit", "quit"]:
38
+ break
39
+
40
  output = llm(
41
+ f"User: {user_input}\nAssistant:",
42
  max_tokens=256,
43
  stop=["User:", "\n"],
44
  echo=False
45
  )
46
+ print(f"Assistant: {output['choices'][0]['text']}")
 
 
 
 
 
 
 
47
 
48
  except Exception as e:
49
+ print(f"❌ CRITICAL ERROR: {e}")
50
  sys.exit(1)