Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import os
|
|
7 |
import tempfile
|
8 |
import pypdf
|
9 |
from pydub import AudioSegment, effects
|
10 |
-
import difflib
|
11 |
|
12 |
from utils import (
|
13 |
generate_script,
|
@@ -33,19 +33,14 @@ def parse_user_edited_transcript(edited_text: str, host_name: str, guest_name: s
|
|
33 |
|
34 |
Returns a list of DialogueItem.
|
35 |
"""
|
36 |
-
# Regex pattern to match lines in the format:
|
37 |
-
# **SpeakerName**: Some text here
|
38 |
pattern = r"\*\*(.+?)\*\*:\s*(.+)"
|
39 |
matches = re.findall(pattern, edited_text)
|
40 |
|
41 |
items = []
|
42 |
-
|
43 |
-
# If no matches found, treat entire text as if it's from the host
|
44 |
if not matches:
|
45 |
raw_name = host_name or "Jane"
|
46 |
text_line = edited_text.strip()
|
47 |
speaker = "Jane"
|
48 |
-
# If user typed the entire text under the guest's name, switch
|
49 |
if raw_name.lower() == guest_name.lower():
|
50 |
speaker = "John"
|
51 |
item = DialogueItem(
|
@@ -56,15 +51,12 @@ def parse_user_edited_transcript(edited_text: str, host_name: str, guest_name: s
|
|
56 |
items.append(item)
|
57 |
return items
|
58 |
|
59 |
-
# Otherwise, we found multiple lines
|
60 |
for (raw_name, text_line) in matches:
|
61 |
-
# Decide TTS speaker based on the name
|
62 |
if raw_name.lower() == host_name.lower():
|
63 |
speaker = "Jane"
|
64 |
elif raw_name.lower() == guest_name.lower():
|
65 |
speaker = "John"
|
66 |
else:
|
67 |
-
# Default to "Jane" if we can't match
|
68 |
speaker = "Jane"
|
69 |
item = DialogueItem(
|
70 |
speaker=speaker,
|
@@ -132,7 +124,7 @@ def generate_podcast(
|
|
132 |
guest_desc,
|
133 |
user_specs,
|
134 |
sponsor_content,
|
135 |
-
sponsor_style, #
|
136 |
custom_bg_music_path
|
137 |
):
|
138 |
"""
|
@@ -285,29 +277,39 @@ def highlight_differences(original: str, edited: str) -> str:
|
|
285 |
|
286 |
def main():
|
287 |
# Set page config
|
288 |
-
st.set_page_config(
|
|
|
|
|
|
|
289 |
|
290 |
-
#
|
291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
293 |
# Original Intro Explanation
|
294 |
st.markdown(
|
295 |
"Welcome to **MyPod**, your go-to AI-powered podcast generator! 🎉\n\n"
|
296 |
-
"MyPod transforms your documents, webpages, YouTube videos, or research topics into a more human-sounding,
|
|
|
297 |
"Select a tone and a duration range. The script will be on-topic, concise, and respect your chosen length.\n\n"
|
298 |
"### How to use:\n"
|
299 |
"1. **Provide one source:** PDF Files, Website URL, YouTube link or a Topic to Research.\n"
|
300 |
"2. **Choose the tone and the target duration.**\n"
|
301 |
-
"3. **Click 'Generate Podcast'** to produce your podcast. After the audio is generated,
|
|
|
302 |
"**Research a Topic:** If it's too niche or specific, you might not get the desired outcome.\n\n"
|
303 |
"**Token Limit:** Up to ~2,048 tokens are supported. Long inputs may be truncated.\n"
|
304 |
"**Note:** YouTube videos will only work if they have captions built in.\n\n"
|
305 |
-
"⏳**Please be patient while your podcast is being generated.** This process involves content analysis,
|
306 |
-
"and high-quality audio synthesis, which may take a few minutes.\n\n"
|
307 |
"🔥 **Ready to create your personalized podcast?** Give it a try now and let the magic happen! 🔥"
|
308 |
)
|
309 |
|
310 |
-
# Two columns for inputs
|
311 |
col1, col2 = st.columns(2)
|
312 |
with col1:
|
313 |
file = st.file_uploader("Upload File (.pdf only)", type=["pdf"])
|
@@ -318,7 +320,6 @@ def main():
|
|
318 |
tone = st.radio("Tone", ["Humorous", "Formal", "Casual", "Youthful"], index=2)
|
319 |
length_minutes = st.slider("Podcast Length (in minutes)", 1, 60, 3)
|
320 |
|
321 |
-
# Additional user customizations
|
322 |
st.markdown("### Customize Your Podcast (New Features)")
|
323 |
|
324 |
# Host & Guest
|
@@ -330,8 +331,6 @@ def main():
|
|
330 |
|
331 |
# Additional specs
|
332 |
user_specs = st.text_area("Any special instructions or prompts for the script? (Optional)", "")
|
333 |
-
|
334 |
-
# Sponsor content
|
335 |
sponsor_content = st.text_area("Sponsored Content / Ad (Optional)", "")
|
336 |
|
337 |
# Sponsor integration style
|
|
|
7 |
import tempfile
|
8 |
import pypdf
|
9 |
from pydub import AudioSegment, effects
|
10 |
+
import difflib
|
11 |
|
12 |
from utils import (
|
13 |
generate_script,
|
|
|
33 |
|
34 |
Returns a list of DialogueItem.
|
35 |
"""
|
|
|
|
|
36 |
pattern = r"\*\*(.+?)\*\*:\s*(.+)"
|
37 |
matches = re.findall(pattern, edited_text)
|
38 |
|
39 |
items = []
|
|
|
|
|
40 |
if not matches:
|
41 |
raw_name = host_name or "Jane"
|
42 |
text_line = edited_text.strip()
|
43 |
speaker = "Jane"
|
|
|
44 |
if raw_name.lower() == guest_name.lower():
|
45 |
speaker = "John"
|
46 |
item = DialogueItem(
|
|
|
51 |
items.append(item)
|
52 |
return items
|
53 |
|
|
|
54 |
for (raw_name, text_line) in matches:
|
|
|
55 |
if raw_name.lower() == host_name.lower():
|
56 |
speaker = "Jane"
|
57 |
elif raw_name.lower() == guest_name.lower():
|
58 |
speaker = "John"
|
59 |
else:
|
|
|
60 |
speaker = "Jane"
|
61 |
item = DialogueItem(
|
62 |
speaker=speaker,
|
|
|
124 |
guest_desc,
|
125 |
user_specs,
|
126 |
sponsor_content,
|
127 |
+
sponsor_style, # "Separate Break" or "Blended"
|
128 |
custom_bg_music_path
|
129 |
):
|
130 |
"""
|
|
|
277 |
|
278 |
def main():
|
279 |
# Set page config
|
280 |
+
st.set_page_config(
|
281 |
+
page_title="MyPod - AI-based Podcast Generator",
|
282 |
+
layout="centered"
|
283 |
+
)
|
284 |
|
285 |
+
# Place the logo to the left of the main title
|
286 |
+
# We'll create 2 columns: narrow col for the logo, wide col for the text
|
287 |
+
logo_col, title_col = st.columns([1, 10])
|
288 |
+
with logo_col:
|
289 |
+
# Use the exact file name "logomypod.jpg" per your request
|
290 |
+
st.image("logomypod.jpg", width=60)
|
291 |
+
with title_col:
|
292 |
+
st.markdown("## MyPod - AI powered Podcast Generator")
|
293 |
|
294 |
# Original Intro Explanation
|
295 |
st.markdown(
|
296 |
"Welcome to **MyPod**, your go-to AI-powered podcast generator! 🎉\n\n"
|
297 |
+
"MyPod transforms your documents, webpages, YouTube videos, or research topics into a more human-sounding, "
|
298 |
+
"conversational podcast.\n"
|
299 |
"Select a tone and a duration range. The script will be on-topic, concise, and respect your chosen length.\n\n"
|
300 |
"### How to use:\n"
|
301 |
"1. **Provide one source:** PDF Files, Website URL, YouTube link or a Topic to Research.\n"
|
302 |
"2. **Choose the tone and the target duration.**\n"
|
303 |
+
"3. **Click 'Generate Podcast'** to produce your podcast. After the audio is generated, "
|
304 |
+
" you can edit the transcript and re-generate the audio with your edits if needed.\n\n"
|
305 |
"**Research a Topic:** If it's too niche or specific, you might not get the desired outcome.\n\n"
|
306 |
"**Token Limit:** Up to ~2,048 tokens are supported. Long inputs may be truncated.\n"
|
307 |
"**Note:** YouTube videos will only work if they have captions built in.\n\n"
|
308 |
+
"⏳**Please be patient while your podcast is being generated.** This process involves content analysis, "
|
309 |
+
"script creation, and high-quality audio synthesis, which may take a few minutes.\n\n"
|
310 |
"🔥 **Ready to create your personalized podcast?** Give it a try now and let the magic happen! 🔥"
|
311 |
)
|
312 |
|
|
|
313 |
col1, col2 = st.columns(2)
|
314 |
with col1:
|
315 |
file = st.file_uploader("Upload File (.pdf only)", type=["pdf"])
|
|
|
320 |
tone = st.radio("Tone", ["Humorous", "Formal", "Casual", "Youthful"], index=2)
|
321 |
length_minutes = st.slider("Podcast Length (in minutes)", 1, 60, 3)
|
322 |
|
|
|
323 |
st.markdown("### Customize Your Podcast (New Features)")
|
324 |
|
325 |
# Host & Guest
|
|
|
331 |
|
332 |
# Additional specs
|
333 |
user_specs = st.text_area("Any special instructions or prompts for the script? (Optional)", "")
|
|
|
|
|
334 |
sponsor_content = st.text_area("Sponsored Content / Ad (Optional)", "")
|
335 |
|
336 |
# Sponsor integration style
|