Daaku-C5 commited on
Commit
8277f45
·
verified ·
1 Parent(s): 6e6e6ae

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +24 -13
src/streamlit_app.py CHANGED
@@ -67,6 +67,8 @@ def init_session_state():
67
  st.session_state.context = load_context()
68
  if 'processing' not in st.session_state:
69
  st.session_state.processing = False
 
 
70
 
71
  def load_context():
72
  """Load the context from file or return default."""
@@ -223,22 +225,31 @@ def main():
223
 
224
  # Process audio when new recording is available
225
  if audio_bytes and not st.session_state.processing:
226
- st.session_state.processing = True
 
 
227
 
228
- user_text, ai_response, speech_audio = process_audio(audio_bytes)
229
-
230
- if user_text and ai_response:
231
- # Add to conversation history
232
- st.session_state.conversation_history.append({
233
- "user": user_text,
234
- "ai": ai_response,
235
- "speech": speech_audio
236
- })
 
 
 
 
 
 
 
 
237
 
238
  # Force a rerun to update the conversation display
239
- st.rerun()
240
-
241
- st.session_state.processing = False
242
 
243
  with col2:
244
  st.subheader("💬 Conversation")
 
67
  st.session_state.context = load_context()
68
  if 'processing' not in st.session_state:
69
  st.session_state.processing = False
70
+ if 'last_audio_hash' not in st.session_state:
71
+ st.session_state.last_audio_hash = None
72
 
73
  def load_context():
74
  """Load the context from file or return default."""
 
225
 
226
  # Process audio when new recording is available
227
  if audio_bytes and not st.session_state.processing:
228
+ # Create a hash of the audio to detect new recordings
229
+ import hashlib
230
+ audio_hash = hashlib.md5(audio_bytes).hexdigest()
231
 
232
+ # Only process if this is a new recording
233
+ if audio_hash != st.session_state.last_audio_hash:
234
+ st.session_state.processing = True
235
+ st.session_state.last_audio_hash = audio_hash
236
+
237
+ user_text, ai_response, speech_audio = process_audio(audio_bytes)
238
+
239
+ if user_text and ai_response:
240
+ # Add to conversation history
241
+ st.session_state.conversation_history.append({
242
+ "user": user_text,
243
+ "ai": ai_response,
244
+ "speech": speech_audio
245
+ })
246
+
247
+ # Reset processing flag before rerun
248
+ st.session_state.processing = False
249
 
250
  # Force a rerun to update the conversation display
251
+ if user_text and ai_response:
252
+ st.rerun()
 
253
 
254
  with col2:
255
  st.subheader("💬 Conversation")