oraculo / app.py
salomonsky's picture
Update app.py
b476686
raw
history blame
2.52 kB
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, date_of_birth, progress=gr.Progress()):
prompt = f"{name}, tu horoscpo y or谩culo astrol贸gico de hoy 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.replace(prompt, "").strip()
if len(response.choices) == 0 or 'text' not in response.choices[0]:
return None, "No se pudo generar el texto."
def _progress(generated, to_generate):
progress((generated, to_generate))
_progress(0, 1)
try:
tts = gTTS(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)
_progress(1, 2)
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 oraculo.jpg --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):
_progress(2, 2)
return output_video_path, None
return None, "No se pudo generar el video"
iface = gr.Interface(
fn=generate_output,
inputs=[
gr.inputs.Textbox(lines=1, label="Nombre", placeholder="Ingresa tu nombre"),
gr.inputs.Textbox(lines=1, label="Fecha de Nacimiento", placeholder="DD/MM/AAAA")
],
outputs=[
gr.outputs.Video(label="Respuesta de Andrea (un minuto aproximadamente)").style(width=256),
#gr.outputs.Textbox(label="Mensaje de error", type="text")
],
title="Or谩culo de Inteligencia Artificial v2.1",
description="Por favor, ingresa tu nombre y fecha de nacimiento.",
layout="vertical", template="default"
)
iface.launch()