IAMTFRMZA commited on
Commit
d2baa88
ยท
verified ยท
1 Parent(s): 65aa40f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -136,6 +136,9 @@ def clear_chat_and_transcript(client_id):
136
  connections[client_id].transcript = ""
137
  return [], "", None, None
138
 
 
 
 
139
  # UI
140
  with gr.Blocks(theme=gr.themes.Soft()) as app:
141
  gr.Markdown("# ๐Ÿ“„ Document AI Assistant")
@@ -147,7 +150,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
147
  padding: 10px 24px !important;
148
  margin-top: 6px;
149
  }
150
- .record-button button {
151
  display: none !important;
152
  }
153
  </style>
@@ -170,26 +173,36 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
170
  send_btn = gr.Button("Send", variant="primary", scale=2)
171
 
172
  with gr.Accordion("๐ŸŽค Voice Transcription", open=False) as voice_section:
173
- voice_input = gr.Audio(label="๐ŸŽ™๏ธ Record", streaming=True, elem_classes="record-button")
174
  voice_transcript = gr.Textbox(label="Transcript", lines=2, interactive=False)
175
 
176
  with gr.Row():
 
177
  ask_btn = gr.Button("๐ŸŸข Ask", elem_id="ask-btn")
178
  clear_chat_btn = gr.Button("๐Ÿงน Clear Chat", elem_id="clear-chat-btn")
179
- record_btn = gr.Button("๐ŸŽ™๏ธ Record", elem_id="record-btn")
180
 
181
  # Functional bindings
182
  send_btn.click(fn=handle_chat,
183
  inputs=[user_prompt, chat_state, thread_state, image_state],
184
  outputs=[user_prompt, chat, thread_state, image_state])
185
  image_state.change(fn=lambda x: x, inputs=image_state, outputs=image_display)
 
186
  voice_input.stream(fn=send_audio, inputs=[voice_input, client_id], outputs=voice_transcript, stream_every=0.5)
 
 
 
 
 
 
 
187
  ask_btn.click(fn=send_transcript_to_assistant,
188
  inputs=[voice_transcript, chat_state, thread_state, image_state],
189
  outputs=[user_prompt, chat, thread_state, image_state])
 
190
  clear_chat_btn.click(fn=clear_chat_and_transcript,
191
  inputs=[client_id],
192
  outputs=[chat, voice_transcript, thread_state, image_state])
 
193
  app.load(fn=create_ws, outputs=[client_id])
194
 
195
  app.launch()
 
136
  connections[client_id].transcript = ""
137
  return [], "", None, None
138
 
139
+ def toggle_record_visibility(is_visible):
140
+ return not is_visible, gr.update(visible=not is_visible)
141
+
142
  # UI
143
  with gr.Blocks(theme=gr.themes.Soft()) as app:
144
  gr.Markdown("# ๐Ÿ“„ Document AI Assistant")
 
150
  padding: 10px 24px !important;
151
  margin-top: 6px;
152
  }
153
+ #audio-stream button {
154
  display: none !important;
155
  }
156
  </style>
 
173
  send_btn = gr.Button("Send", variant="primary", scale=2)
174
 
175
  with gr.Accordion("๐ŸŽค Voice Transcription", open=False) as voice_section:
176
+ voice_input = gr.Audio(label="๐ŸŽ™๏ธ Mic Input", streaming=True, visible=False, elem_id="audio-stream")
177
  voice_transcript = gr.Textbox(label="Transcript", lines=2, interactive=False)
178
 
179
  with gr.Row():
180
+ record_toggle_btn = gr.Button("๐ŸŽ™๏ธ Record", elem_id="record-btn")
181
  ask_btn = gr.Button("๐ŸŸข Ask", elem_id="ask-btn")
182
  clear_chat_btn = gr.Button("๐Ÿงน Clear Chat", elem_id="clear-chat-btn")
 
183
 
184
  # Functional bindings
185
  send_btn.click(fn=handle_chat,
186
  inputs=[user_prompt, chat_state, thread_state, image_state],
187
  outputs=[user_prompt, chat, thread_state, image_state])
188
  image_state.change(fn=lambda x: x, inputs=image_state, outputs=image_display)
189
+
190
  voice_input.stream(fn=send_audio, inputs=[voice_input, client_id], outputs=voice_transcript, stream_every=0.5)
191
+
192
+ record_toggle_btn.click(
193
+ fn=toggle_record_visibility,
194
+ inputs=[voice_enabled],
195
+ outputs=[voice_enabled, voice_input]
196
+ )
197
+
198
  ask_btn.click(fn=send_transcript_to_assistant,
199
  inputs=[voice_transcript, chat_state, thread_state, image_state],
200
  outputs=[user_prompt, chat, thread_state, image_state])
201
+
202
  clear_chat_btn.click(fn=clear_chat_and_transcript,
203
  inputs=[client_id],
204
  outputs=[chat, voice_transcript, thread_state, image_state])
205
+
206
  app.load(fn=create_ws, outputs=[client_id])
207
 
208
  app.launch()