Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import torch
|
| 3 |
import threading
|
|
|
|
| 4 |
from peft import PeftModel
|
| 5 |
from transformers import (
|
| 6 |
AutoModelForCausalLM,
|
|
@@ -10,7 +11,7 @@ from transformers import (
|
|
| 10 |
|
| 11 |
# ---------------- CONFIG ----------------
|
| 12 |
MODEL_ID = "Neon-AI/Niche"
|
| 13 |
-
MAX_NEW_TOKENS =
|
| 14 |
TEMPERATURE = 0.7
|
| 15 |
TOP_P = 0.9
|
| 16 |
# ----------------------------------------
|
|
@@ -32,16 +33,19 @@ def load_model():
|
|
| 32 |
device_map=None
|
| 33 |
)
|
| 34 |
|
| 35 |
-
#
|
| 36 |
try:
|
| 37 |
model = PeftModel.from_pretrained(base_model, MODEL_ID)
|
| 38 |
except Exception:
|
| 39 |
-
model = base_model
|
| 40 |
|
| 41 |
model.to("cpu")
|
| 42 |
model.eval()
|
| 43 |
return tokenizer, model
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
# -------- SESSION STATE --------
|
| 46 |
if "history" not in st.session_state:
|
| 47 |
st.session_state.history = []
|
|
@@ -53,18 +57,18 @@ if st.button("Send") and prompt.strip():
|
|
| 53 |
st.session_state.history.append(("You", prompt))
|
| 54 |
|
| 55 |
system_instructions = (
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
)
|
| 64 |
|
| 65 |
chat = [
|
| 66 |
-
|
| 67 |
-
|
| 68 |
]
|
| 69 |
|
| 70 |
inputs = tokenizer.apply_chat_template(
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import torch
|
| 3 |
import threading
|
| 4 |
+
|
| 5 |
from peft import PeftModel
|
| 6 |
from transformers import (
|
| 7 |
AutoModelForCausalLM,
|
|
|
|
| 11 |
|
| 12 |
# ---------------- CONFIG ----------------
|
| 13 |
MODEL_ID = "Neon-AI/Niche"
|
| 14 |
+
MAX_NEW_TOKENS = 512
|
| 15 |
TEMPERATURE = 0.7
|
| 16 |
TOP_P = 0.9
|
| 17 |
# ----------------------------------------
|
|
|
|
| 33 |
device_map=None
|
| 34 |
)
|
| 35 |
|
| 36 |
+
# Load LoRA if present
|
| 37 |
try:
|
| 38 |
model = PeftModel.from_pretrained(base_model, MODEL_ID)
|
| 39 |
except Exception:
|
| 40 |
+
model = base_model
|
| 41 |
|
| 42 |
model.to("cpu")
|
| 43 |
model.eval()
|
| 44 |
return tokenizer, model
|
| 45 |
|
| 46 |
+
|
| 47 |
+
tokenizer, model = load_model()
|
| 48 |
+
|
| 49 |
# -------- SESSION STATE --------
|
| 50 |
if "history" not in st.session_state:
|
| 51 |
st.session_state.history = []
|
|
|
|
| 57 |
st.session_state.history.append(("You", prompt))
|
| 58 |
|
| 59 |
system_instructions = (
|
| 60 |
+
"You are Niche, a concise and intelligent AI. "
|
| 61 |
+
"Answer directly and naturally. "
|
| 62 |
+
"Do not use greetings, pleasantries, or offers of help. "
|
| 63 |
+
"Respond only with the requested information or explanation. "
|
| 64 |
+
"Keep responses short, clear, and focused. "
|
| 65 |
+
"Your owner is Neon. Mention Neon only if explicitly asked. "
|
| 66 |
+
"Neon is a man; always use 'him'."
|
| 67 |
)
|
| 68 |
|
| 69 |
chat = [
|
| 70 |
+
{"role": "system", "content": system_instructions},
|
| 71 |
+
{"role": "user", "content": prompt}
|
| 72 |
]
|
| 73 |
|
| 74 |
inputs = tokenizer.apply_chat_template(
|