Update app.py
Browse files
app.py
CHANGED
|
@@ -55,7 +55,7 @@ def process_audio(audio: tuple, state: AppState):
|
|
| 55 |
state.pause_detected = pause_detected
|
| 56 |
|
| 57 |
if state.pause_detected:
|
| 58 |
-
return gr.
|
| 59 |
else:
|
| 60 |
return None, state
|
| 61 |
|
|
@@ -130,9 +130,9 @@ def response(state: AppState):
|
|
| 130 |
|
| 131 |
def start_recording_user(state: AppState):
|
| 132 |
if not state.stopped:
|
| 133 |
-
return gr.
|
| 134 |
else:
|
| 135 |
-
return gr.
|
| 136 |
|
| 137 |
def set_api_key(api_key, state):
|
| 138 |
if not api_key:
|
|
@@ -156,7 +156,7 @@ with gr.Blocks() as demo:
|
|
| 156 |
|
| 157 |
with gr.Row():
|
| 158 |
with gr.Column():
|
| 159 |
-
input_audio = gr.Audio(label="Input Audio",
|
| 160 |
with gr.Column():
|
| 161 |
chatbot = gr.Chatbot(label="Conversation", type="messages")
|
| 162 |
output_audio = gr.Audio(label="Output Audio", autoplay=True)
|
|
@@ -178,11 +178,10 @@ with gr.Blocks() as demo:
|
|
| 178 |
response,
|
| 179 |
[state],
|
| 180 |
[chatbot, output_audio, state],
|
| 181 |
-
every=1 # Ensures outputs are updated as they are yielded
|
| 182 |
)
|
| 183 |
|
| 184 |
# Automatically restart recording after the assistant's response
|
| 185 |
-
restart = output_audio.
|
| 186 |
start_recording_user,
|
| 187 |
[state],
|
| 188 |
[input_audio]
|
|
@@ -190,7 +189,7 @@ with gr.Blocks() as demo:
|
|
| 190 |
|
| 191 |
# Add a "Stop Conversation" button
|
| 192 |
cancel = gr.Button("Stop Conversation", variant="stop")
|
| 193 |
-
cancel.click(lambda: (AppState(stopped=True), gr.
|
| 194 |
-
|
| 195 |
|
| 196 |
-
demo.launch()
|
|
|
|
| 55 |
state.pause_detected = pause_detected
|
| 56 |
|
| 57 |
if state.pause_detected:
|
| 58 |
+
return gr.update(recording=False), state
|
| 59 |
else:
|
| 60 |
return None, state
|
| 61 |
|
|
|
|
| 130 |
|
| 131 |
def start_recording_user(state: AppState):
|
| 132 |
if not state.stopped:
|
| 133 |
+
return gr.update(recording=True)
|
| 134 |
else:
|
| 135 |
+
return gr.update(recording=False)
|
| 136 |
|
| 137 |
def set_api_key(api_key, state):
|
| 138 |
if not api_key:
|
|
|
|
| 156 |
|
| 157 |
with gr.Row():
|
| 158 |
with gr.Column():
|
| 159 |
+
input_audio = gr.Audio(label="Input Audio", source="microphone", type="numpy")
|
| 160 |
with gr.Column():
|
| 161 |
chatbot = gr.Chatbot(label="Conversation", type="messages")
|
| 162 |
output_audio = gr.Audio(label="Output Audio", autoplay=True)
|
|
|
|
| 178 |
response,
|
| 179 |
[state],
|
| 180 |
[chatbot, output_audio, state],
|
|
|
|
| 181 |
)
|
| 182 |
|
| 183 |
# Automatically restart recording after the assistant's response
|
| 184 |
+
restart = output_audio.change(
|
| 185 |
start_recording_user,
|
| 186 |
[state],
|
| 187 |
[input_audio]
|
|
|
|
| 189 |
|
| 190 |
# Add a "Stop Conversation" button
|
| 191 |
cancel = gr.Button("Stop Conversation", variant="stop")
|
| 192 |
+
cancel.click(lambda: (AppState(stopped=True), gr.update(recording=False)), None,
|
| 193 |
+
[state, input_audio], cancels=[respond, restart])
|
| 194 |
|
| 195 |
+
demo.launch(queue=True, stream=True)
|