Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -98,17 +98,27 @@ def transcribe_and_chat(audio):
|
|
98 |
return response, audio_path
|
99 |
|
100 |
def create_demo():
|
101 |
-
with gr.Blocks() as demo:
|
102 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
with gr.Row():
|
105 |
with gr.Column(scale=1):
|
106 |
-
audio_input = gr.Audio(type="filepath", label="
|
|
|
107 |
|
108 |
with gr.Column(scale=1):
|
109 |
-
chat_output = gr.Textbox(label="AI Response")
|
110 |
-
audio_output = gr.Audio(label="AI Voice Response", autoplay=True)
|
|
|
|
|
|
|
111 |
|
|
|
112 |
def process_audio(audio):
|
113 |
logging.info(f"Received audio: {audio}")
|
114 |
if audio is None:
|
@@ -117,6 +127,10 @@ def create_demo():
|
|
117 |
logging.info(f"Response: {response}, Audio path: {audio_path}")
|
118 |
return response, audio_path, None # Return None to clear the audio input
|
119 |
|
|
|
|
|
|
|
|
|
120 |
demo.load(None, js="""
|
121 |
function() {
|
122 |
document.querySelector("audio").addEventListener("stop", function() {
|
@@ -145,11 +159,9 @@ def create_demo():
|
|
145 |
}
|
146 |
""")
|
147 |
|
148 |
-
audio_input.change(process_audio, inputs=[audio_input], outputs=[chat_output, audio_output, audio_input])
|
149 |
-
|
150 |
return demo
|
151 |
|
152 |
# Launch the Gradio app
|
153 |
if __name__ == "__main__":
|
154 |
demo = create_demo()
|
155 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
98 |
return response, audio_path
|
99 |
|
100 |
def create_demo():
|
101 |
+
with gr.Blocks(theme="compact") as demo:
|
102 |
+
gr.Markdown(
|
103 |
+
"""
|
104 |
+
# π£οΈ AI Voice Assistant
|
105 |
+
Welcome to your personal voice assistant! Simply record your voice, and I will respond with both text and speech. Powered by advanced AI models.
|
106 |
+
"""
|
107 |
+
)
|
108 |
|
109 |
with gr.Row():
|
110 |
with gr.Column(scale=1):
|
111 |
+
audio_input = gr.Audio(type="filepath", label="π€ Record your voice", elem_id="audio-input", source="microphone")
|
112 |
+
clear_button = gr.Button("Clear", variant="secondary", elem_id="clear-button")
|
113 |
|
114 |
with gr.Column(scale=1):
|
115 |
+
chat_output = gr.Textbox(label="π¬ AI Response", elem_id="chat-output", lines=5, interactive=False)
|
116 |
+
audio_output = gr.Audio(label="π AI Voice Response", autoplay=True, elem_id="audio-output")
|
117 |
+
|
118 |
+
# Add some spacing and a divider
|
119 |
+
gr.Markdown("---")
|
120 |
|
121 |
+
# Processing the audio input
|
122 |
def process_audio(audio):
|
123 |
logging.info(f"Received audio: {audio}")
|
124 |
if audio is None:
|
|
|
127 |
logging.info(f"Response: {response}, Audio path: {audio_path}")
|
128 |
return response, audio_path, None # Return None to clear the audio input
|
129 |
|
130 |
+
audio_input.change(process_audio, inputs=[audio_input], outputs=[chat_output, audio_output, audio_input])
|
131 |
+
clear_button.click(lambda: (None, None, None), None, [chat_output, audio_output, audio_input])
|
132 |
+
|
133 |
+
# JavaScript to handle autoplay and automatic submission
|
134 |
demo.load(None, js="""
|
135 |
function() {
|
136 |
document.querySelector("audio").addEventListener("stop", function() {
|
|
|
159 |
}
|
160 |
""")
|
161 |
|
|
|
|
|
162 |
return demo
|
163 |
|
164 |
# Launch the Gradio app
|
165 |
if __name__ == "__main__":
|
166 |
demo = create_demo()
|
167 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|