lljz66 commited on
Commit
1def405
·
verified ·
1 Parent(s): e17c856

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -1,22 +1,31 @@
1
  from llama_cpp import Llama
2
  import gradio as gr
3
 
4
- # 🦙 Llama model (bartowski GGUF)
5
- llm = Llama.from_pretrained(
6
- repo_id="bartowski/Llama-3.2-3B-Instruct-uncensored-GGUF",
7
- filename="Llama-3.2-3B-Instruct-uncensored-Q4_K_M.gguf",
8
- n_ctx=4096,
9
- n_threads=2,
10
- verbose=False
11
- )
 
 
 
 
 
 
 
12
 
13
  def chat(message, history):
 
 
14
  prompt = f"""<|im_start|>user
15
  {message}<|im_end|>
16
  <|im_start|>assistant
17
  """
18
 
19
- output = llm(
20
  prompt,
21
  max_tokens=512,
22
  temperature=0.7,
@@ -29,4 +38,8 @@ def chat(message, history):
29
  response += chunk["choices"][0]["text"]
30
  yield response
31
 
32
- gr.ChatInterface(chat, title="🦙 Llama 3.2 3B Chat").launch()
 
 
 
 
 
1
  from llama_cpp import Llama
2
  import gradio as gr
3
 
4
+ # 🔁 Lazy loading (important to avoid OOM)
5
+ llm = None
6
+
7
+ def load_model():
8
+ global llm
9
+ if llm is None:
10
+ llm = Llama.from_pretrained(
11
+ repo_id="bartowski/microsoft_Phi-4-mini-instruct-GGUF",
12
+ filename="microsoft_Phi-4-mini-instruct-Q4_K_M.gguf",
13
+ n_ctx=2048, # lower = less RAM
14
+ n_threads=2,
15
+ verbose=False
16
+ )
17
+ return llm
18
+
19
 
20
  def chat(message, history):
21
+ model = load_model()
22
+
23
  prompt = f"""<|im_start|>user
24
  {message}<|im_end|>
25
  <|im_start|>assistant
26
  """
27
 
28
+ output = model(
29
  prompt,
30
  max_tokens=512,
31
  temperature=0.7,
 
38
  response += chunk["choices"][0]["text"]
39
  yield response
40
 
41
+
42
+ gr.ChatInterface(
43
+ chat,
44
+ title="🧠 Phi-4 Mini (CPU Stable Space)"
45
+ ).launch()