Spaces:
Running
Running
restore keyboard shortcuts with enter key for sending messages
Browse files
app.py
CHANGED
|
@@ -586,23 +586,21 @@ def create_interface():
|
|
| 586 |
chatbot = gr.Chatbot(type="messages", height=400)
|
| 587 |
msg = gr.Textbox(
|
| 588 |
label="Message",
|
| 589 |
-
placeholder="Type your message here...
|
| 590 |
-
lines=2
|
| 591 |
-
elem_id="msg-textbox"
|
| 592 |
)
|
| 593 |
|
| 594 |
with gr.Row():
|
| 595 |
-
submit_btn = gr.Button("Send", variant="primary"
|
| 596 |
-
clear_btn = gr.Button("Clear"
|
| 597 |
|
| 598 |
# Export functionality
|
| 599 |
with gr.Row():
|
| 600 |
# Use a regular Button for triggering export
|
| 601 |
export_trigger_btn = gr.Button(
|
| 602 |
-
"📥 Export Conversation
|
| 603 |
variant="secondary",
|
| 604 |
-
size="sm"
|
| 605 |
-
elem_id="export-btn"
|
| 606 |
)
|
| 607 |
# Hidden file component for actual download
|
| 608 |
export_file = gr.File(
|
|
@@ -1053,6 +1051,7 @@ def create_interface():
|
|
| 1053 |
outputs=[access_panel, main_panel, access_status, access_granted]
|
| 1054 |
)
|
| 1055 |
|
|
|
|
| 1056 |
# Add keyboard shortcuts
|
| 1057 |
demo.load(
|
| 1058 |
None,
|
|
@@ -1060,31 +1059,29 @@ def create_interface():
|
|
| 1060 |
None,
|
| 1061 |
js="""
|
| 1062 |
() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1063 |
// Keyboard shortcuts
|
| 1064 |
document.addEventListener('keydown', function(e) {
|
| 1065 |
-
// Ctrl+Enter to send message
|
| 1066 |
-
if (e.ctrlKey && e.key === 'Enter') {
|
| 1067 |
-
e.preventDefault();
|
| 1068 |
-
const sendBtn = document.querySelector('#send-btn button');
|
| 1069 |
-
if (sendBtn) sendBtn.click();
|
| 1070 |
-
}
|
| 1071 |
// Ctrl+L to clear chat
|
| 1072 |
-
|
| 1073 |
e.preventDefault();
|
| 1074 |
-
const
|
|
|
|
| 1075 |
if (clearBtn) clearBtn.click();
|
| 1076 |
}
|
| 1077 |
// Ctrl+E to export
|
| 1078 |
else if (e.ctrlKey && e.key === 'e') {
|
| 1079 |
e.preventDefault();
|
| 1080 |
-
const
|
|
|
|
| 1081 |
if (exportBtn) exportBtn.click();
|
| 1082 |
}
|
| 1083 |
});
|
| 1084 |
-
|
| 1085 |
-
// Focus on message input when page loads
|
| 1086 |
-
const msgInput = document.querySelector('#msg-textbox textarea');
|
| 1087 |
-
if (msgInput) msgInput.focus();
|
| 1088 |
}
|
| 1089 |
"""
|
| 1090 |
)
|
|
|
|
| 586 |
chatbot = gr.Chatbot(type="messages", height=400)
|
| 587 |
msg = gr.Textbox(
|
| 588 |
label="Message",
|
| 589 |
+
placeholder="Type your message here...",
|
| 590 |
+
lines=2
|
|
|
|
| 591 |
)
|
| 592 |
|
| 593 |
with gr.Row():
|
| 594 |
+
submit_btn = gr.Button("Send", variant="primary")
|
| 595 |
+
clear_btn = gr.Button("Clear")
|
| 596 |
|
| 597 |
# Export functionality
|
| 598 |
with gr.Row():
|
| 599 |
# Use a regular Button for triggering export
|
| 600 |
export_trigger_btn = gr.Button(
|
| 601 |
+
"📥 Export Conversation",
|
| 602 |
variant="secondary",
|
| 603 |
+
size="sm"
|
|
|
|
| 604 |
)
|
| 605 |
# Hidden file component for actual download
|
| 606 |
export_file = gr.File(
|
|
|
|
| 1051 |
outputs=[access_panel, main_panel, access_status, access_granted]
|
| 1052 |
)
|
| 1053 |
|
| 1054 |
+
|
| 1055 |
# Add keyboard shortcuts
|
| 1056 |
demo.load(
|
| 1057 |
None,
|
|
|
|
| 1059 |
None,
|
| 1060 |
js="""
|
| 1061 |
() => {
|
| 1062 |
+
// Focus on message input when page loads
|
| 1063 |
+
setTimeout(() => {
|
| 1064 |
+
const msgInput = document.querySelector('textarea');
|
| 1065 |
+
if (msgInput) msgInput.focus();
|
| 1066 |
+
}, 100);
|
| 1067 |
+
|
| 1068 |
// Keyboard shortcuts
|
| 1069 |
document.addEventListener('keydown', function(e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1070 |
// Ctrl+L to clear chat
|
| 1071 |
+
if (e.ctrlKey && e.key === 'l') {
|
| 1072 |
e.preventDefault();
|
| 1073 |
+
const buttons = Array.from(document.querySelectorAll('button'));
|
| 1074 |
+
const clearBtn = buttons.find(btn => btn.textContent.includes('Clear'));
|
| 1075 |
if (clearBtn) clearBtn.click();
|
| 1076 |
}
|
| 1077 |
// Ctrl+E to export
|
| 1078 |
else if (e.ctrlKey && e.key === 'e') {
|
| 1079 |
e.preventDefault();
|
| 1080 |
+
const buttons = Array.from(document.querySelectorAll('button'));
|
| 1081 |
+
const exportBtn = buttons.find(btn => btn.textContent.includes('Export'));
|
| 1082 |
if (exportBtn) exportBtn.click();
|
| 1083 |
}
|
| 1084 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1085 |
}
|
| 1086 |
"""
|
| 1087 |
)
|