Spaces:
Running
Running
salomonsky
commited on
Commit
路
9f11c36
1
Parent(s):
3ee93d5
Delete app1.py
Browse files
app1.py
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import openai
|
3 |
-
import gradio as gr
|
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",
|
16 |
-
prompt=prompt,
|
17 |
-
max_tokens=180,
|
18 |
-
temperature=0.6,
|
19 |
-
n=1,
|
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."
|
27 |
-
|
28 |
-
try:
|
29 |
-
tts = gTTS(personalized_response, lang='es')
|
30 |
-
audio_path = "audio.mp3"
|
31 |
-
tts.save(audio_path)
|
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 checkpoints/wav2lip_gan.pth --face face.jpg --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 |
-
|
51 |
-
def generate_and_display_output(name, birth_date):
|
52 |
-
video_path, error_message = generate_output(name, birth_date)
|
53 |
-
if error_message:
|
54 |
-
print(f"Error: {error_message}")
|
55 |
-
return None, error_message
|
56 |
-
else:
|
57 |
-
return video_path, None
|
58 |
-
|
59 |
-
outputs = [output, error_output]
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|