Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,29 +42,13 @@ with gr.Blocks(css=".gradio-container {max-width: 900px; margin: auto;}") as dem
|
|
| 42 |
msg = gr.Textbox(
|
| 43 |
show_label=False,
|
| 44 |
placeholder="Type your message here...",
|
| 45 |
-
|
| 46 |
-
).style(container=False)
|
| 47 |
with gr.Column(scale=1, min_width=100):
|
| 48 |
-
send_btn = gr.Button("Send")
|
| 49 |
-
|
| 50 |
with gr.Accordion("Settings", open=False):
|
| 51 |
system_message = gr.Textbox(value="You are a friendly Chatbot.", label="System message")
|
| 52 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
| 53 |
temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
| 54 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
| 55 |
|
| 56 |
-
def user_interaction(user_message, history, system_message, max_tokens, temperature, top_p):
|
| 57 |
-
history = history or []
|
| 58 |
-
history.append((user_message, None))
|
| 59 |
-
bot_response = respond(user_message, history, system_message, max_tokens, temperature, top_p)
|
| 60 |
-
history[-1] = (user_message, next(bot_response))
|
| 61 |
-
for token in bot_response:
|
| 62 |
-
history[-1] = (user_message, token)
|
| 63 |
-
yield history
|
| 64 |
-
|
| 65 |
-
msg.submit(user_interaction, [msg, chatbot, system_message, max_tokens, temperature, top_p], chatbot)
|
| 66 |
-
send_btn.click(user_interaction, [msg, chatbot, system_message, max_tokens, temperature, top_p], chatbot)
|
| 67 |
-
send_btn.click(lambda: "", None, msg) # Clear the input box after sending
|
| 68 |
-
|
| 69 |
-
if __name__ == "__main__":
|
| 70 |
-
demo.launch()
|
|
|
|
| 42 |
msg = gr.Textbox(
|
| 43 |
show_label=False,
|
| 44 |
placeholder="Type your message here...",
|
| 45 |
+
)
|
|
|
|
| 46 |
with gr.Column(scale=1, min_width=100):
|
| 47 |
+
send_btn = gr.Button("Send")
|
| 48 |
+
|
| 49 |
with gr.Accordion("Settings", open=False):
|
| 50 |
system_message = gr.Textbox(value="You are a friendly Chatbot.", label="System message")
|
| 51 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
| 52 |
temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
| 53 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|