Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ from prompts import SYSTEM_PROMPT
|
|
24 |
# NEW: For Q&A
|
25 |
from qa import transcribe_audio_deepgram, handle_qa_exchange
|
26 |
|
27 |
-
MAX_QA_QUESTIONS = 5
|
28 |
|
29 |
def parse_user_edited_transcript(edited_text: str, host_name: str, guest_name: str):
|
30 |
"""
|
@@ -68,10 +68,8 @@ def parse_user_edited_transcript(edited_text: str, host_name: str, guest_name: s
|
|
68 |
text=text_line
|
69 |
)
|
70 |
items.append(item)
|
71 |
-
|
72 |
return items
|
73 |
|
74 |
-
|
75 |
def regenerate_audio_from_dialogue(dialogue_items, custom_bg_music_path=None):
|
76 |
"""
|
77 |
Re-generates multi-speaker audio from user-edited DialogueItems,
|
@@ -83,7 +81,6 @@ def regenerate_audio_from_dialogue(dialogue_items, custom_bg_music_path=None):
|
|
83 |
crossfade_duration = 50 # ms
|
84 |
|
85 |
for item in dialogue_items:
|
86 |
-
# Generate TTS for each line
|
87 |
audio_file = generate_audio_mp3(item.text, item.speaker)
|
88 |
seg = AudioSegment.from_file(audio_file, format="mp3")
|
89 |
audio_segments.append(seg)
|
@@ -109,7 +106,6 @@ def regenerate_audio_from_dialogue(dialogue_items, custom_bg_music_path=None):
|
|
109 |
|
110 |
return audio_bytes, transcript
|
111 |
|
112 |
-
|
113 |
def generate_podcast(
|
114 |
file,
|
115 |
url,
|
@@ -169,6 +165,7 @@ def generate_podcast(
|
|
169 |
except Exception as e:
|
170 |
return None, f"Error researching topic: {str(e)}"
|
171 |
|
|
|
172 |
text = truncate_text(text)
|
173 |
|
174 |
extra_instructions = []
|
@@ -185,13 +182,13 @@ def generate_podcast(
|
|
185 |
f"Sponsor Content Provided (should be under ~30 seconds):\n{sponsor_content}"
|
186 |
)
|
187 |
|
188 |
-
from prompts import SYSTEM_PROMPT
|
189 |
combined_instructions = "\n\n".join(extra_instructions).strip()
|
190 |
full_prompt = SYSTEM_PROMPT
|
191 |
if combined_instructions:
|
192 |
full_prompt += f"\n\n# Additional Instructions\n{combined_instructions}\n"
|
193 |
|
194 |
-
from utils import generate_script
|
195 |
try:
|
196 |
script = generate_script(
|
197 |
full_prompt,
|
@@ -209,7 +206,6 @@ def generate_podcast(
|
|
209 |
transcript = ""
|
210 |
crossfade_duration = 50
|
211 |
|
212 |
-
from utils import generate_audio_mp3, mix_with_bg_music # Just for clarity
|
213 |
try:
|
214 |
for item in script.dialogue:
|
215 |
audio_file = generate_audio_mp3(item.text, item.speaker)
|
@@ -458,13 +454,16 @@ def main():
|
|
458 |
st.markdown("### Updated Transcript")
|
459 |
st.markdown(new_transcript)
|
460 |
|
461 |
-
#
|
|
|
|
|
462 |
st.markdown("## Post-Podcast Q&A")
|
463 |
used_questions = st.session_state["qa_count"]
|
464 |
remaining = MAX_QA_QUESTIONS - used_questions
|
465 |
|
466 |
if remaining > 0:
|
467 |
st.write(f"You can ask up to {remaining} more question(s).")
|
|
|
468 |
typed_q = st.text_input("Type your follow-up question:")
|
469 |
audio_q = st.file_uploader("Or upload an audio question (WAV, MP3)")
|
470 |
|
|
|
24 |
# NEW: For Q&A
|
25 |
from qa import transcribe_audio_deepgram, handle_qa_exchange
|
26 |
|
27 |
+
MAX_QA_QUESTIONS = 5 # up to 5 voice/text questions
|
28 |
|
29 |
def parse_user_edited_transcript(edited_text: str, host_name: str, guest_name: str):
|
30 |
"""
|
|
|
68 |
text=text_line
|
69 |
)
|
70 |
items.append(item)
|
|
|
71 |
return items
|
72 |
|
|
|
73 |
def regenerate_audio_from_dialogue(dialogue_items, custom_bg_music_path=None):
|
74 |
"""
|
75 |
Re-generates multi-speaker audio from user-edited DialogueItems,
|
|
|
81 |
crossfade_duration = 50 # ms
|
82 |
|
83 |
for item in dialogue_items:
|
|
|
84 |
audio_file = generate_audio_mp3(item.text, item.speaker)
|
85 |
seg = AudioSegment.from_file(audio_file, format="mp3")
|
86 |
audio_segments.append(seg)
|
|
|
106 |
|
107 |
return audio_bytes, transcript
|
108 |
|
|
|
109 |
def generate_podcast(
|
110 |
file,
|
111 |
url,
|
|
|
165 |
except Exception as e:
|
166 |
return None, f"Error researching topic: {str(e)}"
|
167 |
|
168 |
+
from utils import truncate_text
|
169 |
text = truncate_text(text)
|
170 |
|
171 |
extra_instructions = []
|
|
|
182 |
f"Sponsor Content Provided (should be under ~30 seconds):\n{sponsor_content}"
|
183 |
)
|
184 |
|
185 |
+
from prompts import SYSTEM_PROMPT
|
186 |
combined_instructions = "\n\n".join(extra_instructions).strip()
|
187 |
full_prompt = SYSTEM_PROMPT
|
188 |
if combined_instructions:
|
189 |
full_prompt += f"\n\n# Additional Instructions\n{combined_instructions}\n"
|
190 |
|
191 |
+
from utils import generate_script, generate_audio_mp3, mix_with_bg_music
|
192 |
try:
|
193 |
script = generate_script(
|
194 |
full_prompt,
|
|
|
206 |
transcript = ""
|
207 |
crossfade_duration = 50
|
208 |
|
|
|
209 |
try:
|
210 |
for item in script.dialogue:
|
211 |
audio_file = generate_audio_mp3(item.text, item.speaker)
|
|
|
454 |
st.markdown("### Updated Transcript")
|
455 |
st.markdown(new_transcript)
|
456 |
|
457 |
+
# -----------------------
|
458 |
+
# POST-PODCAST Q&A Logic
|
459 |
+
# -----------------------
|
460 |
st.markdown("## Post-Podcast Q&A")
|
461 |
used_questions = st.session_state["qa_count"]
|
462 |
remaining = MAX_QA_QUESTIONS - used_questions
|
463 |
|
464 |
if remaining > 0:
|
465 |
st.write(f"You can ask up to {remaining} more question(s).")
|
466 |
+
|
467 |
typed_q = st.text_input("Type your follow-up question:")
|
468 |
audio_q = st.file_uploader("Or upload an audio question (WAV, MP3)")
|
469 |
|