Spaces:
Running
Running
Adjusted the model for concise responses
Browse files
app.py
CHANGED
@@ -3,9 +3,12 @@ from huggingface_hub import InferenceClient
|
|
3 |
|
4 |
# ---------------- CONFIG ----------------
|
5 |
MODEL_REPO = "HuggingFaceH4/zephyr-7b-beta"
|
6 |
-
SYSTEM_PROMPT_DEFAULT =
|
|
|
|
|
|
|
7 |
|
8 |
-
MAX_NEW_TOKENS_DEFAULT =
|
9 |
TEMP_DEFAULT = 0.7
|
10 |
TOP_P_DEFAULT = 0.95
|
11 |
|
@@ -13,14 +16,15 @@ TOP_P_DEFAULT = 0.95
|
|
13 |
client = InferenceClient(MODEL_REPO)
|
14 |
|
15 |
# ---------------- CHAT FUNCTION ----------------
|
16 |
-
def stream_response(message, chat_history, system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
messages = [{"role": "system", "content": system_message}]
|
18 |
-
for user_msg, bot_msg in chat_history:
|
19 |
-
if user_msg:
|
20 |
-
messages.append({"role": "user", "content": user_msg})
|
21 |
-
if bot_msg:
|
22 |
-
messages.append({"role": "assistant", "content": bot_msg})
|
23 |
-
messages.append({"role": "user", "content": message})
|
24 |
|
25 |
response = ""
|
26 |
for msg in client.chat_completion(
|
@@ -73,14 +77,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="pink"))
|
|
73 |
|
74 |
# Events (streaming response)
|
75 |
send_btn.click(
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
)
|
80 |
msg.submit(
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
)
|
85 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
86 |
|
|
|
3 |
|
4 |
# ---------------- CONFIG ----------------
|
5 |
MODEL_REPO = "HuggingFaceH4/zephyr-7b-beta"
|
6 |
+
SYSTEM_PROMPT_DEFAULT = (
|
7 |
+
"You are Zephyr, a concise and polite AI assistant. "
|
8 |
+
"Answer briefly unless the user specifically asks for detail."
|
9 |
+
)
|
10 |
|
11 |
+
MAX_NEW_TOKENS_DEFAULT = 128
|
12 |
TEMP_DEFAULT = 0.7
|
13 |
TOP_P_DEFAULT = 0.95
|
14 |
|
|
|
16 |
client = InferenceClient(MODEL_REPO)
|
17 |
|
18 |
# ---------------- CHAT FUNCTION ----------------
|
19 |
+
def stream_response(message, chat_history, system_message, max_tokens, temperature, top_p, response_style):
|
20 |
+
if response_style == "concise":
|
21 |
+
system_message += " Keep answers short and direct."
|
22 |
+
elif response_style == "detailed":
|
23 |
+
system_message += " Provide more explanation and context when helpful."
|
24 |
+
elif response_style == "essay":
|
25 |
+
system_message += " Write long, structured, essay-style responses."
|
26 |
+
|
27 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
response = ""
|
30 |
for msg in client.chat_completion(
|
|
|
77 |
|
78 |
# Events (streaming response)
|
79 |
send_btn.click(
|
80 |
+
stream_response,
|
81 |
+
[msg, chatbot, system_prompt, max_tokens, temperature, top_p, response_style],
|
82 |
+
[msg, chatbot]
|
83 |
)
|
84 |
msg.submit(
|
85 |
+
stream_response,
|
86 |
+
[msg, chatbot, system_prompt, max_tokens, temperature, top_p, response_style],
|
87 |
+
[msg, chatbot]
|
88 |
)
|
89 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
90 |
|