Spaces:
Runtime error
Runtime error
modify interface
Browse files
app.py
CHANGED
|
@@ -31,8 +31,9 @@ def create_prompt(system_message, user_message, tool_definition="", context=""):
|
|
| 31 |
else:
|
| 32 |
return f"<extra_id_0>System\n{system_message}\n\n<extra_id_1>User\n{user_message}\n<extra_id_1>Assistant\n"
|
| 33 |
|
|
|
|
| 34 |
@spaces.GPU(duration=94)
|
| 35 |
-
def generate_response(message, history, system_message, max_tokens, temperature, top_p, use_pipeline=False, tool_definition="", context=""):
|
| 36 |
full_prompt = create_prompt(system_message, message, tool_definition, context)
|
| 37 |
|
| 38 |
if use_pipeline:
|
|
@@ -52,7 +53,7 @@ def generate_response(message, history, system_message, max_tokens, temperature,
|
|
| 52 |
max_new_tokens=max_tokens,
|
| 53 |
temperature=temperature,
|
| 54 |
top_p=top_p,
|
| 55 |
-
do_sample=
|
| 56 |
attention_mask=attention_mask
|
| 57 |
)
|
| 58 |
|
|
@@ -66,6 +67,9 @@ def generate_response(message, history, system_message, max_tokens, temperature,
|
|
| 66 |
|
| 67 |
return assistant_response
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
with gr.Blocks() as demo:
|
| 70 |
with gr.Row():
|
| 71 |
gr.Markdown(title)
|
|
@@ -79,23 +83,15 @@ with gr.Blocks() as demo:
|
|
| 79 |
with gr.Group():
|
| 80 |
gr.Markdown(joinus)
|
| 81 |
with gr.Row():
|
| 82 |
-
with gr.Column(scale=
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
)
|
| 91 |
-
context = gr.Textbox(
|
| 92 |
-
label="Context",
|
| 93 |
-
lines=2,
|
| 94 |
-
placeholder="Enter additional context information..."
|
| 95 |
-
)
|
| 96 |
-
max_tokens = gr.Slider(minimum=1, maximum=1024, value=256, step=1, label="Max Tokens")
|
| 97 |
-
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
| 98 |
-
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
|
| 99 |
use_pipeline = gr.Checkbox(label="Use Pipeline", value=False)
|
| 100 |
use_tool = gr.Checkbox(label="Use Function Calling", value=False)
|
| 101 |
with gr.Column(visible=False) as tool_options:
|
|
@@ -105,29 +101,37 @@ with gr.Blocks() as demo:
|
|
| 105 |
lines=15,
|
| 106 |
language="json"
|
| 107 |
)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
send = gr.Button("Send")
|
| 111 |
-
with gr.Column(scale=1):
|
| 112 |
-
chatbot = gr.Chatbot(label="π€ Mistral-NeMo", height=400)
|
| 113 |
-
|
| 114 |
|
|
|
|
|
|
|
|
|
|
| 115 |
def user(user_message, history):
|
| 116 |
return "", history + [[user_message, None]]
|
| 117 |
|
| 118 |
-
def bot(history,
|
| 119 |
user_message = history[-1][0]
|
| 120 |
-
bot_message = generate_response(user_message, history,
|
| 121 |
history[-1][1] = bot_message
|
| 122 |
return history
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
)
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
| 129 |
)
|
| 130 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
| 131 |
|
| 132 |
use_tool.change(
|
| 133 |
fn=lambda x: gr.update(visible=x),
|
|
|
|
| 31 |
else:
|
| 32 |
return f"<extra_id_0>System\n{system_message}\n\n<extra_id_1>User\n{user_message}\n<extra_id_1>Assistant\n"
|
| 33 |
|
| 34 |
+
|
| 35 |
@spaces.GPU(duration=94)
|
| 36 |
+
def generate_response(message, history, system_message, max_tokens, temperature, top_p, do_sample, use_pipeline=False, tool_definition="", context=""):
|
| 37 |
full_prompt = create_prompt(system_message, message, tool_definition, context)
|
| 38 |
|
| 39 |
if use_pipeline:
|
|
|
|
| 53 |
max_new_tokens=max_tokens,
|
| 54 |
temperature=temperature,
|
| 55 |
top_p=top_p,
|
| 56 |
+
do_sample=do_sample,
|
| 57 |
attention_mask=attention_mask
|
| 58 |
)
|
| 59 |
|
|
|
|
| 67 |
|
| 68 |
return assistant_response
|
| 69 |
|
| 70 |
+
def update_advanced_settings(show_advanced):
|
| 71 |
+
return {"visible": show_advanced}
|
| 72 |
+
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
with gr.Row():
|
| 75 |
gr.Markdown(title)
|
|
|
|
| 83 |
with gr.Group():
|
| 84 |
gr.Markdown(joinus)
|
| 85 |
with gr.Row():
|
| 86 |
+
with gr.Column(scale=2):
|
| 87 |
+
system_prompt = gr.TextArea(label="πContext", placeholder="add context here...", lines=5)
|
| 88 |
+
user_input = gr.TextArea(label="π€·π»ββοΈUser Input", placeholder="Hi there my name is Tonic!", lines=2)
|
| 89 |
+
advanced_checkbox = gr.Checkbox(label="π§ͺ Advanced Settings", value=False)
|
| 90 |
+
with gr.Column(visible=False) as advanced_settings:
|
| 91 |
+
max_length = gr.Slider(label="πMax Length", minimum=12, maximum=1700, value=650, step=1)
|
| 92 |
+
temperature = gr.Slider(label="π‘οΈTemperature", minimum=0.01, maximum=1.0, value=0.7, step=0.01)
|
| 93 |
+
top_p = gr.Slider(label="βοΈTop-p (Nucleus Sampling)", minimum=0.1, maximum=1.0, value=0.9, step=0.01)
|
| 94 |
+
# do_sample = gr.Checkbox(label="Do Sample", value=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
use_pipeline = gr.Checkbox(label="Use Pipeline", value=False)
|
| 96 |
use_tool = gr.Checkbox(label="Use Function Calling", value=False)
|
| 97 |
with gr.Column(visible=False) as tool_options:
|
|
|
|
| 101 |
lines=15,
|
| 102 |
language="json"
|
| 103 |
)
|
| 104 |
+
|
| 105 |
+
generate_button = gr.Button(value="π€Mistral-NeMo-Minitron")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
with gr.Column(scale=2):
|
| 108 |
+
chatbot = gr.Chatbot(label="π€Mistral-NeMo-Minitron")
|
| 109 |
+
|
| 110 |
def user(user_message, history):
|
| 111 |
return "", history + [[user_message, None]]
|
| 112 |
|
| 113 |
+
def bot(history, system_prompt, max_length, temperature, top_p, advanced_settings, use_pipeline, tool_definition):
|
| 114 |
user_message = history[-1][0]
|
| 115 |
+
bot_message = generate_response(user_message, history, system_prompt, max_length, temperature, top_p, advanced_checkbox, use_pipeline, tool_definition)
|
| 116 |
history[-1][1] = bot_message
|
| 117 |
return history
|
| 118 |
|
| 119 |
+
generate_button.click(
|
| 120 |
+
user,
|
| 121 |
+
[user_input, chatbot],
|
| 122 |
+
[user_input, chatbot],
|
| 123 |
+
queue=False
|
| 124 |
+
).then(
|
| 125 |
+
bot,
|
| 126 |
+
[chatbot, system_prompt, max_length, temperature, top_p, advanced_checkbox, use_pipeline, tool_definition],
|
| 127 |
+
chatbot
|
| 128 |
)
|
| 129 |
+
|
| 130 |
+
advanced_checkbox.change(
|
| 131 |
+
fn=update_advanced_settings,
|
| 132 |
+
inputs=[advanced_checkbox],
|
| 133 |
+
outputs=advanced_settings
|
| 134 |
)
|
|
|
|
| 135 |
|
| 136 |
use_tool.change(
|
| 137 |
fn=lambda x: gr.update(visible=x),
|