Commit
·
b33ea97
1
Parent(s):
389cd6c
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,16 +3,18 @@ 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 |
def generate(
|
| 15 |
-
prompt, history, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0,
|
| 16 |
):
|
| 17 |
temperature = float(temperature)
|
| 18 |
if temperature < 1e-2:
|
|
@@ -28,7 +30,7 @@ def generate(
|
|
| 28 |
seed=42,
|
| 29 |
)
|
| 30 |
|
| 31 |
-
formatted_prompt = format_prompt(prompt, history)
|
| 32 |
|
| 33 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 34 |
output = ""
|
|
@@ -41,12 +43,17 @@ def generate(
|
|
| 41 |
mychatbot = gr.Chatbot(
|
| 42 |
avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
|
| 43 |
|
| 44 |
-
demo = gr.ChatInterface(
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
":root {--color-accent: transparent !important; --color-accent-soft:transparent !important; --code-background-fill:black !important;}"
|
| 51 |
"#component-2 {background:#ffffff1a; display:contents;}"
|
| 52 |
"div#component-0 { height: auto !important;}"
|
|
@@ -68,6 +75,6 @@ demo = gr.ChatInterface(fn=generate,
|
|
| 68 |
".bubble-wrap.svelte-12dsd9j.svelte-12dsd9j.svelte-12dsd9j {padding: 0;}"
|
| 69 |
".prose h1 { color: white !important; font-size: 16px !important; font-weight: normal !important; background: #ffffff1a; padding: 20px; border-radius: 20px; width: fit-content; margin-left: auto !important; margin-right: auto !important;}"
|
| 70 |
|
| 71 |
-
|
| 72 |
|
| 73 |
-
demo.queue().launch(show_api=False)
|
|
|
|
| 3 |
|
| 4 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 5 |
|
| 6 |
+
def format_prompt(message, history, system_prompt=None):
|
| 7 |
+
prompt = "<s>"
|
| 8 |
+
for user_prompt, bot_response in history:
|
| 9 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
| 10 |
+
prompt += f" {bot_response}</s> "
|
| 11 |
+
if system_prompt:
|
| 12 |
+
prompt += f"[SYS] {system_prompt} [/SYS]"
|
| 13 |
+
prompt += f"[INST] {message} [/INST]"
|
| 14 |
+
return prompt
|
| 15 |
|
| 16 |
def generate(
|
| 17 |
+
prompt, history, system_prompt=None, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0,
|
| 18 |
):
|
| 19 |
temperature = float(temperature)
|
| 20 |
if temperature < 1e-2:
|
|
|
|
| 30 |
seed=42,
|
| 31 |
)
|
| 32 |
|
| 33 |
+
formatted_prompt = format_prompt(prompt, history, system_prompt)
|
| 34 |
|
| 35 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 36 |
output = ""
|
|
|
|
| 43 |
mychatbot = gr.Chatbot(
|
| 44 |
avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
|
| 45 |
|
| 46 |
+
demo = gr.ChatInterface(
|
| 47 |
+
fn=generate,
|
| 48 |
+
chatbot=mychatbot,
|
| 49 |
+
title="Hello! I'm Elisa by SpriFi.👋 How can I help you today?",
|
| 50 |
+
retry_btn=None,
|
| 51 |
+
undo_btn=None,
|
| 52 |
+
examples=[
|
| 53 |
+
["Hello", [], "Your name is Elisa, an AI created by SpriFi Inc. on February 14 2023.", 0.2, 512, 0.95, 1.0],
|
| 54 |
+
# Add more examples as needed
|
| 55 |
+
],
|
| 56 |
+
css="body { background-color: inherit; overflow-x:hidden;}"
|
| 57 |
":root {--color-accent: transparent !important; --color-accent-soft:transparent !important; --code-background-fill:black !important;}"
|
| 58 |
"#component-2 {background:#ffffff1a; display:contents;}"
|
| 59 |
"div#component-0 { height: auto !important;}"
|
|
|
|
| 75 |
".bubble-wrap.svelte-12dsd9j.svelte-12dsd9j.svelte-12dsd9j {padding: 0;}"
|
| 76 |
".prose h1 { color: white !important; font-size: 16px !important; font-weight: normal !important; background: #ffffff1a; padding: 20px; border-radius: 20px; width: fit-content; margin-left: auto !important; margin-right: auto !important;}"
|
| 77 |
|
| 78 |
+
)
|
| 79 |
|
| 80 |
+
demo.queue().launch(show_api=False)
|