Spaces:
Running
Running
File size: 2,379 Bytes
a56b407 5c68285 75150b0 05d3cbf 7b6fb4e 5c68285 51f45b8 61d8765 972a12b 9369c96 972a12b 61d8765 972a12b 231d78c 25002fb 972a12b 4b73d5c 05d3cbf b3d0e64 25002fb 61d8765 b3d0e64 a5c316e 4caa659 61d8765 34f0edf 61d8765 05d3cbf 61d8765 b3d0e64 05d3cbf 61d8765 b43a3bd 05d3cbf ad20876 61d8765 5c68285 61d8765 75150b0 61d8765 75150b0 61d8765 77894c7 75150b0 61d8765 75150b0 5d164f2 75150b0 77894c7 38804e8 |
1 2 3 4 5 6 7 8 9 10 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import os
import openai
import gradio as gr
import subprocess
from gtts import gTTS
openai.api_key = os.environ.get("openai_api_key")
def generate_output(name, birth_date):
if not birth_date:
return None, "El campo de fecha de nacimiento es obligatorio."
prompt = f"Tú horóscopo de hoy, si naciste el {birth_date}, es:"
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=180,
temperature=0.6,
n=1,
stop=None,
)
gpt3_output = response.choices[0].text.strip()
personalized_response = f"Tu horóscopo {name} nacido el {birth_date} es: {gpt3_output}"
if len(response.choices) == 0 or 'text' not in response.choices[0]:
return None, "No se pudo generar el texto."
try:
tts = gTTS(personalized_response, lang='es')
audio_path = "audio.mp3"
tts.save(audio_path)
except Exception as e:
return None, f"No se pudo generar el audio: {str(e)}"
video_path = "video.mp4"
command = f"python3 inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face face.png --audio {audio_path} --outfile {video_path} --nosmooth"
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if process.returncode != 0:
error_message = process.stderr
return None, f"No se pudo generar el video: {error_message}"
if os.path.isfile(video_path):
return video_path, None
return None, "No se pudo generar el video"
name_input = gr.inputs.Textbox(lines=1, placeholder="Escribe tu Nombre Completo", label="Nombre")
birth_date_input = gr.inputs.Textbox(lines=1, placeholder="Fecha Nacimiento - DD/MM/AAAA", label="Cumpleaños")
output = gr.outputs.Video(label="Resultado", type="mp4").style(width=350)
error_output = gr.outputs.Textbox(label="Errores")
def generate_and_display_output(name, birth_date):
video_path, error_message = generate_output(name, birth_date)
if error_message:
print(f"Error: {error_message}")
return None, error_message
else:
return video_path, None
outputs = [output, error_output]
iface = gr.Interface(
fn=generate_and_display_output,
inputs=[name_input, birth_date_input],
outputs=outputs,
layout="vertical",
theme="darkdefault"
)
iface.launch()
|