Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ class PodcastGenerator:
|
|
30 |
def __init__(self):
|
31 |
pass
|
32 |
|
33 |
-
async def generate_script(self, prompt: str, language: str,
|
34 |
example = """
|
35 |
{
|
36 |
"topic": "AGI",
|
@@ -209,14 +209,14 @@ Return the result strictly as a JSON object in the format:
|
|
209 |
|
210 |
return output_filename
|
211 |
|
212 |
-
async def generate_podcast(self, input_text: str, language: str, speaker1: str, speaker2: str,
|
213 |
try:
|
214 |
if progress:
|
215 |
progress(0.1, "Starting podcast generation...")
|
216 |
|
217 |
# Set overall timeout for the entire process
|
218 |
return await asyncio.wait_for(
|
219 |
-
self._generate_podcast_internal(input_text, language, speaker1, speaker2,
|
220 |
timeout=600 # 10 minutes total timeout
|
221 |
)
|
222 |
except asyncio.TimeoutError:
|
@@ -224,11 +224,11 @@ Return the result strictly as a JSON object in the format:
|
|
224 |
except Exception as e:
|
225 |
raise Exception(f"Error generating podcast: {str(e)}")
|
226 |
|
227 |
-
async def _generate_podcast_internal(self, input_text: str, language: str, speaker1: str, speaker2: str,
|
228 |
if progress:
|
229 |
progress(0.2, "Generating podcast script...")
|
230 |
|
231 |
-
podcast_json = await self.generate_script(input_text, language,
|
232 |
|
233 |
if progress:
|
234 |
progress(0.5, "Converting text to speech...")
|
@@ -281,7 +281,7 @@ Return the result strictly as a JSON object in the format:
|
|
281 |
combined_audio = await self.combine_audio_files(audio_files, progress)
|
282 |
return combined_audio
|
283 |
|
284 |
-
async def process_input(input_text: str, input_file, language: str, speaker1: str, speaker2: str,
|
285 |
start_time = time.time()
|
286 |
|
287 |
voice_names = {
|
@@ -305,7 +305,7 @@ async def process_input(input_text: str, input_file, language: str, speaker1: st
|
|
305 |
api_key = "" # No API key needed for local model
|
306 |
|
307 |
podcast_generator = PodcastGenerator()
|
308 |
-
podcast = await podcast_generator.generate_podcast(input_text, language, speaker1, speaker2,
|
309 |
|
310 |
end_time = time.time()
|
311 |
print(f"Total podcast generation time: {end_time - start_time:.2f} seconds")
|
@@ -322,7 +322,7 @@ async def process_input(input_text: str, input_file, language: str, speaker1: st
|
|
322 |
raise Exception(f"Error: {error_msg}")
|
323 |
|
324 |
# Gradio UI
|
325 |
-
def generate_podcast_gradio(input_text, input_file, language, speaker1, speaker2,
|
326 |
# Handle the file if uploaded
|
327 |
file_obj = None
|
328 |
if input_file is not None:
|
@@ -339,7 +339,6 @@ def generate_podcast_gradio(input_text, input_file, language, speaker1, speaker2
|
|
339 |
language,
|
340 |
speaker1,
|
341 |
speaker2,
|
342 |
-
api_key,
|
343 |
progress_callback
|
344 |
))
|
345 |
|
|
|
30 |
def __init__(self):
|
31 |
pass
|
32 |
|
33 |
+
async def generate_script(self, prompt: str, language: str, file_obj=None, progress=None) -> Dict:
|
34 |
example = """
|
35 |
{
|
36 |
"topic": "AGI",
|
|
|
209 |
|
210 |
return output_filename
|
211 |
|
212 |
+
async def generate_podcast(self, input_text: str, language: str, speaker1: str, speaker2: str, file_obj=None, progress=None) -> str:
|
213 |
try:
|
214 |
if progress:
|
215 |
progress(0.1, "Starting podcast generation...")
|
216 |
|
217 |
# Set overall timeout for the entire process
|
218 |
return await asyncio.wait_for(
|
219 |
+
self._generate_podcast_internal(input_text, language, speaker1, speaker2, file_obj, progress),
|
220 |
timeout=600 # 10 minutes total timeout
|
221 |
)
|
222 |
except asyncio.TimeoutError:
|
|
|
224 |
except Exception as e:
|
225 |
raise Exception(f"Error generating podcast: {str(e)}")
|
226 |
|
227 |
+
async def _generate_podcast_internal(self, input_text: str, language: str, speaker1: str, speaker2: str, file_obj=None, progress=None) -> str:
|
228 |
if progress:
|
229 |
progress(0.2, "Generating podcast script...")
|
230 |
|
231 |
+
podcast_json = await self.generate_script(input_text, language, file_obj, progress)
|
232 |
|
233 |
if progress:
|
234 |
progress(0.5, "Converting text to speech...")
|
|
|
281 |
combined_audio = await self.combine_audio_files(audio_files, progress)
|
282 |
return combined_audio
|
283 |
|
284 |
+
async def process_input(input_text: str, input_file, language: str, speaker1: str, speaker2: str, progress=None) -> str:
|
285 |
start_time = time.time()
|
286 |
|
287 |
voice_names = {
|
|
|
305 |
api_key = "" # No API key needed for local model
|
306 |
|
307 |
podcast_generator = PodcastGenerator()
|
308 |
+
podcast = await podcast_generator.generate_podcast(input_text, language, speaker1, speaker2, input_file, progress)
|
309 |
|
310 |
end_time = time.time()
|
311 |
print(f"Total podcast generation time: {end_time - start_time:.2f} seconds")
|
|
|
322 |
raise Exception(f"Error: {error_msg}")
|
323 |
|
324 |
# Gradio UI
|
325 |
+
def generate_podcast_gradio(input_text, input_file, language, speaker1, speaker2, progress=gr.Progress()):
|
326 |
# Handle the file if uploaded
|
327 |
file_obj = None
|
328 |
if input_file is not None:
|
|
|
339 |
language,
|
340 |
speaker1,
|
341 |
speaker2,
|
|
|
342 |
progress_callback
|
343 |
))
|
344 |
|