Spaces:
Runtime error
Runtime error
Commit 路
68d4040
1
Parent(s): 83a4daf
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,12 +23,26 @@ def generate_audio(text, output_path):
|
|
| 23 |
tts = gTTS(text, lang='es')
|
| 24 |
tts.save(output_path)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def generate_video(audio_path, face_image_path, video_path):
|
| 27 |
command = f"python3 inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face {face_image_path} --audio {audio_path} --outfile {video_path} --nosmooth"
|
| 28 |
process = subprocess.run(command, shell=True, text=True)
|
| 29 |
return process.returncode
|
| 30 |
|
| 31 |
-
# Descargar el archivo wav2lip_gan.pth si no existe
|
| 32 |
checkpoint_path = "checkpoints/wav2lip_gan.pth"
|
| 33 |
if not os.path.exists(checkpoint_path):
|
| 34 |
url = "https://huggingface.co/spaces/salomonsky/tarot/resolve/main/checkpoints/wav2lip_gan.pth"
|
|
@@ -42,7 +56,6 @@ if not os.path.exists(checkpoint_path):
|
|
| 42 |
else:
|
| 43 |
print("Error al descargar el archivo.")
|
| 44 |
|
| 45 |
-
# Crear la carpeta 'temp' si no existe
|
| 46 |
os.makedirs('temp', exist_ok=True)
|
| 47 |
|
| 48 |
def generate_output(name):
|
|
@@ -78,21 +91,17 @@ if st.button("Tirar Cartas de Tarot"):
|
|
| 78 |
st.success("Cartas tiradas exitosamente.")
|
| 79 |
st.write(f"Cartas seleccionadas: {', '.join(cartas)}")
|
| 80 |
st.write(f"Interpretaci贸n de GPT-3: {gpt_output}")
|
| 81 |
-
st.write("Generando
|
| 82 |
|
| 83 |
-
|
| 84 |
video_dir = "videos/"
|
| 85 |
os.makedirs(video_dir, exist_ok=True)
|
| 86 |
-
|
| 87 |
-
# Rutas de los archivos
|
| 88 |
-
audio_path = "temp/temp.wav" # Cambiado el nombre del archivo de audio
|
| 89 |
video_path = f"{video_dir}video.mp4"
|
| 90 |
face_image_path = "face.jpg"
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
-
# Luego, genera el video usando el c贸digo que proporcionaste
|
| 96 |
return_code = generate_video(audio_path, face_image_path, video_path)
|
| 97 |
if return_code != 0:
|
| 98 |
st.error(f"No se pudo generar el video.")
|
|
|
|
| 23 |
tts = gTTS(text, lang='es')
|
| 24 |
tts.save(output_path)
|
| 25 |
|
| 26 |
+
def generate_audio_coqui(text, output_path, api_key):
|
| 27 |
+
url = "https://api.coqui.ai/tts"
|
| 28 |
+
payload = {
|
| 29 |
+
"input_text": text,
|
| 30 |
+
"output_path": output_path,
|
| 31 |
+
"use_model": "coqui/tts/coqui-tts-ljspeech",
|
| 32 |
+
"api_key": api_key
|
| 33 |
+
}
|
| 34 |
+
response = requests.post(url, data=payload)
|
| 35 |
+
|
| 36 |
+
if response.status_code == 200:
|
| 37 |
+
print("Audio generado exitosamente.")
|
| 38 |
+
else:
|
| 39 |
+
print(f"Error al generar el audio: {response.text}")
|
| 40 |
+
|
| 41 |
def generate_video(audio_path, face_image_path, video_path):
|
| 42 |
command = f"python3 inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face {face_image_path} --audio {audio_path} --outfile {video_path} --nosmooth"
|
| 43 |
process = subprocess.run(command, shell=True, text=True)
|
| 44 |
return process.returncode
|
| 45 |
|
|
|
|
| 46 |
checkpoint_path = "checkpoints/wav2lip_gan.pth"
|
| 47 |
if not os.path.exists(checkpoint_path):
|
| 48 |
url = "https://huggingface.co/spaces/salomonsky/tarot/resolve/main/checkpoints/wav2lip_gan.pth"
|
|
|
|
| 56 |
else:
|
| 57 |
print("Error al descargar el archivo.")
|
| 58 |
|
|
|
|
| 59 |
os.makedirs('temp', exist_ok=True)
|
| 60 |
|
| 61 |
def generate_output(name):
|
|
|
|
| 91 |
st.success("Cartas tiradas exitosamente.")
|
| 92 |
st.write(f"Cartas seleccionadas: {', '.join(cartas)}")
|
| 93 |
st.write(f"Interpretaci贸n de GPT-3: {gpt_output}")
|
| 94 |
+
st.write("Generando audio...")
|
| 95 |
|
| 96 |
+
audio_path = "temp/temp.wav"
|
| 97 |
video_dir = "videos/"
|
| 98 |
os.makedirs(video_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
| 99 |
video_path = f"{video_dir}video.mp4"
|
| 100 |
face_image_path = "face.jpg"
|
| 101 |
+
coqui_api_key = "yx9GhszGxbJVZ11kO6BrxAPS5OvZLhQdM01F5BwzLMFjhgApXbeJfFauzBrJIoB6"
|
| 102 |
+
|
| 103 |
+
generate_audio_coqui(gpt_output, audio_path, coqui_api_key)
|
| 104 |
|
|
|
|
| 105 |
return_code = generate_video(audio_path, face_image_path, video_path)
|
| 106 |
if return_code != 0:
|
| 107 |
st.error(f"No se pudo generar el video.")
|