awacke1 commited on
Commit
04176b8
·
verified ·
1 Parent(s): c577d03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -432,6 +432,24 @@ async def async_save_qa_with_audio(
432
 
433
  return md_file, audio_file, md_time, audio_time
434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  def create_download_link_with_cache(file_path: str, file_type: str = "mp3") -> str:
436
  """
437
  ⬇️ Create a download link for a file with caching & error handling.
@@ -663,6 +681,15 @@ def perform_ai_lookup(
663
  # ▶ Print and store
664
  st.write("### Claude's reply 🧠:")
665
  st.markdown(result_text)
 
 
 
 
 
 
 
 
 
666
 
667
  # ▶ We'll add to the chat history
668
  st.session_state.chat_history.append({"user": q, "claude": result_text})
@@ -670,6 +697,11 @@ def perform_ai_lookup(
670
  # ▶ Return final text
671
  end = time.time()
672
  st.write(f"**Elapsed:** {end - start:.2f}s")
 
 
 
 
 
673
 
674
  return result_text
675
 
 
432
 
433
  return md_file, audio_file, md_time, audio_time
434
 
435
+ def save_qa_with_audio(question, answer, voice=None):
436
+ """Save Q&A to markdown and also generate audio."""
437
+ if not voice:
438
+ voice = st.session_state['tts_voice']
439
+
440
+ combined_text = f"# Question\n{question}\n\n# Answer\n{answer}"
441
+ md_file = create_file(question, answer, "md")
442
+ audio_text = f"{question}\n\nAnswer: {answer}"
443
+ audio_file = speak_with_edge_tts(
444
+ audio_text,
445
+ voice=voice,
446
+ file_format=st.session_state['audio_format']
447
+ )
448
+ return md_file, audio_file
449
+
450
+
451
+
452
+
453
  def create_download_link_with_cache(file_path: str, file_type: str = "mp3") -> str:
454
  """
455
  ⬇️ Create a download link for a file with caching & error handling.
 
681
  # ▶ Print and store
682
  st.write("### Claude's reply 🧠:")
683
  st.markdown(result_text)
684
+
685
+
686
+ # Save & produce audio
687
+ #create_file(q, result_text)
688
+ #md_file, audio_file = save_qa_with_audio(q, result_text)
689
+ #st.subheader("📝 Main Response Audio")
690
+ #play_and_download_audio(audio_file, st.session_state['audio_format'])
691
+
692
+
693
 
694
  # ▶ We'll add to the chat history
695
  st.session_state.chat_history.append({"user": q, "claude": result_text})
 
697
  # ▶ Return final text
698
  end = time.time()
699
  st.write(f"**Elapsed:** {end - start:.2f}s")
700
+
701
+
702
+ # Try async run from top
703
+ st.markdown('# Async run:')
704
+ asyncio.run(process_voice_input(q + result_text))
705
 
706
  return result_text
707