Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,18 +16,14 @@ print("Your Computer IP Address is:" + IPAddr)
|
|
16 |
|
17 |
|
18 |
DESCRIPTION = """
|
19 |
-
# Breexe-8x7B-Instruct-
|
20 |
-
|
21 |
Breexe-8x7B is a language model family that builds on top of [Mixtral-8x7B](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1),
|
22 |
specifically intended for Traditional Chinese use. [Breexe-8x7B-Instruct-v0_1](https://huggingface.co/MediaTek-Research/Breexe-8x7B-Instruct-v0_1) demonstrates impressive performance in benchmarks for Traditional Chinese and English, on par with OpenAI's gpt3.5.
|
23 |
-
|
24 |
*A project by the members (in alphabetical order): Chan-Jan Hsu 許湛然, Chang-Le Liu 劉昶樂, Feng-Ting Liao 廖峰挺, Po-Chun Hsu 許博竣, Yi-Chang Chen 陳宜昌, and the supervisor Da-Shan Shiu 許大山.*
|
25 |
-
|
26 |
**免責聲明: Breexe-8x7B-Instruct 並未針對問答進行安全保護,因此語言模型的任何回應不代表 MediaTek Research 立場。**
|
27 |
"""
|
28 |
|
29 |
LICENSE = """
|
30 |
-
|
31 |
"""
|
32 |
|
33 |
DEFAULT_SYSTEM_PROMPT = "You are a helpful AI assistant built by MediaTek Research. The user you are helping speaks Traditional Chinese and comes from Taiwan."
|
@@ -45,7 +41,7 @@ HEADERS = {
|
|
45 |
MAX_SEC = 30
|
46 |
MAX_INPUT_LENGTH = 5000
|
47 |
|
48 |
-
tokenizer = AutoTokenizer.from_pretrained("MediaTek-Research/Breexe-8x7B-Instruct-v0_1")
|
49 |
|
50 |
def insert_to_db(prompt, response, temperature, top_p):
|
51 |
try:
|
@@ -96,40 +92,33 @@ with gr.Blocks() as demo:
|
|
96 |
gr.Markdown(DESCRIPTION)
|
97 |
|
98 |
system_prompt = gr.Textbox(label='System prompt',
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
with gr.Accordion(label='Advanced options', open=False):
|
103 |
-
|
104 |
-
max_new_tokens = gr.Slider(
|
105 |
-
label='Max new tokens',
|
106 |
-
minimum=32,
|
107 |
-
maximum=2048,
|
108 |
-
step=1,
|
109 |
-
value=1024,
|
110 |
-
)
|
111 |
-
temperature = gr.Slider(
|
112 |
-
label='Temperature',
|
113 |
-
minimum=0.01,
|
114 |
-
maximum=1.0,
|
115 |
-
step=0.01,
|
116 |
-
value=0.01,
|
117 |
-
)
|
118 |
-
top_p = gr.Slider(
|
119 |
-
label='Top-p (nucleus sampling)',
|
120 |
-
minimum=0.01,
|
121 |
-
maximum=0.99,
|
122 |
-
step=0.01,
|
123 |
-
value=0.01,
|
124 |
-
)
|
125 |
-
repetition_penalty = gr.Slider(
|
126 |
-
label='Repetition Penalty',
|
127 |
-
minimum=0.1,
|
128 |
-
maximum=2,
|
129 |
-
step=0.01,
|
130 |
-
value=1.1,
|
131 |
-
)
|
132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
chatbot = gr.Chatbot()
|
134 |
with gr.Row():
|
135 |
msg = gr.Textbox(
|
@@ -151,6 +140,9 @@ with gr.Blocks() as demo:
|
|
151 |
|
152 |
saved_input = gr.State()
|
153 |
|
|
|
|
|
|
|
154 |
def user(user_message, history):
|
155 |
return "", history + [[user_message, None]]
|
156 |
|
@@ -188,7 +180,7 @@ with gr.Blocks() as demo:
|
|
188 |
# start_time = time.time()
|
189 |
|
190 |
|
191 |
-
def bot(history, max_new_tokens, temperature, top_p, system_prompt
|
192 |
chat_data = []
|
193 |
system_prompt = system_prompt.strip()
|
194 |
if system_prompt:
|
@@ -210,19 +202,13 @@ with gr.Blocks() as demo:
|
|
210 |
yield history
|
211 |
else:
|
212 |
data = {
|
213 |
-
"model_type": "
|
214 |
"prompt": str(message),
|
215 |
"parameters": {
|
216 |
"temperature": float(temperature),
|
217 |
"top_p": float(top_p),
|
218 |
"max_new_tokens": int(max_new_tokens),
|
219 |
-
"repetition_penalty":
|
220 |
-
|
221 |
-
"num_beams":1, # w/o beam search
|
222 |
-
"typical_p":0.99,
|
223 |
-
"top_k":61952, # w/o top_k
|
224 |
-
"do_sample": True,
|
225 |
-
"min_length":1,
|
226 |
}
|
227 |
}
|
228 |
|
@@ -241,14 +227,13 @@ with gr.Blocks() as demo:
|
|
241 |
response = history[-1][1]
|
242 |
|
243 |
if refusal_condition(history[-1][1]):
|
244 |
-
history[-1][1] = history[-1][1] + '\n\n**[免責聲明:
|
245 |
yield history
|
246 |
else:
|
247 |
del history[-1]
|
248 |
yield history
|
249 |
|
250 |
print('== Record ==\nQuery: {query}\nResponse: {response}'.format(query=repr(message), response=repr(history[-1][1])))
|
251 |
-
insert_to_db(message, response, float(temperature), float(top_p))
|
252 |
|
253 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
254 |
fn=bot,
|
@@ -258,7 +243,6 @@ with gr.Blocks() as demo:
|
|
258 |
temperature,
|
259 |
top_p,
|
260 |
system_prompt,
|
261 |
-
repetition_penalty,
|
262 |
],
|
263 |
outputs=chatbot
|
264 |
)
|
@@ -272,7 +256,6 @@ with gr.Blocks() as demo:
|
|
272 |
temperature,
|
273 |
top_p,
|
274 |
system_prompt,
|
275 |
-
repetition_penalty,
|
276 |
],
|
277 |
outputs=chatbot
|
278 |
)
|
@@ -312,7 +295,6 @@ with gr.Blocks() as demo:
|
|
312 |
temperature,
|
313 |
top_p,
|
314 |
system_prompt,
|
315 |
-
repetition_penalty,
|
316 |
],
|
317 |
outputs=chatbot,
|
318 |
)
|
@@ -335,5 +317,5 @@ with gr.Blocks() as demo:
|
|
335 |
|
336 |
gr.Markdown(LICENSE)
|
337 |
|
338 |
-
demo.queue(concurrency_count=
|
339 |
-
demo.launch()
|
|
|
16 |
|
17 |
|
18 |
DESCRIPTION = """
|
19 |
+
# Breexe-8x7B-Instruct-v0.1
|
|
|
20 |
Breexe-8x7B is a language model family that builds on top of [Mixtral-8x7B](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1),
|
21 |
specifically intended for Traditional Chinese use. [Breexe-8x7B-Instruct-v0_1](https://huggingface.co/MediaTek-Research/Breexe-8x7B-Instruct-v0_1) demonstrates impressive performance in benchmarks for Traditional Chinese and English, on par with OpenAI's gpt3.5.
|
|
|
22 |
*A project by the members (in alphabetical order): Chan-Jan Hsu 許湛然, Chang-Le Liu 劉昶樂, Feng-Ting Liao 廖峰挺, Po-Chun Hsu 許博竣, Yi-Chang Chen 陳宜昌, and the supervisor Da-Shan Shiu 許大山.*
|
|
|
23 |
**免責聲明: Breexe-8x7B-Instruct 並未針對問答進行安全保護,因此語言模型的任何回應不代表 MediaTek Research 立場。**
|
24 |
"""
|
25 |
|
26 |
LICENSE = """
|
|
|
27 |
"""
|
28 |
|
29 |
DEFAULT_SYSTEM_PROMPT = "You are a helpful AI assistant built by MediaTek Research. The user you are helping speaks Traditional Chinese and comes from Taiwan."
|
|
|
41 |
MAX_SEC = 30
|
42 |
MAX_INPUT_LENGTH = 5000
|
43 |
|
44 |
+
tokenizer = AutoTokenizer.from_pretrained("MediaTek-Research/Breexe-8x7B-Instruct-v0_1", use_auth_token=os.environ.get("HF_TOKEN"))
|
45 |
|
46 |
def insert_to_db(prompt, response, temperature, top_p):
|
47 |
try:
|
|
|
92 |
gr.Markdown(DESCRIPTION)
|
93 |
|
94 |
system_prompt = gr.Textbox(label='System prompt',
|
95 |
+
value=DEFAULT_SYSTEM_PROMPT,
|
96 |
+
lines=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
with gr.Accordion(label='Advanced options', open=False):
|
99 |
+
|
100 |
+
max_new_tokens = gr.Slider(
|
101 |
+
label='Max new tokens',
|
102 |
+
minimum=32,
|
103 |
+
maximum=2048,
|
104 |
+
step=1,
|
105 |
+
value=1024,
|
106 |
+
)
|
107 |
+
temperature = gr.Slider(
|
108 |
+
label='Temperature',
|
109 |
+
minimum=0.01,
|
110 |
+
maximum=0.5,
|
111 |
+
step=0.01,
|
112 |
+
value=0.01,
|
113 |
+
)
|
114 |
+
top_p = gr.Slider(
|
115 |
+
label='Top-p (nucleus sampling)',
|
116 |
+
minimum=0.01,
|
117 |
+
maximum=0.99,
|
118 |
+
step=0.01,
|
119 |
+
value=0.01,
|
120 |
+
)
|
121 |
+
|
122 |
chatbot = gr.Chatbot()
|
123 |
with gr.Row():
|
124 |
msg = gr.Textbox(
|
|
|
140 |
|
141 |
saved_input = gr.State()
|
142 |
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
def user(user_message, history):
|
147 |
return "", history + [[user_message, None]]
|
148 |
|
|
|
180 |
# start_time = time.time()
|
181 |
|
182 |
|
183 |
+
def bot(history, max_new_tokens, temperature, top_p, system_prompt):
|
184 |
chat_data = []
|
185 |
system_prompt = system_prompt.strip()
|
186 |
if system_prompt:
|
|
|
202 |
yield history
|
203 |
else:
|
204 |
data = {
|
205 |
+
"model_type": "breexe-8x7b-instruct-v01",
|
206 |
"prompt": str(message),
|
207 |
"parameters": {
|
208 |
"temperature": float(temperature),
|
209 |
"top_p": float(top_p),
|
210 |
"max_new_tokens": int(max_new_tokens),
|
211 |
+
"repetition_penalty": 1.1
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
}
|
213 |
}
|
214 |
|
|
|
227 |
response = history[-1][1]
|
228 |
|
229 |
if refusal_condition(history[-1][1]):
|
230 |
+
history[-1][1] = history[-1][1] + '\n\n**[免責聲明: Breexe-8x7B-Instruct 和 Breexe-8x7B-Instruct-64k 並未針對問答進行安全保護,因此語言模型的任何回應不代表 MediaTek Research 立場。]**'
|
231 |
yield history
|
232 |
else:
|
233 |
del history[-1]
|
234 |
yield history
|
235 |
|
236 |
print('== Record ==\nQuery: {query}\nResponse: {response}'.format(query=repr(message), response=repr(history[-1][1])))
|
|
|
237 |
|
238 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
239 |
fn=bot,
|
|
|
243 |
temperature,
|
244 |
top_p,
|
245 |
system_prompt,
|
|
|
246 |
],
|
247 |
outputs=chatbot
|
248 |
)
|
|
|
256 |
temperature,
|
257 |
top_p,
|
258 |
system_prompt,
|
|
|
259 |
],
|
260 |
outputs=chatbot
|
261 |
)
|
|
|
295 |
temperature,
|
296 |
top_p,
|
297 |
system_prompt,
|
|
|
298 |
],
|
299 |
outputs=chatbot,
|
300 |
)
|
|
|
317 |
|
318 |
gr.Markdown(LICENSE)
|
319 |
|
320 |
+
demo.queue(concurrency_count=4, max_size=128)
|
321 |
+
demo.launch()
|