Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,10 +104,11 @@ def stream_chat(
|
|
| 104 |
eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
| 105 |
|
| 106 |
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
| 107 |
-
|
| 108 |
for i in range(len(result)):
|
| 109 |
time.sleep(0.05)
|
| 110 |
yield result[: i + 1]
|
|
|
|
| 111 |
|
| 112 |
|
| 113 |
tools_schema = """function_params = {
|
|
@@ -130,51 +131,47 @@ tools_schema = """function_params = {
|
|
| 130 |
},
|
| 131 |
}"""
|
| 132 |
|
|
|
|
| 133 |
with gr.Blocks(theme="citrus", css=CSS) as demo:
|
| 134 |
gr.DuplicateButton(value="Duplicate Space for private use", elem_classes="duplicate-button")
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
| 138 |
examples=[
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
]
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
)
|
| 149 |
-
|
| 150 |
-
send = gr.Button(
|
| 151 |
-
value = "Send",
|
| 152 |
-
size="lg",
|
| 153 |
-
variant = "primary",
|
| 154 |
-
)
|
| 155 |
-
clear = gr.ClearButton([msg, chatbot])
|
| 156 |
-
|
| 157 |
-
with gr.Accordion(label="⚙️ Parameters", open=True,):
|
| 158 |
-
tools = gr.Textbox(
|
| 159 |
-
value = tools_schema,
|
| 160 |
-
label = "Tools schema",
|
| 161 |
-
)
|
| 162 |
-
temperature = gr.Slider(
|
| 163 |
-
minimum=0,
|
| 164 |
-
maximum=1,
|
| 165 |
-
step=0.1,
|
| 166 |
-
value=0.3,
|
| 167 |
-
label="Temperature",
|
| 168 |
-
),
|
| 169 |
-
max_tokens = gr.Slider(
|
| 170 |
-
minimum=128,
|
| 171 |
-
maximum=8192,
|
| 172 |
-
step=1,
|
| 173 |
-
value=1024,
|
| 174 |
-
label="Max new tokens",
|
| 175 |
-
)
|
| 176 |
-
msg.submit(fn = stream_chat, inputs = [msg, chatbot, tools, temperature, max_tokens], outputs = [chatbot])
|
| 177 |
-
send.click(fn = stream_chat, inputs = [msg, chatbot, tools, temperature, max_tokens], outputs = [chatbot])
|
| 178 |
|
| 179 |
if __name__ == "__main__":
|
| 180 |
demo.launch()
|
|
|
|
| 104 |
eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
| 105 |
|
| 106 |
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
| 107 |
+
|
| 108 |
for i in range(len(result)):
|
| 109 |
time.sleep(0.05)
|
| 110 |
yield result[: i + 1]
|
| 111 |
+
|
| 112 |
|
| 113 |
|
| 114 |
tools_schema = """function_params = {
|
|
|
|
| 131 |
},
|
| 132 |
}"""
|
| 133 |
|
| 134 |
+
chatbot = gr.Chatbot(height=600, placeholder=PLACEHOLDER)
|
| 135 |
with gr.Blocks(theme="citrus", css=CSS) as demo:
|
| 136 |
gr.DuplicateButton(value="Duplicate Space for private use", elem_classes="duplicate-button")
|
| 137 |
+
gr.ChatInterface(
|
| 138 |
+
fn=stream_chat,
|
| 139 |
+
title="Mistral-lab",
|
| 140 |
+
chatbot=chatbot,
|
| 141 |
+
# type="messages",
|
| 142 |
+
fill_height=True,
|
| 143 |
examples=[
|
| 144 |
+
["Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option."],
|
| 145 |
+
["What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter."],
|
| 146 |
+
["Tell me a random fun fact about the Roman Empire."],
|
| 147 |
+
["Show me a code snippet of a website's sticky header in CSS and JavaScript."],
|
| 148 |
+
],
|
| 149 |
+
cache_examples = False,
|
| 150 |
+
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
| 151 |
+
additional_inputs=[
|
| 152 |
+
gr.Textbox(
|
| 153 |
+
value = tools_schema,
|
| 154 |
+
label = "Tools schema",
|
| 155 |
+
)
|
| 156 |
+
gr.Slider(
|
| 157 |
+
minimum=0,
|
| 158 |
+
maximum=1,
|
| 159 |
+
step=0.1,
|
| 160 |
+
value=0.3,
|
| 161 |
+
label="Temperature",
|
| 162 |
+
render=False,
|
| 163 |
+
),
|
| 164 |
+
gr.Slider(
|
| 165 |
+
minimum=128,
|
| 166 |
+
maximum=8192,
|
| 167 |
+
step=1,
|
| 168 |
+
value=1024,
|
| 169 |
+
label="Max new tokens",
|
| 170 |
+
render=False,
|
| 171 |
+
),
|
| 172 |
+
],
|
| 173 |
)
|
| 174 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|
| 177 |
demo.launch()
|