oraculo / app.py
salomonsky's picture
Update app.py
ab14faa
raw
history blame
2.02 kB
import os
import openai
import streamlit as st
import subprocess
from gtts import gTTS
import cv2
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.jpg --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"
st.title("Generador de Hor贸scopos en Video")
name = st.text_input("Nombre", "Escribe tu nick (espera 60 segundos)
birth_date = st.text_input("Fecha de Nacimiento", "DD/MM/AAAA")
if st.button("Generar Video"):
video_path, error_message = generate_output(name, birth_date)
if error_message:
st.error(f"Error: {error_message}")
else:
video_file = open(video_path, "rb").read()
st.video(video_file)