Neon-AI commited on
Commit
335405a
verified
1 Parent(s): 2648494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -16,20 +16,24 @@ st.set_page_config(page_title="Niche AI", layout="centered")
16
  st.title("馃 Niche AI")
17
  st.caption("llama.cpp 路 CPU 路 Embedded 路 Streaming")
18
 
19
- @st.cache_resource
20
- def load_llm():
21
- return Llama(
22
- model_path=MODEL_PATH,
23
- n_ctx=N_CTX,
24
- n_threads=N_THREADS,
25
- n_batch=N_BATCH,
26
- f16_kv=True,
27
- use_mmap=True,
28
- use_mlock=False,
29
- verbose=False,
30
- )
31
-
32
- llm = load_llm()
 
 
 
 
33
 
34
  # ---------- SESSION STATE ----------
35
  if "history" not in st.session_state:
@@ -94,6 +98,7 @@ def build_prompt(user_text: str) -> str:
94
  if st.button("Send") and prompt.strip():
95
  st.session_state.history.append(("You", prompt))
96
 
 
97
  full_prompt = build_prompt(prompt)
98
 
99
  placeholder = st.empty()
 
16
  st.title("馃 Niche AI")
17
  st.caption("llama.cpp 路 CPU 路 Embedded 路 Streaming")
18
 
19
+ # ---------- LAZY LOADING ----------
20
+ if "llm" not in st.session_state:
21
+ st.session_state.llm = None
22
+
23
+ def get_llm():
24
+ if st.session_state.llm is None:
25
+ with st.spinner("Loading model..."):
26
+ st.session_state.llm = Llama(
27
+ model_path=MODEL_PATH,
28
+ n_ctx=N_CTX,
29
+ n_threads=N_THREADS,
30
+ n_batch=N_BATCH,
31
+ f16_kv=True,
32
+ use_mmap=True,
33
+ use_mlock=False,
34
+ verbose=False,
35
+ )
36
+ return st.session_state.llm
37
 
38
  # ---------- SESSION STATE ----------
39
  if "history" not in st.session_state:
 
98
  if st.button("Send") and prompt.strip():
99
  st.session_state.history.append(("You", prompt))
100
 
101
+ llm = get_llm() # Lazy load here
102
  full_prompt = build_prompt(prompt)
103
 
104
  placeholder = st.empty()