siddhartharyaai commited on
Commit
15d59d2
·
verified ·
1 Parent(s): 93ac96d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -22,8 +22,9 @@ from utils import (
22
  from prompts import SYSTEM_PROMPT
23
 
24
  # The new Q&A with mic
25
- from qa import AudioBufferProcessor, handle_qa_exchange
26
- from streamlit_webrtc import webrtc_streamer, WebRtcMode
 
27
 
28
  MAX_QA_QUESTIONS = 5
29
 
@@ -145,6 +146,7 @@ def generate_podcast(
145
  except Exception as e:
146
  return None, f"Error researching topic: {str(e)}"
147
 
 
148
  text = truncate_text(text)
149
 
150
  extra_instructions = []
@@ -332,7 +334,6 @@ def main():
332
  progress_bar.progress(75)
333
  time.sleep(1.0)
334
 
335
- from utils import truncate_text
336
  audio_bytes, transcript = generate_podcast(
337
  file,
338
  url,
@@ -458,15 +459,21 @@ def main():
458
  st.write(f"You can ask up to {remaining} more question(s).")
459
 
460
  st.write("### Record Your Follow-Up Question:")
461
- from streamlit_webrtc import webrtc_streamer, WebRtcMode, RTCConfiguration
462
- from qa import AudioBufferProcessor
463
 
464
- RTC_CONFIGURATION = {"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}
 
 
 
 
 
 
 
 
465
 
466
  webrtc_ctx = webrtc_streamer(
467
  key="qna-audio-stream",
468
  mode=WebRtcMode.SENDONLY,
469
- rtc_configuration=RTC_CONFIGURATION,
470
  media_stream_constraints={"audio": True, "video": False},
471
  audio_processor_factory=AudioBufferProcessor
472
  )
@@ -478,11 +485,12 @@ def main():
478
  if webrtc_ctx.state.playing and webrtc_ctx.audio_processor:
479
  st.session_state["audio-processor"] = webrtc_ctx.audio_processor
480
 
481
- # Instead of checking .state.status, we check .state.playing
 
 
482
  if not webrtc_ctx.state.playing:
483
  st.write("Recording Stopped. You may now submit your question.")
484
 
485
- # Submit button
486
  if st.button("Submit Q&A"):
487
  if used_questions >= MAX_QA_QUESTIONS:
488
  st.warning("You have reached the Q&A limit.")
@@ -495,7 +503,6 @@ def main():
495
  if not local_wav_path:
496
  st.warning("No audio frames found. Please record again.")
497
  else:
498
- from qa import transcribe_audio_deepgram
499
  st.write("Transcribing your voice question via Deepgram...")
500
  question_text = transcribe_audio_deepgram(local_wav_path)
501
  if not question_text.strip():
 
22
  from prompts import SYSTEM_PROMPT
23
 
24
  # The new Q&A with mic
25
+ from qa import AudioBufferProcessor, handle_qa_exchange, transcribe_audio_deepgram
26
+
27
+ from streamlit_webrtc import webrtc_streamer, WebRtcMode, RTCConfiguration
28
 
29
  MAX_QA_QUESTIONS = 5
30
 
 
146
  except Exception as e:
147
  return None, f"Error researching topic: {str(e)}"
148
 
149
+ from utils import truncate_text
150
  text = truncate_text(text)
151
 
152
  extra_instructions = []
 
334
  progress_bar.progress(75)
335
  time.sleep(1.0)
336
 
 
337
  audio_bytes, transcript = generate_podcast(
338
  file,
339
  url,
 
459
  st.write(f"You can ask up to {remaining} more question(s).")
460
 
461
  st.write("### Record Your Follow-Up Question:")
 
 
462
 
463
+ # EXPLICIT STUN SERVER
464
+ # So we can confirm ICE candidates are gathered
465
+ new_rtc_config = RTCConfiguration(
466
+ {
467
+ "iceServers": [
468
+ {"urls": ["stun:stun.l.google.com:19302"]}
469
+ ]
470
+ }
471
+ )
472
 
473
  webrtc_ctx = webrtc_streamer(
474
  key="qna-audio-stream",
475
  mode=WebRtcMode.SENDONLY,
476
+ rtc_configuration=new_rtc_config, # <--- STUN server explicitly set
477
  media_stream_constraints={"audio": True, "video": False},
478
  audio_processor_factory=AudioBufferProcessor
479
  )
 
485
  if webrtc_ctx.state.playing and webrtc_ctx.audio_processor:
486
  st.session_state["audio-processor"] = webrtc_ctx.audio_processor
487
 
488
+ # Debug print: how many frames have arrived?
489
+ st.write("Frames so far:", webrtc_ctx.audio_processor.frame_count)
490
+
491
  if not webrtc_ctx.state.playing:
492
  st.write("Recording Stopped. You may now submit your question.")
493
 
 
494
  if st.button("Submit Q&A"):
495
  if used_questions >= MAX_QA_QUESTIONS:
496
  st.warning("You have reached the Q&A limit.")
 
503
  if not local_wav_path:
504
  st.warning("No audio frames found. Please record again.")
505
  else:
 
506
  st.write("Transcribing your voice question via Deepgram...")
507
  question_text = transcribe_audio_deepgram(local_wav_path)
508
  if not question_text.strip():