Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,3 @@
|
|
1 |
-
|
2 |
-
6. Changes in **`prompts.py`**: No Change
|
3 |
-
|
4 |
-
7. Changes to **`APP.PY`**
|
5 |
-
```python
|
6 |
import streamlit as st
|
7 |
import time
|
8 |
import re
|
@@ -15,13 +10,14 @@ import difflib
|
|
15 |
from utils import (
|
16 |
generate_script,
|
17 |
generate_audio_mp3,
|
18 |
-
truncate_text,
|
19 |
-
extract_text_from_url,
|
20 |
-
transcribe_youtube_video,
|
21 |
-
# research_topic, #Removed
|
22 |
mix_with_bg_music,
|
23 |
DialogueItem,
|
24 |
-
run_research_agent #Imported
|
|
|
25 |
)
|
26 |
from prompts import SYSTEM_PROMPT
|
27 |
|
@@ -96,9 +92,6 @@ def regenerate_audio_from_dialogue(dialogue_items, custom_bg_music_path=None):
|
|
96 |
return audio_bytes, transcript
|
97 |
|
98 |
def generate_podcast(
|
99 |
-
# file, #Removed
|
100 |
-
# url, #Removed
|
101 |
-
# video_url, #Removed
|
102 |
research_topic_input,
|
103 |
tone,
|
104 |
length_minutes,
|
@@ -110,47 +103,13 @@ def generate_podcast(
|
|
110 |
sponsor_content,
|
111 |
sponsor_style,
|
112 |
custom_bg_music_path
|
113 |
-
)
|
114 |
-
# sources = [bool(file), bool(url), bool(video_url), bool(research_topic_input)]
|
115 |
-
# if sum(sources) > 1:
|
116 |
-
# return None, "Provide only one input (PDF, URL, YouTube, or Topic)."
|
117 |
-
# if not any(sources):
|
118 |
-
# return None, "Please provide at least one source."
|
119 |
if not research_topic_input:
|
120 |
return None, "Please enter a topic to research for the podcast."
|
121 |
-
text = ""
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
# return None, "Please upload a PDF file."
|
126 |
-
# reader = pypdf.PdfReader(file)
|
127 |
-
# text = " ".join(page.extract_text() for page in reader.pages if page.extract_text())
|
128 |
-
# except Exception as e:
|
129 |
-
# return None, f"Error reading PDF: {str(e)}"
|
130 |
-
# elif url: #Removed
|
131 |
-
# try:
|
132 |
-
# text = extract_text_from_url(url)
|
133 |
-
# if not text:
|
134 |
-
# return None, "Failed to extract text from URL."
|
135 |
-
# except Exception as e:
|
136 |
-
# return None, f"Error extracting text from URL: {str(e)}"
|
137 |
-
# elif video_url: #Removed
|
138 |
-
# try:
|
139 |
-
# text = transcribe_youtube_video(video_url)
|
140 |
-
# if not text:
|
141 |
-
# return None, "Failed to transcribe YouTube video."
|
142 |
-
# except Exception as e:
|
143 |
-
# return None, f"Error transcribing YouTube video: {str(e)}"
|
144 |
-
# elif research_topic_input:#Removed
|
145 |
-
# try:
|
146 |
-
# text = research_topic(research_topic_input)
|
147 |
-
# if not text:
|
148 |
-
# return None, f"Sorry, no information found on '{research_topic_input}'."
|
149 |
-
# except Exception as e:
|
150 |
-
# return None, f"Error researching topic: {str(e)}"
|
151 |
-
text = st.session_state["report_content"] #The text for the podcast is taken from the report content.
|
152 |
-
# from utils import truncate_text #Removed Truncate text
|
153 |
-
# text = truncate_text(text)
|
154 |
|
155 |
extra_instructions = []
|
156 |
if host_name or guest_name:
|
@@ -166,7 +125,6 @@ def generate_podcast(
|
|
166 |
f"Sponsor Content Provided (should be under ~30 seconds):\n{sponsor_content}"
|
167 |
)
|
168 |
|
169 |
-
from prompts import SYSTEM_PROMPT
|
170 |
combined_instructions = "\n\n".join(extra_instructions).strip()
|
171 |
full_prompt = SYSTEM_PROMPT
|
172 |
if combined_instructions:
|
@@ -176,7 +134,6 @@ def generate_podcast(
|
|
176 |
if st.session_state.get("language_selection") == "Hinglish":
|
177 |
full_prompt += "\n\nPlease generate the script in Romanized Hindi.\n"
|
178 |
|
179 |
-
from utils import generate_script, generate_audio_mp3, mix_with_bg_music
|
180 |
try:
|
181 |
script = generate_script(
|
182 |
full_prompt,
|
@@ -250,7 +207,7 @@ def highlight_differences(original: str, edited: str) -> str:
|
|
250 |
|
251 |
def main():
|
252 |
st.set_page_config(
|
253 |
-
page_title="MyPod
|
254 |
layout="centered"
|
255 |
)
|
256 |
|
@@ -272,7 +229,7 @@ def main():
|
|
272 |
with logo_col:
|
273 |
st.image("logomypod.jpg", width=70)
|
274 |
with title_col:
|
275 |
-
st.markdown("## MyPod v3: AI-Powered Podcast
|
276 |
|
277 |
st.markdown("""
|
278 |
Welcome to **MyPod**, your go-to AI-powered podcast generator and research report tool! 🎉
|
@@ -331,7 +288,6 @@ def main():
|
|
331 |
st.text_area("Report Content", value=report_content, height=300)
|
332 |
|
333 |
# Generate PDF and offer download
|
334 |
-
from utils import generate_report
|
335 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmpfile:
|
336 |
pdf_path = tmpfile.name
|
337 |
generate_report(report_content, filename=pdf_path) # Generate PDF
|
@@ -356,13 +312,7 @@ def main():
|
|
356 |
elif mode == "Generate Podcast":
|
357 |
st.markdown("### Generate Podcast")
|
358 |
|
359 |
-
|
360 |
-
# with col1:
|
361 |
-
# file = st.file_uploader("Upload File (.pdf only)", type=["pdf"])
|
362 |
-
# url = st.text_input("Or Enter Website URL")
|
363 |
-
# video_url = st.text_input("Or Enter YouTube Link (Captioned videos)")
|
364 |
-
# with col2:
|
365 |
-
research_topic_input = st.text_input("Or Research a Topic for the podcast")
|
366 |
tone = st.radio("Tone", ["Casual", "Formal", "Humorous", "Youthful"], index=0)
|
367 |
length_minutes = st.slider("Podcast Length (in minutes)", 1, 60, 3)
|
368 |
|
@@ -373,7 +323,7 @@ def main():
|
|
373 |
)
|
374 |
st.session_state["language_selection"] = language
|
375 |
|
376 |
-
st.markdown("### Customize Your Podcast (
|
377 |
|
378 |
with st.expander("Set Host & Guest Names/Descriptions (Optional)"):
|
379 |
host_name = st.text_input("Female Host Name (leave blank for 'Jane')")
|
@@ -433,9 +383,6 @@ def main():
|
|
433 |
time.sleep(1.0)
|
434 |
|
435 |
audio_bytes, transcript = generate_podcast(
|
436 |
-
# file, #Removed
|
437 |
-
# url, #Removed
|
438 |
-
# video_url, #Removed
|
439 |
research_topic_input,
|
440 |
tone,
|
441 |
length_minutes,
|
@@ -465,7 +412,115 @@ def main():
|
|
465 |
st.session_state["qa_count"] = 0
|
466 |
st.session_state["conversation_history"] = ""
|
467 |
|
468 |
-
if st.session_state
|
469 |
st.audio(st.session_state["audio_bytes"], format='audio/mp3')
|
470 |
st.download_button(
|
471 |
-
label="Download Podcast (MP3)",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import time
|
3 |
import re
|
|
|
10 |
from utils import (
|
11 |
generate_script,
|
12 |
generate_audio_mp3,
|
13 |
+
# truncate_text, # Removed - no longer needed
|
14 |
+
# extract_text_from_url, # Removed - no longer primary input
|
15 |
+
# transcribe_youtube_video, # Removed - no longer primary input
|
16 |
+
# research_topic, # Removed - replaced by agent
|
17 |
mix_with_bg_music,
|
18 |
DialogueItem,
|
19 |
+
run_research_agent, # Imported
|
20 |
+
generate_report
|
21 |
)
|
22 |
from prompts import SYSTEM_PROMPT
|
23 |
|
|
|
92 |
return audio_bytes, transcript
|
93 |
|
94 |
def generate_podcast(
|
|
|
|
|
|
|
95 |
research_topic_input,
|
96 |
tone,
|
97 |
length_minutes,
|
|
|
103 |
sponsor_content,
|
104 |
sponsor_style,
|
105 |
custom_bg_music_path
|
106 |
+
):
|
|
|
|
|
|
|
|
|
|
|
107 |
if not research_topic_input:
|
108 |
return None, "Please enter a topic to research for the podcast."
|
109 |
+
text = st.session_state.get("report_content", "") # Get report content
|
110 |
+
if not text:
|
111 |
+
return None, "Please generate a research report first, or enter a topic."
|
112 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
extra_instructions = []
|
115 |
if host_name or guest_name:
|
|
|
125 |
f"Sponsor Content Provided (should be under ~30 seconds):\n{sponsor_content}"
|
126 |
)
|
127 |
|
|
|
128 |
combined_instructions = "\n\n".join(extra_instructions).strip()
|
129 |
full_prompt = SYSTEM_PROMPT
|
130 |
if combined_instructions:
|
|
|
134 |
if st.session_state.get("language_selection") == "Hinglish":
|
135 |
full_prompt += "\n\nPlease generate the script in Romanized Hindi.\n"
|
136 |
|
|
|
137 |
try:
|
138 |
script = generate_script(
|
139 |
full_prompt,
|
|
|
207 |
|
208 |
def main():
|
209 |
st.set_page_config(
|
210 |
+
page_title="MyPod v3: AI-Powered Podcast & Research",
|
211 |
layout="centered"
|
212 |
)
|
213 |
|
|
|
229 |
with logo_col:
|
230 |
st.image("logomypod.jpg", width=70)
|
231 |
with title_col:
|
232 |
+
st.markdown("## MyPod v3: AI-Powered Podcast & Research")
|
233 |
|
234 |
st.markdown("""
|
235 |
Welcome to **MyPod**, your go-to AI-powered podcast generator and research report tool! 🎉
|
|
|
288 |
st.text_area("Report Content", value=report_content, height=300)
|
289 |
|
290 |
# Generate PDF and offer download
|
|
|
291 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmpfile:
|
292 |
pdf_path = tmpfile.name
|
293 |
generate_report(report_content, filename=pdf_path) # Generate PDF
|
|
|
312 |
elif mode == "Generate Podcast":
|
313 |
st.markdown("### Generate Podcast")
|
314 |
|
315 |
+
research_topic_input = st.text_input("Enter research topic for the podcast (or use a generated report):")
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
tone = st.radio("Tone", ["Casual", "Formal", "Humorous", "Youthful"], index=0)
|
317 |
length_minutes = st.slider("Podcast Length (in minutes)", 1, 60, 3)
|
318 |
|
|
|
323 |
)
|
324 |
st.session_state["language_selection"] = language
|
325 |
|
326 |
+
st.markdown("### Customize Your Podcast (Optional)")
|
327 |
|
328 |
with st.expander("Set Host & Guest Names/Descriptions (Optional)"):
|
329 |
host_name = st.text_input("Female Host Name (leave blank for 'Jane')")
|
|
|
383 |
time.sleep(1.0)
|
384 |
|
385 |
audio_bytes, transcript = generate_podcast(
|
|
|
|
|
|
|
386 |
research_topic_input,
|
387 |
tone,
|
388 |
length_minutes,
|
|
|
412 |
st.session_state["qa_count"] = 0
|
413 |
st.session_state["conversation_history"] = ""
|
414 |
|
415 |
+
if st.session_state.get("audio_bytes"):
|
416 |
st.audio(st.session_state["audio_bytes"], format='audio/mp3')
|
417 |
st.download_button(
|
418 |
+
label="Download Podcast (MP3)",
|
419 |
+
data=st.session_state["audio_bytes"],
|
420 |
+
file_name="my_podcast.mp3",
|
421 |
+
mime="audio/mpeg"
|
422 |
+
)
|
423 |
+
|
424 |
+
st.markdown("### Generated Transcript (Editable)")
|
425 |
+
edited_text = st.text_area(
|
426 |
+
"Feel free to tweak lines, fix errors, or reword anything.",
|
427 |
+
value=st.session_state["transcript"],
|
428 |
+
height=300
|
429 |
+
)
|
430 |
+
|
431 |
+
if st.session_state.get("transcript_original"):
|
432 |
+
highlighted_transcript = highlight_differences(
|
433 |
+
st.session_state["transcript_original"],
|
434 |
+
edited_text
|
435 |
+
)
|
436 |
+
|
437 |
+
st.markdown("### **Edited Transcript Highlights**", unsafe_allow_html=True)
|
438 |
+
st.markdown(highlighted_transcript, unsafe_allow_html=True)
|
439 |
+
|
440 |
+
if st.button("Regenerate Audio From Edited Text"):
|
441 |
+
regen_bar = st.progress(0)
|
442 |
+
regen_text = st.empty()
|
443 |
+
|
444 |
+
regen_text.write("🔄 Regenerating your podcast with the edits...")
|
445 |
+
regen_bar.progress(25)
|
446 |
+
time.sleep(1.0)
|
447 |
+
|
448 |
+
regen_text.write("🔧 Adjusting the script based on your changes...")
|
449 |
+
regen_bar.progress(50)
|
450 |
+
time.sleep(1.0)
|
451 |
+
|
452 |
+
dialogue_items = parse_user_edited_transcript(
|
453 |
+
edited_text,
|
454 |
+
host_name or "Jane",
|
455 |
+
guest_name or "John"
|
456 |
+
)
|
457 |
+
new_audio_bytes, new_transcript = regenerate_audio_from_dialogue(dialogue_items, custom_bg_music_path)
|
458 |
+
|
459 |
+
regen_bar.progress(75)
|
460 |
+
time.sleep(1.0)
|
461 |
+
|
462 |
+
if new_audio_bytes is None:
|
463 |
+
regen_bar.progress(100)
|
464 |
+
st.error(new_transcript)
|
465 |
+
else:
|
466 |
+
regen_bar.progress(100)
|
467 |
+
regen_text.write("✅ Regeneration complete!")
|
468 |
+
st.success("Regenerated audio below:")
|
469 |
+
|
470 |
+
st.session_state["audio_bytes"] = new_audio_bytes
|
471 |
+
st.session_state["transcript"] = new_transcript
|
472 |
+
st.session_state["transcript_original"] = new_transcript
|
473 |
+
|
474 |
+
st.audio(new_audio_bytes, format='audio/mp3')
|
475 |
+
st.download_button(
|
476 |
+
label="Download Edited Podcast (MP3)",
|
477 |
+
data=new_audio_bytes,
|
478 |
+
file_name="my_podcast_edited.mp3",
|
479 |
+
mime="audio/mpeg"
|
480 |
+
)
|
481 |
+
st.markdown("### Updated Transcript")
|
482 |
+
st.markdown(new_transcript)
|
483 |
+
|
484 |
+
st.markdown("## Post-Podcast Q&A")
|
485 |
+
used_questions = st.session_state.get("qa_count", 0)
|
486 |
+
remaining = MAX_QA_QUESTIONS - used_questions
|
487 |
+
|
488 |
+
if remaining > 0:
|
489 |
+
st.write(f"You can ask up to {remaining} more question(s).")
|
490 |
+
|
491 |
+
typed_q = st.text_input("Type your follow-up question:")
|
492 |
+
audio_q = st.audio_input("Or record an audio question (WAV)")
|
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.")
|
497 |
+
else:
|
498 |
+
question_text = typed_q.strip()
|
499 |
+
if audio_q is not None:
|
500 |
+
suffix = ".wav"
|
501 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
|
502 |
+
tmp.write(audio_q.read())
|
503 |
+
local_audio_path = tmp.name
|
504 |
+
st.write("Transcribing your audio question...")
|
505 |
+
audio_transcript = transcribe_audio_deepgram(local_audio_path)
|
506 |
+
if audio_transcript:
|
507 |
+
question_text = audio_transcript
|
508 |
+
|
509 |
+
if not question_text:
|
510 |
+
st.warning("No question found (text or audio).")
|
511 |
+
else:
|
512 |
+
st.write("Generating an answer...")
|
513 |
+
ans_audio, ans_text = handle_qa_exchange(question_text)
|
514 |
+
if ans_audio:
|
515 |
+
st.audio(ans_audio, format='audio/mp3')
|
516 |
+
st.markdown(f"**John**: {ans_text}")
|
517 |
+
st.session_state["qa_count"] = used_questions + 1
|
518 |
+
else:
|
519 |
+
st.warning("No response could be generated.")
|
520 |
+
else:
|
521 |
+
st.write("You have used all 5 Q&A opportunities.")
|
522 |
+
|
523 |
+
st.markdown("<footer>©2025 MyPod. All rights reserved.</footer>", unsafe_allow_html=True)
|
524 |
+
|
525 |
+
if __name__ == "__main__":
|
526 |
+
main()
|