Commit
·
f16951b
1
Parent(s):
e15a09f
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,22 +6,14 @@ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
| 6 |
def tokenize(text):
|
| 7 |
return text
|
| 8 |
# return tok.encode(text, add_special_tokens=False)
|
| 9 |
-
|
| 10 |
def format_prompt(message, history):
|
| 11 |
-
prompt = "
|
| 12 |
for user_prompt, bot_response in history:
|
| 13 |
-
prompt +=
|
| 14 |
-
prompt +=
|
| 15 |
-
prompt +=
|
| 16 |
return prompt
|
| 17 |
-
|
| 18 |
-
# def format_prompt(message, history):
|
| 19 |
-
# prompt = ""
|
| 20 |
-
# for user_prompt, bot_response in history:
|
| 21 |
-
# prompt += "<s>" + tokenize("[INST]") + tokenize(user_prompt) + tokenize("[/INST]")
|
| 22 |
-
# prompt += tokenize(bot_response) + "</s> "
|
| 23 |
-
# prompt += tokenize("[INST]") + tokenize(message) + tokenize("[/INST]")
|
| 24 |
-
# return prompt
|
| 25 |
|
| 26 |
def generate(prompt, history, system_prompt, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
| 27 |
temperature = float(temperature)
|
|
@@ -38,7 +30,6 @@ def generate(prompt, history, system_prompt, temperature=0.2, max_new_tokens=512
|
|
| 38 |
seed=42,
|
| 39 |
)
|
| 40 |
|
| 41 |
-
# formatted_prompt = format_prompt(prompt, history)
|
| 42 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
| 43 |
|
| 44 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
|
@@ -94,32 +85,15 @@ additional_inputs=[
|
|
| 94 |
)
|
| 95 |
]
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
# demo = gr.ChatInterface(fn=generate,
|
| 101 |
-
# chatbot=mychatbot,
|
| 102 |
-
# additional_inputs=additional_inputs,
|
| 103 |
-
# title="Kamran's Mixtral 8x7b Chat",
|
| 104 |
-
# retry_btn=None,
|
| 105 |
-
# undo_btn=None
|
| 106 |
-
# )
|
| 107 |
-
|
| 108 |
-
# demo.queue().launch(show_api=False)
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
-
|
| 119 |
-
fn=generate,
|
| 120 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
| 121 |
-
additional_inputs=additional_inputs,
|
| 122 |
-
title="Mixtral 46.7B",
|
| 123 |
-
examples=examples,
|
| 124 |
-
concurrency_limit=20,
|
| 125 |
-
).launch(show_api=False)
|
|
|
|
| 6 |
def tokenize(text):
|
| 7 |
return text
|
| 8 |
# return tok.encode(text, add_special_tokens=False)
|
| 9 |
+
|
| 10 |
def format_prompt(message, history):
|
| 11 |
+
prompt = ""
|
| 12 |
for user_prompt, bot_response in history:
|
| 13 |
+
prompt += "<s>" + tokenize("[INST]") + tokenize(user_prompt) + tokenize("[/INST]")
|
| 14 |
+
prompt += tokenize(bot_response) + "</s> "
|
| 15 |
+
prompt += tokenize("[INST]") + tokenize(message) + tokenize("[/INST]")
|
| 16 |
return prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def generate(prompt, history, system_prompt, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
| 19 |
temperature = float(temperature)
|
|
|
|
| 30 |
seed=42,
|
| 31 |
)
|
| 32 |
|
|
|
|
| 33 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
| 34 |
|
| 35 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
|
|
|
| 85 |
)
|
| 86 |
]
|
| 87 |
|
| 88 |
+
mychatbot = gr.Chatbot(
|
| 89 |
+
avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
demo = gr.ChatInterface(fn=generate,
|
| 92 |
+
chatbot=mychatbot,
|
| 93 |
+
additional_inputs=additional_inputs,
|
| 94 |
+
title="Kamran's Mixtral 8x7b Chat",
|
| 95 |
+
retry_btn=None,
|
| 96 |
+
undo_btn=None
|
| 97 |
+
)
|
| 98 |
|
| 99 |
+
demo.queue().launch(show_api=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|