Update app.py
Browse files
app.py
CHANGED
@@ -10,10 +10,6 @@ import os
|
|
10 |
import requests
|
11 |
from tqdm import tqdm
|
12 |
|
13 |
-
# Initialize Gemini AI
|
14 |
-
genai.configure(api_key='YOUR_GEMINI_API_KEY')
|
15 |
-
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
16 |
-
|
17 |
# Function to download the model file
|
18 |
def download_model(url, filename):
|
19 |
response = requests.get(url, stream=True)
|
@@ -67,7 +63,10 @@ filtered_state_dict = {k: v for k, v in state_dict.items() if k in model_dict}
|
|
67 |
e2tts.load_state_dict(filtered_state_dict, strict=False)
|
68 |
e2tts.eval()
|
69 |
|
70 |
-
def generate_podcast_script(content, duration):
|
|
|
|
|
|
|
71 |
prompt = f"""
|
72 |
Create a podcast script for two people discussing the following content:
|
73 |
{content}
|
@@ -96,8 +95,8 @@ def text_to_speech(text, speaker_id):
|
|
96 |
|
97 |
return sampled.cpu().numpy()
|
98 |
|
99 |
-
def create_podcast(content, duration, voice1, voice2):
|
100 |
-
script = generate_podcast_script(content, duration)
|
101 |
lines = script.split('\n')
|
102 |
audio_segments = []
|
103 |
|
@@ -113,11 +112,11 @@ def create_podcast(content, duration, voice1, voice2):
|
|
113 |
podcast_audio = np.concatenate(audio_segments)
|
114 |
return (22050, podcast_audio) # Assuming 22050 Hz sample rate
|
115 |
|
116 |
-
def gradio_interface(content, duration, voice1, voice2):
|
117 |
-
script = generate_podcast_script(content, duration)
|
118 |
return script
|
119 |
|
120 |
-
def render_podcast(script, voice1, voice2):
|
121 |
lines = script.split('\n')
|
122 |
audio_segments = []
|
123 |
|
@@ -136,6 +135,8 @@ def render_podcast(script, voice1, voice2):
|
|
136 |
with gr.Blocks() as demo:
|
137 |
gr.Markdown("# AI Podcast Generator")
|
138 |
|
|
|
|
|
139 |
with gr.Row():
|
140 |
content_input = gr.Textbox(label="Paste your content or upload a document")
|
141 |
document_upload = gr.File(label="Upload Document")
|
@@ -152,7 +153,7 @@ with gr.Blocks() as demo:
|
|
152 |
render_btn = gr.Button("Render Podcast")
|
153 |
audio_output = gr.Audio(label="Generated Podcast")
|
154 |
|
155 |
-
generate_btn.click(gradio_interface, inputs=[content_input, duration, voice1_upload, voice2_upload], outputs=script_output)
|
156 |
-
render_btn.click(render_podcast, inputs=[script_output, voice1_upload, voice2_upload], outputs=audio_output)
|
157 |
|
158 |
demo.launch()
|
|
|
10 |
import requests
|
11 |
from tqdm import tqdm
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# Function to download the model file
|
14 |
def download_model(url, filename):
|
15 |
response = requests.get(url, stream=True)
|
|
|
63 |
e2tts.load_state_dict(filtered_state_dict, strict=False)
|
64 |
e2tts.eval()
|
65 |
|
66 |
+
def generate_podcast_script(api_key, content, duration):
|
67 |
+
genai.configure(api_key=api_key)
|
68 |
+
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
69 |
+
|
70 |
prompt = f"""
|
71 |
Create a podcast script for two people discussing the following content:
|
72 |
{content}
|
|
|
95 |
|
96 |
return sampled.cpu().numpy()
|
97 |
|
98 |
+
def create_podcast(api_key, content, duration, voice1, voice2):
|
99 |
+
script = generate_podcast_script(api_key, content, duration)
|
100 |
lines = script.split('\n')
|
101 |
audio_segments = []
|
102 |
|
|
|
112 |
podcast_audio = np.concatenate(audio_segments)
|
113 |
return (22050, podcast_audio) # Assuming 22050 Hz sample rate
|
114 |
|
115 |
+
def gradio_interface(api_key, content, duration, voice1, voice2):
|
116 |
+
script = generate_podcast_script(api_key, content, duration)
|
117 |
return script
|
118 |
|
119 |
+
def render_podcast(api_key, script, voice1, voice2):
|
120 |
lines = script.split('\n')
|
121 |
audio_segments = []
|
122 |
|
|
|
135 |
with gr.Blocks() as demo:
|
136 |
gr.Markdown("# AI Podcast Generator")
|
137 |
|
138 |
+
api_key_input = gr.Textbox(label="Enter your Gemini API Key", type="password")
|
139 |
+
|
140 |
with gr.Row():
|
141 |
content_input = gr.Textbox(label="Paste your content or upload a document")
|
142 |
document_upload = gr.File(label="Upload Document")
|
|
|
153 |
render_btn = gr.Button("Render Podcast")
|
154 |
audio_output = gr.Audio(label="Generated Podcast")
|
155 |
|
156 |
+
generate_btn.click(gradio_interface, inputs=[api_key_input, content_input, duration, voice1_upload, voice2_upload], outputs=script_output)
|
157 |
+
render_btn.click(render_podcast, inputs=[api_key_input, script_output, voice1_upload, voice2_upload], outputs=audio_output)
|
158 |
|
159 |
demo.launch()
|