Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|