Spaces:
Sleeping
Sleeping
Commit
·
55b11ff
1
Parent(s):
39430d9
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,21 @@
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
client = InferenceClient(
|
| 5 |
-
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 6 |
-
)
|
| 7 |
-
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def format_prompt(message, history):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
def generate(
|
| 18 |
-
prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
| 19 |
-
):
|
| 20 |
temperature = float(temperature)
|
| 21 |
if temperature < 1e-2:
|
| 22 |
temperature = 1e-2
|
|
@@ -31,7 +30,8 @@ def generate(
|
|
| 31 |
seed=42,
|
| 32 |
)
|
| 33 |
|
| 34 |
-
formatted_prompt = format_prompt(
|
|
|
|
| 35 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 36 |
output = ""
|
| 37 |
|
|
@@ -49,7 +49,7 @@ additional_inputs=[
|
|
| 49 |
),
|
| 50 |
gr.Slider(
|
| 51 |
label="Temperature",
|
| 52 |
-
value=0.
|
| 53 |
minimum=0.0,
|
| 54 |
maximum=1.0,
|
| 55 |
step=0.05,
|
|
@@ -58,7 +58,7 @@ additional_inputs=[
|
|
| 58 |
),
|
| 59 |
gr.Slider(
|
| 60 |
label="Max new tokens",
|
| 61 |
-
value=
|
| 62 |
minimum=0,
|
| 63 |
maximum=1048,
|
| 64 |
step=64,
|
|
@@ -67,7 +67,7 @@ additional_inputs=[
|
|
| 67 |
),
|
| 68 |
gr.Slider(
|
| 69 |
label="Top-p (nucleus sampling)",
|
| 70 |
-
value=0.
|
| 71 |
minimum=0.0,
|
| 72 |
maximum=1,
|
| 73 |
step=0.05,
|
|
@@ -76,7 +76,7 @@ additional_inputs=[
|
|
| 76 |
),
|
| 77 |
gr.Slider(
|
| 78 |
label="Repetition penalty",
|
| 79 |
-
value=1
|
| 80 |
minimum=1.0,
|
| 81 |
maximum=2.0,
|
| 82 |
step=0.05,
|
|
@@ -85,19 +85,15 @@ additional_inputs=[
|
|
| 85 |
)
|
| 86 |
]
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
-
fn=generate,
|
| 98 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
| 99 |
-
additional_inputs=additional_inputs,
|
| 100 |
-
title="Mixtral 46.7B",
|
| 101 |
-
examples=examples,
|
| 102 |
-
concurrency_limit=20,
|
| 103 |
-
).launch(show_api=False)
|
|
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 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, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
|
|
|
| 19 |
temperature = float(temperature)
|
| 20 |
if temperature < 1e-2:
|
| 21 |
temperature = 1e-2
|
|
|
|
| 30 |
seed=42,
|
| 31 |
)
|
| 32 |
|
| 33 |
+
formatted_prompt = format_prompt(prompt, history)
|
| 34 |
+
|
| 35 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 36 |
output = ""
|
| 37 |
|
|
|
|
| 49 |
),
|
| 50 |
gr.Slider(
|
| 51 |
label="Temperature",
|
| 52 |
+
value=0.2,
|
| 53 |
minimum=0.0,
|
| 54 |
maximum=1.0,
|
| 55 |
step=0.05,
|
|
|
|
| 58 |
),
|
| 59 |
gr.Slider(
|
| 60 |
label="Max new tokens",
|
| 61 |
+
value=512,
|
| 62 |
minimum=0,
|
| 63 |
maximum=1048,
|
| 64 |
step=64,
|
|
|
|
| 67 |
),
|
| 68 |
gr.Slider(
|
| 69 |
label="Top-p (nucleus sampling)",
|
| 70 |
+
value=0.95,
|
| 71 |
minimum=0.0,
|
| 72 |
maximum=1,
|
| 73 |
step=0.05,
|
|
|
|
| 76 |
),
|
| 77 |
gr.Slider(
|
| 78 |
label="Repetition penalty",
|
| 79 |
+
value=1,
|
| 80 |
minimum=1.0,
|
| 81 |
maximum=2.0,
|
| 82 |
step=0.05,
|
|
|
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|