Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,8 +53,7 @@ def whisper_speech_to_text(audio):
|
|
53 |
return None
|
54 |
finally:
|
55 |
# Clear CUDA cache
|
56 |
-
|
57 |
-
print("1")
|
58 |
|
59 |
async def chat_with_ai(message, history):
|
60 |
global chat_history
|
@@ -109,21 +108,23 @@ with gr.Blocks() as demo:
|
|
109 |
audio_button = gr.Button("Send Audio")
|
110 |
text_button = gr.Button("Send Text")
|
111 |
|
112 |
-
#
|
113 |
-
demo.
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
audioElement
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
127 |
|
128 |
audio_button.click(transcribe_and_chat, inputs=audio_input, outputs=[chat_output, audio_output])
|
129 |
text_button.click(lambda x: asyncio.run(chat_with_ai(x, [])), inputs=text_input, outputs=[chat_output, audio_output])
|
|
|
53 |
return None
|
54 |
finally:
|
55 |
# Clear CUDA cache
|
56 |
+
torch.cuda.empty_cache()
|
|
|
57 |
|
58 |
async def chat_with_ai(message, history):
|
59 |
global chat_history
|
|
|
108 |
audio_button = gr.Button("Send Audio")
|
109 |
text_button = gr.Button("Send Text")
|
110 |
|
111 |
+
# Add custom JavaScript to handle spacebar press and play audio automatically
|
112 |
+
demo.append(gr.HTML("""
|
113 |
+
<script>
|
114 |
+
document.addEventListener('keydown', function(event) {
|
115 |
+
if (event.code === 'Space') {
|
116 |
+
document.querySelector('input[type="file"]').click();
|
117 |
+
}
|
118 |
+
});
|
119 |
+
|
120 |
+
document.addEventListener('gradioAudioLoaded', function(event) {
|
121 |
+
var audioElement = document.querySelector('audio');
|
122 |
+
if (audioElement) {
|
123 |
+
audioElement.play();
|
124 |
+
}
|
125 |
+
});
|
126 |
+
</script>
|
127 |
+
"""))
|
128 |
|
129 |
audio_button.click(transcribe_and_chat, inputs=audio_input, outputs=[chat_output, audio_output])
|
130 |
text_button.click(lambda x: asyncio.run(chat_with_ai(x, [])), inputs=text_input, outputs=[chat_output, audio_output])
|