siddhartharya
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from utils import generate_script, generate_audio, truncate_text, extract_text_from_url
|
3 |
from prompts import SYSTEM_PROMPT
|
|
|
4 |
import pypdf
|
5 |
import os
|
6 |
import tempfile
|
@@ -29,21 +30,25 @@ def generate_podcast(file, url, tone, length):
|
|
29 |
|
30 |
script = generate_script(SYSTEM_PROMPT, truncated_text, tone, length)
|
31 |
|
32 |
-
|
33 |
transcript = ""
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as combined_audio:
|
41 |
-
for audio_file in audio_files:
|
42 |
-
with open(audio_file, 'rb') as f:
|
43 |
-
combined_audio.write(f.read())
|
44 |
-
os.remove(audio_file) # Clean up individual audio files
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
|
48 |
except Exception as e:
|
49 |
return None, f"An error occurred: {str(e)}"
|
@@ -51,22 +56,25 @@ def generate_podcast(file, url, tone, length):
|
|
51 |
instructions = """
|
52 |
# Podcast Generator
|
53 |
|
54 |
-
Welcome to the Podcast Generator project! This tool
|
55 |
|
56 |
## Features
|
57 |
* Generate podcast scripts from PDF content or web pages
|
58 |
* Convert text to speech for a natural listening experience
|
59 |
-
* Choose the tone of your podcast
|
60 |
* Export episodes as MP3 files
|
61 |
|
62 |
## How to Use
|
63 |
1. Upload a PDF file OR enter a URL (content will be truncated to 2048 tokens if longer)
|
64 |
-
2. Select the desired tone
|
|
|
|
|
|
|
65 |
3. Choose the podcast length
|
66 |
4. Click "Generate" to create your podcast
|
67 |
5. Listen to the generated audio and review the transcript
|
68 |
|
69 |
-
Note: This tool uses the LLaMa 3.1 70B model for script generation and
|
70 |
"""
|
71 |
|
72 |
iface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
from utils import generate_script, generate_audio, truncate_text, extract_text_from_url
|
3 |
from prompts import SYSTEM_PROMPT
|
4 |
+
from pydub import AudioSegment
|
5 |
import pypdf
|
6 |
import os
|
7 |
import tempfile
|
|
|
30 |
|
31 |
script = generate_script(SYSTEM_PROMPT, truncated_text, tone, length)
|
32 |
|
33 |
+
audio_segments = []
|
34 |
transcript = ""
|
35 |
+
try:
|
36 |
+
for item in script.dialogue:
|
37 |
+
audio_file = generate_audio(item.text, item.speaker)
|
38 |
+
audio_segment = AudioSegment.from_mp3(audio_file)
|
39 |
+
audio_segments.append(audio_segment)
|
40 |
+
transcript += f"**{item.speaker}**: {item.text}\n\n"
|
41 |
+
os.remove(audio_file) # Clean up temporary audio file
|
42 |
+
except Exception as e:
|
43 |
+
raise gr.Error(f"Error generating audio: {str(e)}")
|
44 |
|
45 |
+
combined_audio = sum(audio_segments)
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_audio:
|
48 |
+
combined_audio.export(temp_audio.name, format="mp3")
|
49 |
+
temp_audio_path = temp_audio.name
|
50 |
+
|
51 |
+
return temp_audio_path, transcript
|
52 |
|
53 |
except Exception as e:
|
54 |
return None, f"An error occurred: {str(e)}"
|
|
|
56 |
instructions = """
|
57 |
# Podcast Generator
|
58 |
|
59 |
+
Welcome to the Podcast Generator project! This tool creates custom podcast episodes using AI-generated content.
|
60 |
|
61 |
## Features
|
62 |
* Generate podcast scripts from PDF content or web pages
|
63 |
* Convert text to speech for a natural listening experience
|
64 |
+
* Choose the tone of your podcast (Humorous, Casual, or Formal)
|
65 |
* Export episodes as MP3 files
|
66 |
|
67 |
## How to Use
|
68 |
1. Upload a PDF file OR enter a URL (content will be truncated to 2048 tokens if longer)
|
69 |
+
2. Select the desired tone:
|
70 |
+
- Humorous: Expect jokes, puns, and playful banter
|
71 |
+
- Casual: Colloquial language, like a conversation between college students
|
72 |
+
- Formal: Professional podcast style with well-structured arguments
|
73 |
3. Choose the podcast length
|
74 |
4. Click "Generate" to create your podcast
|
75 |
5. Listen to the generated audio and review the transcript
|
76 |
|
77 |
+
Note: This tool uses the LLaMa 3.1 70B model for script generation and gTTS for text-to-speech conversion. The podcast features Sarah (American accent) and Maria (British accent) as hosts.
|
78 |
"""
|
79 |
|
80 |
iface = gr.Interface(
|