Add recording hotkey support.
Browse files
app.py
CHANGED
@@ -88,8 +88,32 @@ def copy_notify(code):
|
|
88 |
gr.Info("App code snippet copied!")
|
89 |
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
with gr.Blocks() as demo:
|
92 |
-
gr.Markdown("<h1 align=\"center\">KiteWind πͺπ</h1>")
|
93 |
gr.Markdown(
|
94 |
"<h4 align=\"center\">Chat-assisted web app creator by <a href=\"https://huggingface.co/gstaff\">@gstaff</a></h4>")
|
95 |
selectedTab = gr.State(value='stlite')
|
@@ -102,7 +126,7 @@ with gr.Blocks() as demo:
|
|
102 |
with gr.Row():
|
103 |
with gr.Column():
|
104 |
with gr.Group():
|
105 |
-
in_audio = gr.Audio(label="Record a voice request", source='microphone', type='filepath')
|
106 |
in_prompt = gr.Textbox(label="Or type a text request and press Enter",
|
107 |
placeholder="Need an idea? Try one of these:\n- Add a button to reverse the name\n- Change the greeting to Spanish\n- Make the button primary")
|
108 |
out_text = gr.TextArea(label="Chat Assistant Response")
|
@@ -141,7 +165,7 @@ with gr.Blocks() as demo:
|
|
141 |
with gr.Row():
|
142 |
with gr.Column():
|
143 |
with gr.Group():
|
144 |
-
in_audio = gr.Audio(label="Record a voice request", source='microphone', type='filepath')
|
145 |
in_prompt = gr.Textbox(label="Or type a text request and press Enter",
|
146 |
placeholder="Need an idea? Try one of these:\n- Add a button to reverse the name\n- Change the greeting to Hola\n- Put the reversed name output into a separate textbox\n- Change the theme from monochrome to soft")
|
147 |
out_text = gr.TextArea(label="Chat Assistant Response")
|
@@ -176,6 +200,7 @@ with gr.Blocks() as demo:
|
|
176 |
gradio_lite_tab.select(lambda: "gradio-lite", None, selectedTab).then(None, None, None,
|
177 |
_js=load_js(DemoType.GRADIO))
|
178 |
demo.load(None, None, None, _js=load_js(DemoType.STREAMLIT))
|
|
|
179 |
demo.css = "footer {visibility: hidden}"
|
180 |
|
181 |
if __name__ == "__main__":
|
|
|
88 |
gr.Info("App code snippet copied!")
|
89 |
|
90 |
|
91 |
+
def add_hotkeys() -> str:
|
92 |
+
return """() => {
|
93 |
+
function gradioApp() {
|
94 |
+
const elems = document.getElementsByTagName('gradio-app');
|
95 |
+
const elem = elems.length == 0 ? document : elems[0];
|
96 |
+
|
97 |
+
if (elem !== document) {
|
98 |
+
elem.getElementById = function(id) {
|
99 |
+
return document.getElementById(id);
|
100 |
+
};
|
101 |
+
}
|
102 |
+
return elem.shadowRoot ? elem.shadowRoot : elem;
|
103 |
+
}
|
104 |
+
window.addEventListener('keydown', (e) => {
|
105 |
+
if (e.keyCode == 192 && e.ctrlKey) { // CTRL + ` key
|
106 |
+
const recordButton = gradioApp().querySelector("div.mic-wrap > button");
|
107 |
+
console.log(recordButton);
|
108 |
+
recordButton.click();
|
109 |
+
}
|
110 |
+
});
|
111 |
+
}
|
112 |
+
"""
|
113 |
+
|
114 |
+
|
115 |
with gr.Blocks() as demo:
|
116 |
+
gr.Markdown("<h1 id=\"TEST\" align=\"center\">KiteWind πͺπ</h1>")
|
117 |
gr.Markdown(
|
118 |
"<h4 align=\"center\">Chat-assisted web app creator by <a href=\"https://huggingface.co/gstaff\">@gstaff</a></h4>")
|
119 |
selectedTab = gr.State(value='stlite')
|
|
|
126 |
with gr.Row():
|
127 |
with gr.Column():
|
128 |
with gr.Group():
|
129 |
+
in_audio = gr.Audio(label="Record a voice request (click or press ctrl + ` to start/stop)", source='microphone', type='filepath')
|
130 |
in_prompt = gr.Textbox(label="Or type a text request and press Enter",
|
131 |
placeholder="Need an idea? Try one of these:\n- Add a button to reverse the name\n- Change the greeting to Spanish\n- Make the button primary")
|
132 |
out_text = gr.TextArea(label="Chat Assistant Response")
|
|
|
165 |
with gr.Row():
|
166 |
with gr.Column():
|
167 |
with gr.Group():
|
168 |
+
in_audio = gr.Audio(label="Record a voice request (click or press ctrl + ` to start/stop)", source='microphone', type='filepath')
|
169 |
in_prompt = gr.Textbox(label="Or type a text request and press Enter",
|
170 |
placeholder="Need an idea? Try one of these:\n- Add a button to reverse the name\n- Change the greeting to Hola\n- Put the reversed name output into a separate textbox\n- Change the theme from monochrome to soft")
|
171 |
out_text = gr.TextArea(label="Chat Assistant Response")
|
|
|
200 |
gradio_lite_tab.select(lambda: "gradio-lite", None, selectedTab).then(None, None, None,
|
201 |
_js=load_js(DemoType.GRADIO))
|
202 |
demo.load(None, None, None, _js=load_js(DemoType.STREAMLIT))
|
203 |
+
demo.load(None, None, None, _js=add_hotkeys())
|
204 |
demo.css = "footer {visibility: hidden}"
|
205 |
|
206 |
if __name__ == "__main__":
|