Spaces:
Running
Running
milwright
commited on
Commit
·
588404a
1
Parent(s):
58cbe65
Revert "remove keyboard shortcuts to comply with huggingface csp policy"
Browse filesThis reverts commit 58cbe657b6b5bdec77de88352cca328776006584.
- app.py +35 -4
- space_template.py +35 -4
app.py
CHANGED
|
@@ -152,9 +152,40 @@ class SpaceGenerator:
|
|
| 152 |
# Documentation Tab
|
| 153 |
with gr.Tab("Documentation"):
|
| 154 |
self._create_documentation_tab()
|
| 155 |
-
|
| 156 |
-
#
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
return demo
|
| 160 |
|
|
@@ -507,7 +538,7 @@ class SpaceGenerator:
|
|
| 507 |
|
| 508 |
# Message input
|
| 509 |
msg = gr.Textbox(
|
| 510 |
-
label="Message",
|
| 511 |
placeholder="Type your message here...",
|
| 512 |
lines=2
|
| 513 |
)
|
|
|
|
| 152 |
# Documentation Tab
|
| 153 |
with gr.Tab("Documentation"):
|
| 154 |
self._create_documentation_tab()
|
| 155 |
+
|
| 156 |
+
# Add keyboard shortcuts
|
| 157 |
+
demo.load(
|
| 158 |
+
None,
|
| 159 |
+
None,
|
| 160 |
+
None,
|
| 161 |
+
js="""
|
| 162 |
+
() => {
|
| 163 |
+
// Focus on message input when page loads
|
| 164 |
+
setTimeout(() => {
|
| 165 |
+
const msgInput = document.querySelector('textarea');
|
| 166 |
+
if (msgInput) msgInput.focus();
|
| 167 |
+
}, 100);
|
| 168 |
+
|
| 169 |
+
// Keyboard shortcuts
|
| 170 |
+
document.addEventListener('keydown', function(e) {
|
| 171 |
+
// Ctrl+L to clear chat
|
| 172 |
+
if (e.ctrlKey && e.key === 'l') {
|
| 173 |
+
e.preventDefault();
|
| 174 |
+
const buttons = Array.from(document.querySelectorAll('button'));
|
| 175 |
+
const clearBtn = buttons.find(btn => btn.textContent.includes('Clear'));
|
| 176 |
+
if (clearBtn) clearBtn.click();
|
| 177 |
+
}
|
| 178 |
+
// Ctrl+E to export
|
| 179 |
+
else if (e.ctrlKey && e.key === 'e') {
|
| 180 |
+
e.preventDefault();
|
| 181 |
+
const buttons = Array.from(document.querySelectorAll('button'));
|
| 182 |
+
const exportBtn = buttons.find(btn => btn.textContent.includes('Export'));
|
| 183 |
+
if (exportBtn) exportBtn.click();
|
| 184 |
+
}
|
| 185 |
+
});
|
| 186 |
+
}
|
| 187 |
+
"""
|
| 188 |
+
)
|
| 189 |
|
| 190 |
return demo
|
| 191 |
|
|
|
|
| 538 |
|
| 539 |
# Message input
|
| 540 |
msg = gr.Textbox(
|
| 541 |
+
label="Message (Shift+Enter to send)",
|
| 542 |
placeholder="Type your message here...",
|
| 543 |
lines=2
|
| 544 |
)
|
space_template.py
CHANGED
|
@@ -598,7 +598,7 @@ def create_interface():
|
|
| 598 |
# Create chat interface
|
| 599 |
chatbot = gr.Chatbot(type="messages", height=400)
|
| 600 |
msg = gr.Textbox(
|
| 601 |
-
label="Message",
|
| 602 |
placeholder="Type your message here...",
|
| 603 |
lines=2
|
| 604 |
)
|
|
@@ -1067,9 +1067,40 @@ def create_interface():
|
|
| 1067 |
outputs=[access_panel, main_panel, access_status, access_granted]
|
| 1068 |
)
|
| 1069 |
|
| 1070 |
-
|
| 1071 |
-
#
|
| 1072 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1073 |
|
| 1074 |
return demo
|
| 1075 |
|
|
|
|
| 598 |
# Create chat interface
|
| 599 |
chatbot = gr.Chatbot(type="messages", height=400)
|
| 600 |
msg = gr.Textbox(
|
| 601 |
+
label="Message (Shift+Enter to send)",
|
| 602 |
placeholder="Type your message here...",
|
| 603 |
lines=2
|
| 604 |
)
|
|
|
|
| 1067 |
outputs=[access_panel, main_panel, access_status, access_granted]
|
| 1068 |
)
|
| 1069 |
|
| 1070 |
+
|
| 1071 |
+
# Add keyboard shortcuts
|
| 1072 |
+
demo.load(
|
| 1073 |
+
None,
|
| 1074 |
+
None,
|
| 1075 |
+
None,
|
| 1076 |
+
js="""
|
| 1077 |
+
() => {{
|
| 1078 |
+
// Focus on message input when page loads
|
| 1079 |
+
setTimeout(() => {{
|
| 1080 |
+
const msgInput = document.querySelector('textarea');
|
| 1081 |
+
if (msgInput) msgInput.focus();
|
| 1082 |
+
}}, 100);
|
| 1083 |
+
|
| 1084 |
+
// Keyboard shortcuts
|
| 1085 |
+
document.addEventListener('keydown', function(e) {{
|
| 1086 |
+
// Ctrl+L to clear chat
|
| 1087 |
+
if (e.ctrlKey && e.key === 'l') {{
|
| 1088 |
+
e.preventDefault();
|
| 1089 |
+
const buttons = Array.from(document.querySelectorAll('button'));
|
| 1090 |
+
const clearBtn = buttons.find(btn => btn.textContent.includes('Clear'));
|
| 1091 |
+
if (clearBtn) clearBtn.click();
|
| 1092 |
+
}}
|
| 1093 |
+
// Ctrl+E to export
|
| 1094 |
+
else if (e.ctrlKey && e.key === 'e') {{
|
| 1095 |
+
e.preventDefault();
|
| 1096 |
+
const buttons = Array.from(document.querySelectorAll('button'));
|
| 1097 |
+
const exportBtn = buttons.find(btn => btn.textContent.includes('Export'));
|
| 1098 |
+
if (exportBtn) exportBtn.click();
|
| 1099 |
+
}}
|
| 1100 |
+
}});
|
| 1101 |
+
}}
|
| 1102 |
+
"""
|
| 1103 |
+
)
|
| 1104 |
|
| 1105 |
return demo
|
| 1106 |
|