Drakkarious commited on
Commit
715d004
·
verified ·
1 Parent(s): 85bc0f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -26
app.py CHANGED
@@ -1,36 +1,49 @@
1
  import os
 
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
 
5
- # Enable fast downloads
6
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
7
 
8
- print("--- Downloading Model (this may take a few minutes) ---")
9
- # Download the GGUF file
10
- model_path = hf_hub_download(
11
- repo_id="BugTraceAI/BugTraceAI-Apex-G4-26B-Q4",
12
- filename="BugTraceAI-Apex-G4-26B-Q4.gguf"
13
- )
14
 
15
- print(f"--- Loading Model from {model_path} ---")
16
- # Initialize the model with memory mapping for large MoE models
17
- llm = Llama(
18
- model_path=model_path,
19
- n_ctx=2048, # Context window
20
- n_threads=2, # Free tier CPU cores
21
- use_mmap=True, # CRITICAL: Allows 16.7GB model to run on 16GB RAM
22
- n_gpu_layers=0 # CPU only for free tier
23
- )
24
 
25
- def chat(prompt):
26
- """Function to call from your terminal"""
27
- output = llm(
28
- f"Prompt: {prompt}\nResponse:",
29
- max_tokens=256,
30
- stop=["Prompt:", "\n"],
31
- echo=False
 
32
  )
33
- return output["choices"][0]["text"]
34
 
35
- print("\n🚀 AI Sandbox Ready!")
36
- print("Type: chat('your question') to interact.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import sys
3
  from huggingface_hub import hf_hub_download
4
  from llama_cpp import Llama
5
 
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)