Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ def respond(message, history: list[tuple[str, str]], system_message):
|
|
41 |
# Gradio interface setup
|
42 |
with gr.Blocks() as demo:
|
43 |
# Chatbot Interface
|
44 |
-
chatbot = gr.Chatbot()
|
45 |
state = gr.State([])
|
46 |
system_message = gr.Textbox(
|
47 |
value="You are a helpful assistant.",
|
@@ -73,38 +73,40 @@ with gr.Blocks() as demo:
|
|
73 |
outputs=[chatbot, state],
|
74 |
)
|
75 |
|
76 |
-
#
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
let
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
demo.launch()
|
|
|
|
41 |
# Gradio interface setup
|
42 |
with gr.Blocks() as demo:
|
43 |
# Chatbot Interface
|
44 |
+
chatbot = gr.Chatbot(type="messages") # Use 'messages' format for compatibility
|
45 |
state = gr.State([])
|
46 |
system_message = gr.Textbox(
|
47 |
value="You are a helpful assistant.",
|
|
|
73 |
outputs=[chatbot, state],
|
74 |
)
|
75 |
|
76 |
+
# Inject JavaScript for Speech Recognition using Gradio's HTML component
|
77 |
+
gr.HTML(
|
78 |
+
"""
|
79 |
+
<script>
|
80 |
+
let micButton = document.getElementById('mic_button');
|
81 |
+
let userInputBox = document.getElementById('user_input_box');
|
82 |
+
let recognition = null;
|
83 |
+
|
84 |
+
if ('webkitSpeechRecognition' in window) {
|
85 |
+
recognition = new webkitSpeechRecognition();
|
86 |
+
recognition.continuous = false;
|
87 |
+
recognition.interimResults = false;
|
88 |
+
|
89 |
+
recognition.onresult = function(event) {
|
90 |
+
const transcript = event.results[0][0].transcript;
|
91 |
+
userInputBox.value = transcript;
|
92 |
+
};
|
93 |
+
|
94 |
+
recognition.onspeechend = function() {
|
95 |
+
recognition.stop(); // Stop listening after 2 seconds of silence
|
96 |
+
};
|
97 |
+
|
98 |
+
micButton.onclick = function() {
|
99 |
+
recognition.start(); // Start listening when mic button is clicked
|
100 |
+
};
|
101 |
+
} else {
|
102 |
+
micButton.onclick = function() {
|
103 |
+
alert("Speech recognition is not supported in this browser.");
|
104 |
+
};
|
105 |
+
}
|
106 |
+
</script>
|
107 |
+
"""
|
108 |
+
)
|
109 |
|
110 |
if __name__ == "__main__":
|
111 |
demo.launch()
|
112 |
+
|