Spaces:
Running
Running
Delete app.py
Browse files
app.py
DELETED
@@ -1,152 +0,0 @@
|
|
1 |
-
from utils import generate_podcast
|
2 |
-
import streamlit as st
|
3 |
-
import time
|
4 |
-
import re
|
5 |
-
import os
|
6 |
-
import tempfile
|
7 |
-
import pypdf
|
8 |
-
from pydub import AudioSegment, effects
|
9 |
-
import difflib # For computing differences between texts
|
10 |
-
|
11 |
-
from utils import (
|
12 |
-
generate_script,
|
13 |
-
generate_audio_mp3,
|
14 |
-
truncate_text,
|
15 |
-
extract_text_from_url,
|
16 |
-
transcribe_youtube_video,
|
17 |
-
research_topic
|
18 |
-
)
|
19 |
-
from prompts import SYSTEM_PROMPT
|
20 |
-
|
21 |
-
|
22 |
-
def parse_user_edited_transcript(edited_text: str):
|
23 |
-
pattern = r"\*\*(Jane|John)\*\*:\s*(.+)"
|
24 |
-
matches = re.findall(pattern, edited_text)
|
25 |
-
if not matches:
|
26 |
-
return [("Jane", edited_text)]
|
27 |
-
return matches
|
28 |
-
|
29 |
-
|
30 |
-
def regenerate_audio_from_dialogue(dialogue_items):
|
31 |
-
audio_segments = []
|
32 |
-
transcript = ""
|
33 |
-
crossfade_duration = 50 # in ms
|
34 |
-
|
35 |
-
for speaker, line_text in dialogue_items:
|
36 |
-
audio_file = generate_audio_mp3(line_text, speaker)
|
37 |
-
seg = AudioSegment.from_file(audio_file, format="mp3")
|
38 |
-
audio_segments.append(seg)
|
39 |
-
transcript += f"**{speaker}**: {line_text}\n\n"
|
40 |
-
os.remove(audio_file)
|
41 |
-
|
42 |
-
if not audio_segments:
|
43 |
-
return None, "No audio segments were generated."
|
44 |
-
|
45 |
-
combined_spoken = audio_segments[0]
|
46 |
-
for seg in audio_segments[1:]:
|
47 |
-
combined_spoken = combined_spoken.append(seg, crossfade=crossfade_duration)
|
48 |
-
|
49 |
-
final_mix = mix_with_bg_music(combined_spoken)
|
50 |
-
|
51 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_audio:
|
52 |
-
final_mix.export(temp_audio.name, format="mp3")
|
53 |
-
final_mp3_path = temp_audio.name
|
54 |
-
|
55 |
-
with open(final_mp3_path, "rb") as f:
|
56 |
-
audio_bytes = f.read()
|
57 |
-
os.remove(final_mp3_path)
|
58 |
-
|
59 |
-
return audio_bytes, transcript
|
60 |
-
|
61 |
-
|
62 |
-
def main():
|
63 |
-
st.set_page_config(page_title="MyPod - AI-powered Podcast Generator", layout="centered")
|
64 |
-
|
65 |
-
# Display logo from the root directory
|
66 |
-
st.image("logomypod.jpg", width=150)
|
67 |
-
|
68 |
-
# Main app header
|
69 |
-
st.markdown("## MyPod - AI powered Podcast Generator")
|
70 |
-
|
71 |
-
st.markdown(
|
72 |
-
"Welcome to **MyPod**, your go-to AI-powered podcast generator! 🎉\n\n"
|
73 |
-
"MyPod transforms your documents, webpages, YouTube videos, or research topics into a more human-sounding, conversational podcast.\n"
|
74 |
-
"Select a tone and a duration range. The script will be on-topic, concise, and respect your chosen length.\n\n"
|
75 |
-
"### How to use:\n"
|
76 |
-
"1. **Provide one source:** PDF Files, Website URL, YouTube link or a Topic to Research.\n"
|
77 |
-
"2. **Choose the tone and the target duration.**\n"
|
78 |
-
"3. **Click 'Generate Podcast'** to produce your podcast. After the audio is generated, you can edit the transcript and re-generate the audio with your edits if needed.\n\n"
|
79 |
-
"**Research a Topic:** If your topic is too niche or vague, you might not get the desired outcome.\n\n"
|
80 |
-
"**Token Limit:** Up to ~2,048 tokens are supported. Long inputs may be truncated.\n"
|
81 |
-
"**Note:** YouTube videos will only work if they have captions built in.\n\n"
|
82 |
-
"⏳**Please be patient while your podcast is being generated.** This process involves content analysis, script creation, "
|
83 |
-
"and high-quality audio synthesis, which may take a few minutes.\n\n"
|
84 |
-
"🔥 **Ready to create your personalized podcast?** Give it a try now and let the magic happen! 🔥"
|
85 |
-
)
|
86 |
-
|
87 |
-
col1, col2 = st.columns(2)
|
88 |
-
with col1:
|
89 |
-
file = st.file_uploader("Upload PDF", type=["pdf"])
|
90 |
-
url = st.text_input("Or Enter URL")
|
91 |
-
video_url = st.text_input("Or Enter YouTube Link")
|
92 |
-
with col2:
|
93 |
-
research_topic_input = st.text_input("Or Research a Topic")
|
94 |
-
tone = st.radio("Tone", ["Humorous", "Formal", "Casual", "Youthful"], index=2)
|
95 |
-
length = st.radio("Length", ["1-3 Mins", "3-5 Mins", "5-10 Mins", "10-20 Mins"], index=0)
|
96 |
-
|
97 |
-
if "audio_bytes" not in st.session_state:
|
98 |
-
st.session_state["audio_bytes"] = None
|
99 |
-
if "transcript" not in st.session_state:
|
100 |
-
st.session_state["transcript"] = None
|
101 |
-
if "transcript_original" not in st.session_state:
|
102 |
-
st.session_state["transcript_original"] = None
|
103 |
-
|
104 |
-
generate_button = st.button("Generate Podcast")
|
105 |
-
|
106 |
-
if generate_button:
|
107 |
-
progress_bar = st.progress(0)
|
108 |
-
progress_text = st.empty()
|
109 |
-
|
110 |
-
progress_text.write("🔍 Analyzing your input...")
|
111 |
-
progress_bar.progress(0)
|
112 |
-
time.sleep(1.0)
|
113 |
-
|
114 |
-
progress_text.write("📝 Crafting the script...")
|
115 |
-
progress_bar.progress(25)
|
116 |
-
time.sleep(1.0)
|
117 |
-
|
118 |
-
progress_text.write("🎙️ Generating audio...")
|
119 |
-
progress_bar.progress(50)
|
120 |
-
time.sleep(1.0)
|
121 |
-
|
122 |
-
progress_text.write("🎶 Adding finishing touches...")
|
123 |
-
progress_bar.progress(75)
|
124 |
-
time.sleep(1.0)
|
125 |
-
|
126 |
-
audio_bytes, transcript = generate_podcast(
|
127 |
-
file, url, video_url, research_topic_input, tone, length
|
128 |
-
)
|
129 |
-
|
130 |
-
progress_bar.progress(100)
|
131 |
-
progress_text.write("✅ Done!")
|
132 |
-
|
133 |
-
if audio_bytes is None:
|
134 |
-
st.error(transcript)
|
135 |
-
else:
|
136 |
-
st.success("Podcast generated successfully!")
|
137 |
-
st.session_state["audio_bytes"] = audio_bytes
|
138 |
-
st.session_state["transcript"] = transcript
|
139 |
-
st.session_state["transcript_original"] = transcript
|
140 |
-
|
141 |
-
if st.session_state["audio_bytes"]:
|
142 |
-
st.audio(st.session_state["audio_bytes"], format='audio/mp3')
|
143 |
-
st.download_button(
|
144 |
-
label="Download Podcast",
|
145 |
-
data=st.session_state["audio_bytes"],
|
146 |
-
file_name="my_podcast.mp3",
|
147 |
-
mime="audio/mpeg"
|
148 |
-
)
|
149 |
-
|
150 |
-
|
151 |
-
if __name__ == "__main__":
|
152 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|