milwright commited on
Commit
352fa12
·
1 Parent(s): 5a8f506

add keyboard shortcuts and ui improvements to space template

Browse files

- add shift+enter hint to message input label
- implement keyboard shortcuts (ctrl+l to clear, ctrl+e to export)
- add auto-focus on message input when page loads
- sync improvements from amigai-demo subdirectory

Files changed (1) hide show
  1. space_template.py +41 -21
space_template.py CHANGED
@@ -581,7 +581,11 @@ def create_interface():
581
 
582
  # Create chat interface
583
  chatbot = gr.Chatbot(type="messages", height=400)
584
- msg = gr.Textbox(label="Message", placeholder="Type your message here...", lines=2)
 
 
 
 
585
 
586
  with gr.Row():
587
  submit_btn = gr.Button("Send", variant="primary")
@@ -1043,6 +1047,41 @@ def create_interface():
1043
  inputs=[access_input, access_granted],
1044
  outputs=[access_panel, main_panel, access_status, access_granted]
1045
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1046
 
1047
  return demo
1048
 
@@ -1056,23 +1095,4 @@ if __name__ == "__main__":
1056
 
1057
  def get_template():
1058
  """Return the space template string"""
1059
- return SPACE_TEMPLATE
1060
-
1061
-
1062
- def validate_template():
1063
- """Validate that the template has all required placeholders"""
1064
- required_placeholders = [
1065
- 'name', 'description', 'system_prompt', 'temperature', 'max_tokens',
1066
- 'model', 'api_key_var', 'theme', 'grounding_urls', 'enable_dynamic_urls',
1067
- 'enable_file_upload', 'examples', 'language'
1068
- ]
1069
-
1070
- missing = []
1071
- for placeholder in required_placeholders:
1072
- if f'{{{placeholder}}}' not in SPACE_TEMPLATE:
1073
- missing.append(placeholder)
1074
-
1075
- if missing:
1076
- raise ValueError(f"Template missing required placeholders: {missing}")
1077
-
1078
- return True
 
581
 
582
  # Create chat interface
583
  chatbot = gr.Chatbot(type="messages", height=400)
584
+ msg = gr.Textbox(
585
+ label="Message (Shift+Enter to send)",
586
+ placeholder="Type your message here...",
587
+ lines=2
588
+ )
589
 
590
  with gr.Row():
591
  submit_btn = gr.Button("Send", variant="primary")
 
1047
  inputs=[access_input, access_granted],
1048
  outputs=[access_panel, main_panel, access_status, access_granted]
1049
  )
1050
+
1051
+
1052
+ # Add keyboard shortcuts
1053
+ demo.load(
1054
+ None,
1055
+ None,
1056
+ None,
1057
+ js="""
1058
+ () => {{
1059
+ // Focus on message input when page loads
1060
+ setTimeout(() => {{
1061
+ const msgInput = document.querySelector('textarea');
1062
+ if (msgInput) msgInput.focus();
1063
+ }}, 100);
1064
+
1065
+ // Keyboard shortcuts
1066
+ document.addEventListener('keydown', function(e) {{
1067
+ // Ctrl+L to clear chat
1068
+ if (e.ctrlKey && e.key === 'l') {{
1069
+ e.preventDefault();
1070
+ const buttons = Array.from(document.querySelectorAll('button'));
1071
+ const clearBtn = buttons.find(btn => btn.textContent.includes('Clear'));
1072
+ if (clearBtn) clearBtn.click();
1073
+ }}
1074
+ // Ctrl+E to export
1075
+ else if (e.ctrlKey && e.key === 'e') {{
1076
+ e.preventDefault();
1077
+ const buttons = Array.from(document.querySelectorAll('button'));
1078
+ const exportBtn = buttons.find(btn => btn.textContent.includes('Export'));
1079
+ if (exportBtn) exportBtn.click();
1080
+ }}
1081
+ }});
1082
+ }}
1083
+ """
1084
+ )
1085
 
1086
  return demo
1087
 
 
1095
 
1096
  def get_template():
1097
  """Return the space template string"""
1098
+ return SPACE_TEMPLATE