Spaces:
Runtime error
Runtime error
Commit
·
b9d657b
1
Parent(s):
8fa13bc
fix meloTTS
Browse files
app.py
CHANGED
|
@@ -117,6 +117,7 @@ def generate_podcast(
|
|
| 117 |
raise gr.Error(
|
| 118 |
"The total content is too long. Please ensure the combined text from PDFs and URL is fewer than ~100,000 characters."
|
| 119 |
)
|
|
|
|
| 120 |
|
| 121 |
# Modify the system prompt based on the user input
|
| 122 |
modified_system_prompt = SYSTEM_PROMPT
|
|
@@ -156,6 +157,9 @@ def generate_podcast(
|
|
| 156 |
transcript += speaker + "\n\n"
|
| 157 |
total_characters += len(line.text)
|
| 158 |
|
|
|
|
|
|
|
|
|
|
| 159 |
# Get audio file path
|
| 160 |
audio_file_path = generate_podcast_audio(
|
| 161 |
line.text, line.speaker, LANGUAGE_MAPPING[language], use_advanced_audio
|
|
|
|
| 117 |
raise gr.Error(
|
| 118 |
"The total content is too long. Please ensure the combined text from PDFs and URL is fewer than ~100,000 characters."
|
| 119 |
)
|
| 120 |
+
|
| 121 |
|
| 122 |
# Modify the system prompt based on the user input
|
| 123 |
modified_system_prompt = SYSTEM_PROMPT
|
|
|
|
| 157 |
transcript += speaker + "\n\n"
|
| 158 |
total_characters += len(line.text)
|
| 159 |
|
| 160 |
+
if not use_advanced_audio:
|
| 161 |
+
LANGUAGE_MAPPING = MELO_TTS_LANGUAGE_MAPPING
|
| 162 |
+
|
| 163 |
# Get audio file path
|
| 164 |
audio_file_path = generate_podcast_audio(
|
| 165 |
line.text, line.speaker, LANGUAGE_MAPPING[language], use_advanced_audio
|
utils.py
CHANGED
|
@@ -9,6 +9,7 @@ Functions:
|
|
| 9 |
|
| 10 |
import os
|
| 11 |
import requests
|
|
|
|
| 12 |
from gradio_client import Client
|
| 13 |
from openai import OpenAI
|
| 14 |
from pydantic import ValidationError
|
|
@@ -102,11 +103,17 @@ def generate_podcast_audio(text: str, speaker: str, language: str, use_advanced_
|
|
| 102 |
speed = 1.1
|
| 103 |
|
| 104 |
# Generate audio
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
import os
|
| 11 |
import requests
|
| 12 |
+
import time
|
| 13 |
from gradio_client import Client
|
| 14 |
from openai import OpenAI
|
| 15 |
from pydantic import ValidationError
|
|
|
|
| 103 |
speed = 1.1
|
| 104 |
|
| 105 |
# Generate audio
|
| 106 |
+
for attempt in range(3):
|
| 107 |
+
try:
|
| 108 |
+
result = hf_client.predict(
|
| 109 |
+
text=text,
|
| 110 |
+
language=language,
|
| 111 |
+
speaker=accent,
|
| 112 |
+
speed=speed,
|
| 113 |
+
api_name="/synthesize",
|
| 114 |
+
)
|
| 115 |
+
return result
|
| 116 |
+
except Exception as e:
|
| 117 |
+
if attempt == 2: # Last attempt
|
| 118 |
+
raise # Re-raise the last exception if all attempts fail
|
| 119 |
+
time.sleep(1) # Wait for 1 second before retrying
|