Update app.py
Browse files
app.py
CHANGED
@@ -1,89 +1,49 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
-
import requests
|
5 |
-
from bs4 import BeautifulSoup
|
6 |
-
from groq import Groq
|
7 |
-
from gtts import gTTS
|
8 |
from pydub import AudioSegment
|
9 |
import os
|
10 |
-
import io
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
{"role": "user", "content": prompt}
|
39 |
-
],
|
40 |
-
model="llama-3.1-70b-versatile", # Using LLaMa 3.1 70B model
|
41 |
-
max_tokens=1000,
|
42 |
-
temperature=0.7
|
43 |
-
)
|
44 |
-
return response.choices[0].message.content
|
45 |
-
|
46 |
-
def text_to_speech(script):
|
47 |
-
lines = script.split('\n')
|
48 |
-
audio_segments = []
|
49 |
-
for line in lines:
|
50 |
-
if line.startswith("Man:"):
|
51 |
-
tts = gTTS(line[4:], lang='en', tld='co.uk')
|
52 |
-
elif line.startswith("Woman:"):
|
53 |
-
tts = gTTS(line[6:], lang='en', tld='com.au')
|
54 |
-
else:
|
55 |
-
continue
|
56 |
-
buffer = io.BytesIO()
|
57 |
-
tts.write_to_fp(buffer)
|
58 |
-
buffer.seek(0)
|
59 |
-
audio_segments.append(AudioSegment.from_mp3(buffer))
|
60 |
-
|
61 |
-
final_audio = sum(audio_segments)
|
62 |
-
final_audio = final_audio[:300000] # Trim to 5 minutes (300,000 ms)
|
63 |
-
buffer = io.BytesIO()
|
64 |
-
final_audio.export(buffer, format="mp3")
|
65 |
-
buffer.seek(0)
|
66 |
-
return buffer
|
67 |
-
|
68 |
-
def generate_podcast(file_or_url):
|
69 |
-
text = extract_text(file_or_url)
|
70 |
-
if not text:
|
71 |
-
return None, "Failed to extract text. Please check your input."
|
72 |
-
script = generate_podcast_script(text)
|
73 |
-
audio_file = text_to_speech(script)
|
74 |
-
return audio_file, script
|
75 |
|
76 |
iface = gr.Interface(
|
77 |
fn=generate_podcast,
|
78 |
inputs=[
|
79 |
-
gr.File(label="Upload PDF
|
80 |
-
gr.
|
|
|
81 |
],
|
82 |
outputs=[
|
83 |
gr.Audio(label="Generated Podcast"),
|
84 |
-
gr.
|
85 |
],
|
86 |
-
title="Custom NotebookLM-type Podcast Generator
|
|
|
87 |
)
|
88 |
|
89 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from utils import generate_script, generate_audio
|
3 |
+
from prompts import SYSTEM_PROMPT
|
|
|
|
|
|
|
|
|
4 |
from pydub import AudioSegment
|
5 |
import os
|
|
|
6 |
|
7 |
+
def generate_podcast(file, tone, length):
|
8 |
+
# Extract text from PDF
|
9 |
+
# Generate script using generate_script function
|
10 |
+
# Generate audio for each dialogue item
|
11 |
+
# Combine audio segments
|
12 |
+
# Return audio file and transcript
|
13 |
+
|
14 |
+
# Gradio interface
|
15 |
+
instructions = """
|
16 |
+
# Podcast Generator
|
17 |
+
|
18 |
+
Welcome to the Podcast Generator project! This tool allows you to create custom podcast episodes using AI-generated content.
|
19 |
+
|
20 |
+
## Features
|
21 |
+
* Generate podcast scripts on any topic
|
22 |
+
* Convert text to speech for a natural listening experience
|
23 |
+
* Choose the tone of your podcast
|
24 |
+
* Export episodes as MP3 files
|
25 |
+
|
26 |
+
## How to Use
|
27 |
+
1. Upload a PDF file (max 2048 tokens)
|
28 |
+
2. Select the desired tone (humorous, casual, formal)
|
29 |
+
3. Choose the podcast length
|
30 |
+
4. Click "Generate" to create your podcast
|
31 |
+
5. Listen to the generated audio and review the transcript
|
32 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
iface = gr.Interface(
|
35 |
fn=generate_podcast,
|
36 |
inputs=[
|
37 |
+
gr.File(label="Upload PDF file"),
|
38 |
+
gr.Radio(["humorous", "casual", "formal"], label="Select podcast tone", value="casual"),
|
39 |
+
gr.Radio(["Short (1-2 min)", "Medium (3-5 min)"], label="Podcast length", value="Medium (3-5 min)")
|
40 |
],
|
41 |
outputs=[
|
42 |
gr.Audio(label="Generated Podcast"),
|
43 |
+
gr.Markdown(label="Transcript")
|
44 |
],
|
45 |
+
title="Custom NotebookLM-type Podcast Generator",
|
46 |
+
description=instructions
|
47 |
)
|
48 |
|
49 |
iface.launch()
|