Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,23 @@
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 5 |
|
| 6 |
-
def format_prompt(message, history,
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
def generate(
|
| 16 |
-
prompt, history,
|
| 17 |
):
|
| 18 |
temperature = float(temperature)
|
| 19 |
if temperature < 1e-2:
|
| 20 |
temperature = 1e-2
|
| 21 |
top_p = float(top_p)
|
| 22 |
-
|
| 23 |
generate_kwargs = dict(
|
| 24 |
temperature=temperature,
|
| 25 |
max_new_tokens=max_new_tokens,
|
|
@@ -28,18 +26,14 @@ def generate(
|
|
| 28 |
do_sample=True,
|
| 29 |
seed=42,
|
| 30 |
)
|
| 31 |
-
|
| 32 |
-
formatted_prompt = format_prompt(prompt, history, first_user_message, system_prompt)
|
| 33 |
-
|
| 34 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 35 |
output = ""
|
| 36 |
-
|
| 37 |
for response in stream:
|
| 38 |
-
output += response
|
| 39 |
yield output
|
| 40 |
return output
|
| 41 |
|
| 42 |
-
|
| 43 |
mychatbot = gr.Chatbot(
|
| 44 |
avatar_images=["./user.png", "./botm.png"],
|
| 45 |
bubble_full_width=False,
|
|
@@ -48,13 +42,10 @@ mychatbot = gr.Chatbot(
|
|
| 48 |
likeable=True,
|
| 49 |
)
|
| 50 |
|
| 51 |
-
demo = gr.
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
)
|
| 59 |
-
|
| 60 |
-
demo.queue().launch(show_api=False)
|
|
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 4 |
|
| 5 |
+
def format_prompt(message, history, system_prompt):
|
| 6 |
+
prompt = "<s>"
|
| 7 |
+
for user_prompt, bot_response in history:
|
| 8 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
| 9 |
+
prompt += f" {bot_response}</s> "
|
| 10 |
+
prompt += f"[INST] {message} [/INST]"
|
| 11 |
+
prompt += f" [SYSTEM] {system_prompt} [/SYSTEM]"
|
| 12 |
+
return prompt
|
| 13 |
|
| 14 |
def generate(
|
| 15 |
+
prompt, history, system_prompt, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
| 16 |
):
|
| 17 |
temperature = float(temperature)
|
| 18 |
if temperature < 1e-2:
|
| 19 |
temperature = 1e-2
|
| 20 |
top_p = float(top_p)
|
|
|
|
| 21 |
generate_kwargs = dict(
|
| 22 |
temperature=temperature,
|
| 23 |
max_new_tokens=max_new_tokens,
|
|
|
|
| 26 |
do_sample=True,
|
| 27 |
seed=42,
|
| 28 |
)
|
| 29 |
+
formatted_prompt = format_prompt(prompt, history, system_prompt)
|
|
|
|
|
|
|
| 30 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 31 |
output = ""
|
|
|
|
| 32 |
for response in stream:
|
| 33 |
+
output += response['text']
|
| 34 |
yield output
|
| 35 |
return output
|
| 36 |
|
|
|
|
| 37 |
mychatbot = gr.Chatbot(
|
| 38 |
avatar_images=["./user.png", "./botm.png"],
|
| 39 |
bubble_full_width=False,
|
|
|
|
| 42 |
likeable=True,
|
| 43 |
)
|
| 44 |
|
| 45 |
+
demo = gr.Interface(fn=generate,
|
| 46 |
+
inputs=[gr.inputs.Textbox(lines=2, label="Your Message"), "state", "state"],
|
| 47 |
+
outputs=[gr.outputs.Textbox(label="ChatGPT's Response"), "state", "state"],
|
| 48 |
+
title="Tomoniai's Mixtral 8x7b Chat",
|
| 49 |
+
allow_flagging="never"
|
| 50 |
+
)
|
| 51 |
+
demo.launch(show_api=False)
|
|
|
|
|
|
|
|
|