Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,19 +2,25 @@ import gradio as gr
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
|
4 |
# ---------------- CONFIG ----------------
|
5 |
-
MODEL_NAME = "
|
6 |
SYSTEM_PROMPT_DEFAULT = (
|
7 |
"You are a formal and polite AI assistant. "
|
8 |
"Always respond appropriately depending on the selected explanation style."
|
9 |
)
|
10 |
|
11 |
MAX_NEW_TOKENS_DEFAULT = 256
|
12 |
-
TEMP_DEFAULT = 0.
|
13 |
TOP_P_DEFAULT = 0.9
|
14 |
|
15 |
# ---------------- LOAD MODEL ----------------
|
16 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
generator = pipeline(
|
19 |
"text-generation",
|
20 |
model=model,
|
@@ -61,7 +67,7 @@ def chat(user_message, chat_history, system_message, max_tokens, temperature, to
|
|
61 |
|
62 |
# ---------------- UI ----------------
|
63 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="pink")) as demo:
|
64 |
-
gr.Markdown("# 🧠
|
65 |
|
66 |
chatbot = gr.Chatbot(type="messages", height=500, show_copy_button=True)
|
67 |
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
|
4 |
# ---------------- CONFIG ----------------
|
5 |
+
MODEL_NAME = "mosaicml/mpt-7b-instruct" # Fully open-source, no gated access
|
6 |
SYSTEM_PROMPT_DEFAULT = (
|
7 |
"You are a formal and polite AI assistant. "
|
8 |
"Always respond appropriately depending on the selected explanation style."
|
9 |
)
|
10 |
|
11 |
MAX_NEW_TOKENS_DEFAULT = 256
|
12 |
+
TEMP_DEFAULT = 0.7
|
13 |
TOP_P_DEFAULT = 0.9
|
14 |
|
15 |
# ---------------- LOAD MODEL ----------------
|
16 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
17 |
+
|
18 |
+
model = AutoModelForCausalLM.from_pretrained(
|
19 |
+
MODEL_NAME,
|
20 |
+
trust_remote_code=True, # required for MPT
|
21 |
+
torch_dtype="auto"
|
22 |
+
)
|
23 |
+
|
24 |
generator = pipeline(
|
25 |
"text-generation",
|
26 |
model=model,
|
|
|
67 |
|
68 |
# ---------------- UI ----------------
|
69 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="pink")) as demo:
|
70 |
+
gr.Markdown("# 🧠 MPT-7B Instruct Chat Assistant")
|
71 |
|
72 |
chatbot = gr.Chatbot(type="messages", height=500, show_copy_button=True)
|
73 |
|