Spaces:
Sleeping
Sleeping
File size: 2,810 Bytes
dc60352 5c68285 75150b0 05d3cbf 7b6fb4e 5c68285 51f45b8 296785f 5c68285 296785f 972a12b 9369c96 972a12b 296785f 972a12b 4b73d5c 05d3cbf b3d0e64 296785f b3d0e64 161fa06 b3d0e64 a5c316e 4caa659 ec6b0ee 05d3cbf b43a3bd b3d0e64 05d3cbf 4caa659 05d3cbf 4caa659 b43a3bd 05d3cbf 5c68285 296785f 5c68285 296785f 75150b0 77894c7 75150b0 296785f 75150b0 296785f 75150b0 5c68285 75150b0 77894c7 75150b0 |
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 71 72 |
import os
import openai
import gradio as gr
import subprocess
from gtts import gTTS
from pydub import AudioSegment
openai.api_key = os.environ.get("openai_api_key")
def generate_output(name, horoscope_type, birth_date):
image_filename = f"{horoscope_type.lower()}.jpg" # Construye el nombre de la imagen
prompt = f"Tu hor贸scopo {horoscope_type} y or谩culo de hoy para {name} nacido 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()
generated_text = gpt3_output.strip()
if len(response.choices) == 0 or 'text' not in response.choices[0]:
return None, "No se pudo generar el texto."
try:
tts = gTTS(f"Tu hor贸scopo {horoscope_type} para {name} nacido el {birth_date} es: {generated_text}", lang='es')
temp_audio_path = "temp_audio.mp3"
tts.save(temp_audio_path)
audio_path = "audio.wav"
audio = AudioSegment.from_mp3(temp_audio_path)
audio.export(audio_path, format="wav")
print("Archivo de audio generado:", audio_path)
except Exception as e:
return None, f"No se pudo generar el audio: {str(e)}"
command = f"python3 inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face {image_filename} --audio audio.wav --outfile video.mp4 --nosmooth"
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if process.returncode != 0:
error_message = process.stderr.decode("utf-8")
return None, f"No se pudo generar el video: {error_message}"
output_video_path = "video.mp4"
os.remove(temp_audio_path)
if os.path.isfile(output_video_path):
return output_video_path, None
return None, "No se pudo generar el video"
name_input = gr.inputs.Textbox(lines=1, placeholder="Escribe tu Nombre Completo")
horoscope_type_radio = gr.inputs.Radio(["Griego", "Egipcio", "Maya", "Chino", "Celta", "Hindu"], label="Tipo de Hor贸scopo")
birth_date_input = gr.inputs.Date(label="Fecha de Nacimiento")
output = gr.outputs.Video(label=None)
def generate_and_display_output(name, horoscope_type, birth_date):
video_path, error_message = generate_output(name, horoscope_type, birth_date)
if error_message:
print(f"Error: {error_message}")
else:
return video_path
iface = gr.Interface(
fn=generate_and_display_output,
inputs=[name_input, horoscope_type_radio, birth_date_input],
outputs=output,
title="Hor贸scopo con Inteligencia Artificial v2.1",
description="Ingresa tu nombre, tipo de hor贸scopo y fecha de nacimiento.",
layout="vertical",
theme="dark"
)
iface.launch() |