siddhartharya commited on
Commit
ea2bf21
1 Parent(s): fb1499c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -44
app.py CHANGED
@@ -43,7 +43,7 @@ def generate_podcast(file, url, tone, length):
43
  try:
44
  for item in script.dialogue:
45
  audio_file = generate_audio(item.text, item.speaker)
46
- audio_segment = AudioSegment.from_mp3(audio_file)
47
  audio_segments.append(audio_segment)
48
  transcript += f"**{item.speaker}**: {item.text}\n\n"
49
  os.remove(audio_file) # Clean up temporary audio file
@@ -52,50 +52,10 @@ def generate_podcast(file, url, tone, length):
52
 
53
  combined_audio = sum(audio_segments)
54
 
55
- with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_audio:
56
- combined_audio.export(temp_audio.name, format="mp3")
57
  temp_audio_path = temp_audio.name
58
 
59
  return temp_audio_path, transcript
60
 
61
- instructions = """
62
- # Podcast Generator
63
-
64
- Welcome to the Podcast Generator project! This tool allows you to create custom podcast episodes using AI-generated content.
65
-
66
- ## Features
67
- * Generate podcast scripts from PDF content or web pages
68
- * Convert text to speech for a natural listening experience
69
- * Choose the tone of your podcast
70
- * Export episodes as MP3 files
71
-
72
- ## How to Use
73
- 1. Upload a PDF file OR enter a URL (content will be truncated to 2048 tokens if longer)
74
- 2. Select the desired tone (humorous, casual, formal)
75
- 3. Choose the podcast length
76
- 4. Click "Generate" to create your podcast
77
- 5. Listen to the generated audio and review the transcript
78
-
79
- Note: This tool uses the LLaMa 3.1 70B model for script generation and Voice RSS for text-to-speech conversion. The input is limited to 2048 tokens to ensure compatibility with the model. The podcast features John (Male, American accent) and Lily (Female, British accent) as hosts.
80
- """
81
-
82
- iface = gr.Interface(
83
- fn=generate_podcast,
84
- inputs=[
85
- gr.File(label="Upload PDF file (optional)", file_types=[".pdf"]),
86
- gr.Textbox(label="OR Enter URL"),
87
- gr.Radio(["humorous", "casual", "formal"], label="Select podcast tone", value="casual"),
88
- gr.Radio(["Short (1-2 min)", "Medium (3-5 min)"], label="Podcast length", value="Medium (3-5 min)")
89
- ],
90
- outputs=[
91
- gr.Audio(label="Generated Podcast"),
92
- gr.Markdown(label="Transcript")
93
- ],
94
- title="Custom NotebookLM-type Podcast Generator (2048 token limit)",
95
- description=instructions,
96
- allow_flagging="never",
97
- theme=gr.themes.Soft()
98
- )
99
-
100
- if __name__ == "__main__":
101
- iface.launch()
 
43
  try:
44
  for item in script.dialogue:
45
  audio_file = generate_audio(item.text, item.speaker)
46
+ audio_segment = AudioSegment.from_wav(audio_file)
47
  audio_segments.append(audio_segment)
48
  transcript += f"**{item.speaker}**: {item.text}\n\n"
49
  os.remove(audio_file) # Clean up temporary audio file
 
52
 
53
  combined_audio = sum(audio_segments)
54
 
55
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:
56
+ combined_audio.export(temp_audio.name, format="wav")
57
  temp_audio_path = temp_audio.name
58
 
59
  return temp_audio_path, transcript
60
 
61
+ # The rest of the app.py file remains the same