Spaces:
Running
Running
Commit
·
e371926
1
Parent(s):
2129a76
Update app1.py
Browse files
app1.py
CHANGED
@@ -4,9 +4,12 @@ import gradio as gr
|
|
4 |
import subprocess
|
5 |
from gtts import gTTS
|
6 |
|
7 |
-
openai.api_key = os.environ.get("
|
8 |
|
9 |
def generate_output(name, birth_date):
|
|
|
|
|
|
|
10 |
prompt = f"Tú horóscopo de hoy, si naciste el {birth_date}, es:"
|
11 |
response = openai.Completion.create(
|
12 |
engine="text-davinci-003",
|
@@ -17,7 +20,7 @@ def generate_output(name, birth_date):
|
|
17 |
stop=None,
|
18 |
)
|
19 |
gpt3_output = response.choices[0].text.strip()
|
20 |
-
personalized_response = f"Tu horóscopo {name} es: {gpt3_output}"
|
21 |
|
22 |
if len(response.choices) == 0 or 'text' not in response.choices[0]:
|
23 |
return None, "No se pudo generar el texto."
|
@@ -29,18 +32,19 @@ def generate_output(name, birth_date):
|
|
29 |
except Exception as e:
|
30 |
return None, f"No se pudo generar el audio: {str(e)}"
|
31 |
|
32 |
-
|
33 |
-
|
|
|
34 |
if process.returncode != 0:
|
35 |
-
error_message = process.stderr
|
36 |
return None, f"No se pudo generar el video: {error_message}"
|
37 |
|
38 |
-
if os.path.isfile(
|
39 |
-
return
|
40 |
return None, "No se pudo generar el video"
|
41 |
|
42 |
name_input = gr.inputs.Textbox(lines=1, placeholder="Escribe tu Nombre Completo", label="Nombre")
|
43 |
-
|
44 |
output = gr.outputs.Video(label="Resultado", type="mp4").style(width=350)
|
45 |
error_output = gr.outputs.Textbox(label="Errores")
|
46 |
|
@@ -56,10 +60,10 @@ outputs = [output, error_output]
|
|
56 |
|
57 |
iface = gr.Interface(
|
58 |
fn=generate_and_display_output,
|
59 |
-
inputs=[name_input,
|
60 |
outputs=outputs,
|
61 |
layout="vertical",
|
62 |
theme="darkdefault"
|
63 |
)
|
64 |
|
65 |
-
iface.launch(share=True)
|
|
|
4 |
import subprocess
|
5 |
from gtts import gTTS
|
6 |
|
7 |
+
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
8 |
|
9 |
def generate_output(name, birth_date):
|
10 |
+
if not birth_date:
|
11 |
+
return None, "El campo de fecha de nacimiento es obligatorio."
|
12 |
+
|
13 |
prompt = f"Tú horóscopo de hoy, si naciste el {birth_date}, es:"
|
14 |
response = openai.Completion.create(
|
15 |
engine="text-davinci-003",
|
|
|
20 |
stop=None,
|
21 |
)
|
22 |
gpt3_output = response.choices[0].text.strip()
|
23 |
+
personalized_response = f"Tu horóscopo {name} nacido el {birth_date} es: {gpt3_output}"
|
24 |
|
25 |
if len(response.choices) == 0 or 'text' not in response.choices[0]:
|
26 |
return None, "No se pudo generar el texto."
|
|
|
32 |
except Exception as e:
|
33 |
return None, f"No se pudo generar el audio: {str(e)}"
|
34 |
|
35 |
+
video_path = "video.mp4"
|
36 |
+
command = f"python3 inference.py --checkpoint_path wav2lip_gan.pth --face face2.png --audio {audio_path} --outfile {video_path} --nosmooth"
|
37 |
+
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
38 |
if process.returncode != 0:
|
39 |
+
error_message = process.stderr
|
40 |
return None, f"No se pudo generar el video: {error_message}"
|
41 |
|
42 |
+
if os.path.isfile(video_path):
|
43 |
+
return video_path, None
|
44 |
return None, "No se pudo generar el video"
|
45 |
|
46 |
name_input = gr.inputs.Textbox(lines=1, placeholder="Escribe tu Nombre Completo", label="Nombre")
|
47 |
+
birth_date_input = gr.inputs.Textbox(lines=1, placeholder="Fecha Nacimiento - DD/MM/AAAA", label="Cumpleaños")
|
48 |
output = gr.outputs.Video(label="Resultado", type="mp4").style(width=350)
|
49 |
error_output = gr.outputs.Textbox(label="Errores")
|
50 |
|
|
|
60 |
|
61 |
iface = gr.Interface(
|
62 |
fn=generate_and_display_output,
|
63 |
+
inputs=[name_input, birth_date_input],
|
64 |
outputs=outputs,
|
65 |
layout="vertical",
|
66 |
theme="darkdefault"
|
67 |
)
|
68 |
|
69 |
+
iface.launch(share=True)
|