MaziyarPanahi
commited on
Commit
•
950c25c
1
Parent(s):
e75173f
update the design
Browse files
app.py
CHANGED
@@ -20,13 +20,6 @@ headers = {
|
|
20 |
"Authorization": f"Bearer {API_KEY}",
|
21 |
}
|
22 |
|
23 |
-
sys_msg = [
|
24 |
-
{
|
25 |
-
"content": "You are a helpful assistant. Be respectful, professional, and try to be helpful. If you don't know something, just say \"I don't know\"",
|
26 |
-
"role": "system",
|
27 |
-
}
|
28 |
-
]
|
29 |
-
|
30 |
|
31 |
def is_valid_json(data):
|
32 |
try:
|
@@ -40,12 +33,19 @@ def is_valid_json(data):
|
|
40 |
|
41 |
with gr.Blocks() as demo:
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
chatbot = gr.Chatbot()
|
44 |
-
msg = gr.Textbox()
|
45 |
clear = gr.Button("Clear")
|
46 |
with gr.Row():
|
47 |
|
48 |
-
with gr.Column(scale=
|
49 |
# Define inputs for additional parameters
|
50 |
system_prompt_input = gr.Textbox(
|
51 |
label="System Prompt",
|
@@ -58,27 +58,31 @@ with gr.Blocks() as demo:
|
|
58 |
max_new_tokens_input = gr.Slider(
|
59 |
label="Max New Tokens", minimum=0, maximum=1024, value=256, step=1
|
60 |
)
|
|
|
|
|
61 |
top_p_input = gr.Slider(
|
62 |
-
label="Top P", minimum=0.0, maximum=1.0, value=0.
|
|
|
|
|
|
|
63 |
)
|
64 |
repetition_penalty_input = gr.Slider(
|
65 |
label="Repetition Penalty",
|
66 |
minimum=1.0,
|
67 |
maximum=2.0,
|
68 |
-
value=1.
|
69 |
step=0.01,
|
70 |
)
|
71 |
-
with gr.Column(scale=1):
|
72 |
-
markup = gr.Markdown("## Mistral 7B Instruct v0.2 GGUF")
|
73 |
|
74 |
def update_globals(
|
75 |
-
system_prompt, temperature, max_new_tokens, top_p, repetition_penalty
|
76 |
):
|
77 |
-
global global_system_prompt, global_temperature, global_max_new_tokens, global_top_p, global_repetition_penalty
|
78 |
global_system_prompt = system_prompt
|
79 |
global_temperature = temperature
|
80 |
global_max_new_tokens = max_new_tokens
|
81 |
global_top_p = top_p
|
|
|
82 |
global_repetition_penalty = repetition_penalty
|
83 |
|
84 |
def user(user_message, history):
|
@@ -87,13 +91,20 @@ with gr.Blocks() as demo:
|
|
87 |
return "", history + [[user_message, None]]
|
88 |
|
89 |
def bot(
|
90 |
-
history,
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
):
|
92 |
print(f"History in bot: {history}")
|
93 |
print(f"System Prompt: {system_prompt}")
|
94 |
print(f"Temperature: {temperature}")
|
95 |
print(f"Max New Tokens: {max_new_tokens}")
|
96 |
print(f"Top P: {top_p}")
|
|
|
97 |
print(f"Repetition Penalty: {repetition_penalty}")
|
98 |
|
99 |
# print(f"History in bot: {history}")
|
@@ -103,7 +114,14 @@ with gr.Blocks() as demo:
|
|
103 |
# let's extract the user's question which should be the last touple first element
|
104 |
# user_question = history[-1][0]
|
105 |
history[-1][1] = ""
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
history_messages = sys_msg + history_messages
|
108 |
print(history_messages)
|
109 |
|
@@ -111,8 +129,8 @@ with gr.Blocks() as demo:
|
|
111 |
"messages": history_messages,
|
112 |
"stream": True,
|
113 |
"temprature": temperature,
|
114 |
-
"top_k":
|
115 |
-
"top_p":
|
116 |
"seed": 42,
|
117 |
"repeat_penalty": repetition_penalty,
|
118 |
"chat_format": "mistral-instruct",
|
@@ -167,6 +185,7 @@ with gr.Blocks() as demo:
|
|
167 |
temperature_input,
|
168 |
max_new_tokens_input,
|
169 |
top_p_input,
|
|
|
170 |
repetition_penalty_input,
|
171 |
],
|
172 |
outputs=chatbot,
|
|
|
20 |
"Authorization": f"Bearer {API_KEY}",
|
21 |
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def is_valid_json(data):
|
25 |
try:
|
|
|
33 |
|
34 |
with gr.Blocks() as demo:
|
35 |
|
36 |
+
markup = gr.Markdown(
|
37 |
+
"""
|
38 |
+
# Mistral 7B Instruct v0.2
|
39 |
+
This is a demo of the Mistral 7B Instruct quantized model in GGUF (Q2) hosted on K8s cluster.
|
40 |
+
|
41 |
+
The original models can be found [MaziyarPanahi/Mistral-7B-Instruct-v0.2-GGUF](https://huggingface.co/MaziyarPanahi/Mistral-7B-Instruct-v0.2-GGUF)"""
|
42 |
+
)
|
43 |
chatbot = gr.Chatbot()
|
44 |
+
msg = gr.Textbox(lines=1, label="User Message")
|
45 |
clear = gr.Button("Clear")
|
46 |
with gr.Row():
|
47 |
|
48 |
+
with gr.Column(scale=2):
|
49 |
# Define inputs for additional parameters
|
50 |
system_prompt_input = gr.Textbox(
|
51 |
label="System Prompt",
|
|
|
58 |
max_new_tokens_input = gr.Slider(
|
59 |
label="Max New Tokens", minimum=0, maximum=1024, value=256, step=1
|
60 |
)
|
61 |
+
|
62 |
+
with gr.Column(scale=2):
|
63 |
top_p_input = gr.Slider(
|
64 |
+
label="Top P", minimum=0.0, maximum=1.0, value=0.95, step=0.01
|
65 |
+
)
|
66 |
+
top_k_input = gr.Slider(
|
67 |
+
label="Top K", minimum=1, maximum=100, value=50, step=1
|
68 |
)
|
69 |
repetition_penalty_input = gr.Slider(
|
70 |
label="Repetition Penalty",
|
71 |
minimum=1.0,
|
72 |
maximum=2.0,
|
73 |
+
value=1.1,
|
74 |
step=0.01,
|
75 |
)
|
|
|
|
|
76 |
|
77 |
def update_globals(
|
78 |
+
system_prompt, temperature, max_new_tokens, top_p, top_k, repetition_penalty
|
79 |
):
|
80 |
+
global global_system_prompt, global_temperature, global_max_new_tokens, global_top_p, global_repetition_penalty, global_top_k
|
81 |
global_system_prompt = system_prompt
|
82 |
global_temperature = temperature
|
83 |
global_max_new_tokens = max_new_tokens
|
84 |
global_top_p = top_p
|
85 |
+
global_top_k = top_k
|
86 |
global_repetition_penalty = repetition_penalty
|
87 |
|
88 |
def user(user_message, history):
|
|
|
91 |
return "", history + [[user_message, None]]
|
92 |
|
93 |
def bot(
|
94 |
+
history,
|
95 |
+
system_prompt,
|
96 |
+
temperature,
|
97 |
+
max_new_tokens,
|
98 |
+
top_p,
|
99 |
+
top_k,
|
100 |
+
repetition_penalty,
|
101 |
):
|
102 |
print(f"History in bot: {history}")
|
103 |
print(f"System Prompt: {system_prompt}")
|
104 |
print(f"Temperature: {temperature}")
|
105 |
print(f"Max New Tokens: {max_new_tokens}")
|
106 |
print(f"Top P: {top_p}")
|
107 |
+
print(f"Top K: {top_k}")
|
108 |
print(f"Repetition Penalty: {repetition_penalty}")
|
109 |
|
110 |
# print(f"History in bot: {history}")
|
|
|
114 |
# let's extract the user's question which should be the last touple first element
|
115 |
# user_question = history[-1][0]
|
116 |
history[-1][1] = ""
|
117 |
+
sys_msg = [
|
118 |
+
{
|
119 |
+
"content": (
|
120 |
+
system_prompt if system_prompt else "You are a helpful assistant."
|
121 |
+
),
|
122 |
+
"role": "system",
|
123 |
+
}
|
124 |
+
]
|
125 |
history_messages = sys_msg + history_messages
|
126 |
print(history_messages)
|
127 |
|
|
|
129 |
"messages": history_messages,
|
130 |
"stream": True,
|
131 |
"temprature": temperature,
|
132 |
+
"top_k": top_k,
|
133 |
+
"top_p": top_p,
|
134 |
"seed": 42,
|
135 |
"repeat_penalty": repetition_penalty,
|
136 |
"chat_format": "mistral-instruct",
|
|
|
185 |
temperature_input,
|
186 |
max_new_tokens_input,
|
187 |
top_p_input,
|
188 |
+
top_k_input,
|
189 |
repetition_penalty_input,
|
190 |
],
|
191 |
outputs=chatbot,
|