Spaces:
Build error
Build error
dtompson commited on
Commit ·
6ee949a
1
Parent(s): 8d35c15
Switched to Mistral 7B with text_generation
Browse files
app.py
CHANGED
|
@@ -1,58 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
""
|
| 5 |
-
Multisolve Chatbots
|
| 6 |
-
Real model version using HuggingFace Zephyr-7b-beta.
|
| 7 |
-
"""
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def respond(
|
| 13 |
-
message,
|
| 14 |
-
history: list[tuple[str, str]],
|
| 15 |
-
system_message,
|
| 16 |
-
max_tokens,
|
| 17 |
-
temperature,
|
| 18 |
-
top_p,
|
| 19 |
-
):
|
| 20 |
-
# Build the conversation
|
| 21 |
-
messages = [{"role": "system", "content": system_message}]
|
| 22 |
for user, bot in history:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
temperature=temperature,
|
| 30 |
top_p=top_p,
|
| 31 |
-
|
|
|
|
| 32 |
)
|
| 33 |
-
|
|
|
|
| 34 |
return history, history
|
| 35 |
|
| 36 |
-
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
-
gr.Markdown("# 🤖 Multisolve
|
| 39 |
-
system_message = gr.Textbox(value="You are a helpful assistant.", label="System Prompt")
|
| 40 |
chatbot = gr.Chatbot()
|
| 41 |
message = gr.Textbox(placeholder="Type your message here...")
|
| 42 |
state = gr.State([])
|
| 43 |
|
| 44 |
with gr.Row():
|
| 45 |
-
max_tokens = gr.Slider(
|
| 46 |
-
temperature = gr.Slider(0, 1, value=0.7, step=0.
|
| 47 |
-
top_p = gr.Slider(0
|
| 48 |
-
|
| 49 |
-
def user_message(user_message, history, system_message, max_tokens, temperature, top_p):
|
| 50 |
-
return respond(user_message, history, system_message, max_tokens, temperature, top_p)
|
| 51 |
-
|
| 52 |
-
message.submit(
|
| 53 |
-
user_message,
|
| 54 |
-
[message, state, system_message, max_tokens, temperature, top_p],
|
| 55 |
-
[chatbot, state],
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def format_prompt(history, user_input):
|
| 7 |
+
prompt = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
for user, bot in history:
|
| 9 |
+
prompt += f"User: {user}\nAssistant: {bot}\n"
|
| 10 |
+
prompt += f"User: {user_input}\nAssistant:"
|
| 11 |
+
return prompt
|
| 12 |
+
|
| 13 |
+
def respond(message, history, max_tokens, temperature, top_p):
|
| 14 |
+
prompt = format_prompt(history, message)
|
| 15 |
+
response = client.text_generation(
|
| 16 |
+
prompt,
|
| 17 |
+
max_new_tokens=max_tokens,
|
| 18 |
temperature=temperature,
|
| 19 |
top_p=top_p,
|
| 20 |
+
do_sample=True,
|
| 21 |
+
stop_sequences=["User:"]
|
| 22 |
)
|
| 23 |
+
reply = response.strip()
|
| 24 |
+
history.append((message, reply))
|
| 25 |
return history, history
|
| 26 |
|
|
|
|
| 27 |
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("# 🤖 Multisolve Chatbot (Mistral 7B)")
|
|
|
|
| 29 |
chatbot = gr.Chatbot()
|
| 30 |
message = gr.Textbox(placeholder="Type your message here...")
|
| 31 |
state = gr.State([])
|
| 32 |
|
| 33 |
with gr.Row():
|
| 34 |
+
max_tokens = gr.Slider(64, 1024, value=256, step=64, label="Max Tokens")
|
| 35 |
+
temperature = gr.Slider(0.1, 1.0, value=0.7, step=0.1, label="Temperature")
|
| 36 |
+
top_p = gr.Slider(0.1, 1.0_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|