Spaces:
Runtime error
Runtime error
Add functionality to be able to submit with "return" key on keyboard
Browse files
app.py
CHANGED
|
@@ -55,14 +55,32 @@ with gr.Blocks() as demo:
|
|
| 55 |
user_chat_input = gr.Textbox(label="User input", scale=9)
|
| 56 |
user_chat_submit = gr.Button("Ask/answer model", scale=1)
|
| 57 |
|
| 58 |
-
# First add user's message to the conversation history
|
| 59 |
# Then get reply from the tutor and add that to the conversation history
|
| 60 |
-
|
| 61 |
-
fn = add_user_message,
|
|
|
|
|
|
|
|
|
|
| 62 |
).then(
|
| 63 |
-
fn = get_tutor_reply,
|
|
|
|
|
|
|
|
|
|
| 64 |
)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# Testing the chat history storage, can be deleted at deployment
|
| 67 |
with gr.Blocks():
|
| 68 |
test_btn = gr.Button("View your chat history")
|
|
|
|
| 55 |
user_chat_input = gr.Textbox(label="User input", scale=9)
|
| 56 |
user_chat_submit = gr.Button("Ask/answer model", scale=1)
|
| 57 |
|
| 58 |
+
# First add user's message to the conversation history when user presses "enter" or hits the submit button
|
| 59 |
# Then get reply from the tutor and add that to the conversation history
|
| 60 |
+
user_chat_input.submit(
|
| 61 |
+
fn = add_user_message,
|
| 62 |
+
inputs = [user_chat_input, study_tutor],
|
| 63 |
+
outputs = [user_chat_input, chatbot, study_tutor],
|
| 64 |
+
queue=False
|
| 65 |
).then(
|
| 66 |
+
fn = get_tutor_reply,
|
| 67 |
+
inputs = [study_tutor],
|
| 68 |
+
outputs = [user_chat_input, chatbot, study_tutor],
|
| 69 |
+
queue=True
|
| 70 |
)
|
| 71 |
|
| 72 |
+
user_chat_submit.click(
|
| 73 |
+
fn = add_user_message,
|
| 74 |
+
inputs = [user_chat_input, study_tutor],
|
| 75 |
+
outputs = [user_chat_input, chatbot, study_tutor],
|
| 76 |
+
queue=False
|
| 77 |
+
).then(
|
| 78 |
+
fn = get_tutor_reply,
|
| 79 |
+
inputs = [study_tutor],
|
| 80 |
+
outputs = [user_chat_input, chatbot, study_tutor],
|
| 81 |
+
queue=True
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
# Testing the chat history storage, can be deleted at deployment
|
| 85 |
with gr.Blocks():
|
| 86 |
test_btn = gr.Button("View your chat history")
|