Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,7 @@ def generate_response(prompt, chat_history, max_new_tokens, temperature):
|
|
59 |
response = ""
|
60 |
for token_id in generated_ids.sequences[0][len(model_inputs.input_ids[0]):]:
|
61 |
response += tokenizer.decode([token_id], skip_special_tokens=True)
|
62 |
-
yield response
|
63 |
|
64 |
# Clear Chat History
|
65 |
# ==================
|
@@ -67,7 +67,7 @@ def clear_chat():
|
|
67 |
"""
|
68 |
Clear the chat history.
|
69 |
"""
|
70 |
-
return []
|
71 |
|
72 |
# Gradio Interface
|
73 |
# =================
|
@@ -93,12 +93,14 @@ def gradio_interface():
|
|
93 |
chat_history.append({"role": "user", "content": message})
|
94 |
response = ""
|
95 |
for chunk in generate_response(message, chat_history, max_new_tokens, temperature):
|
96 |
-
response = chunk
|
97 |
-
yield chat_history
|
98 |
chat_history.append({"role": "assistant", "content": response})
|
|
|
99 |
|
100 |
-
submit.click(respond, [msg, chatbot, max_new_tokens, temperature], [chatbot])
|
101 |
-
|
|
|
102 |
|
103 |
demo.launch()
|
104 |
|
|
|
59 |
response = ""
|
60 |
for token_id in generated_ids.sequences[0][len(model_inputs.input_ids[0]):]:
|
61 |
response += tokenizer.decode([token_id], skip_special_tokens=True)
|
62 |
+
yield chat_history + [{"role": "assistant", "content": response}]
|
63 |
|
64 |
# Clear Chat History
|
65 |
# ==================
|
|
|
67 |
"""
|
68 |
Clear the chat history.
|
69 |
"""
|
70 |
+
return [], ""
|
71 |
|
72 |
# Gradio Interface
|
73 |
# =================
|
|
|
93 |
chat_history.append({"role": "user", "content": message})
|
94 |
response = ""
|
95 |
for chunk in generate_response(message, chat_history, max_new_tokens, temperature):
|
96 |
+
response = chunk[-1]["content"]
|
97 |
+
yield chat_history, ""
|
98 |
chat_history.append({"role": "assistant", "content": response})
|
99 |
+
yield chat_history, ""
|
100 |
|
101 |
+
submit.click(respond, [msg, chatbot, max_new_tokens, temperature], [chatbot, msg])
|
102 |
+
msg.submit(respond, [msg, chatbot, max_new_tokens, temperature], [chatbot, msg])
|
103 |
+
clear.click(clear_chat, None, [chatbot, msg])
|
104 |
|
105 |
demo.launch()
|
106 |
|