Spaces:
Sleeping
Sleeping
Commit
路
b43a3bd
1
Parent(s):
435d330
Update app.py
Browse files
app.py
CHANGED
@@ -10,66 +10,50 @@ os.environ["TOKENIZERS_PARALLELISM"] = "true"
|
|
10 |
generator = pipeline('text-generation', model="salomonsky/deepSP")
|
11 |
tokenizer = GPT2Tokenizer.from_pretrained('salomonsky/deepSP')
|
12 |
|
13 |
-
def generate_output(text):
|
14 |
prompt = ""
|
15 |
input_tokens = tokenizer.encode(text, add_special_tokens=False)
|
16 |
input_text = tokenizer.decode(input_tokens)
|
17 |
gpt2_output = generator(input_text, max_length=20, do_sample=True, temperature=0.9)
|
18 |
-
if len(gpt2_output) == 0 or 'generated_text' not in gpt2_output[0]:
|
19 |
-
return None, "No se pudo generar el texto."
|
20 |
-
|
21 |
generated_text = gpt2_output[0]['generated_text']
|
22 |
generated_text = generated_text.replace(input_text, "").strip()
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
audio.export(audio_path, format="wav")
|
31 |
-
print("Archivo de audio generado:", audio_path)
|
32 |
-
except Exception as e:
|
33 |
-
return None, f"No se pudo generar el audio: {str(e)}"
|
34 |
-
|
35 |
-
face_image_path = "face.jpg"
|
36 |
-
if not os.path.isfile(face_image_path):
|
37 |
-
return None, "No se encontr贸 el archivo de imagen de cara."
|
38 |
-
|
39 |
-
print("Archivo de imagen de cara:", face_image_path)
|
40 |
|
41 |
-
command = f"python3 inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face {
|
42 |
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
43 |
if process.returncode != 0:
|
44 |
-
error_message = process.stderr.decode()
|
45 |
-
return None,
|
46 |
|
47 |
output_video_path = "video.mp4"
|
48 |
-
print("Archivo de video generado:", output_video_path)
|
49 |
-
|
50 |
os.remove(temp_audio_path)
|
51 |
|
52 |
if os.path.isfile(output_video_path):
|
53 |
return output_video_path, None
|
54 |
|
55 |
-
return None, "No se pudo generar el video
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
return gr.outputs.Textbox(text=error_message, placeholder="Error")
|
60 |
-
else:
|
61 |
-
return None
|
62 |
|
63 |
iface = gr.Interface(
|
64 |
fn=generate_output,
|
65 |
-
inputs=
|
|
|
|
|
|
|
66 |
outputs=[
|
67 |
gr.outputs.Video(label="Respuesta de Andrea (un minuto aproximadamente)"),
|
68 |
-
gr.outputs.Textbox(label="Mensaje de error", type="
|
69 |
],
|
70 |
title="Andrea - Humanoid Chatbot IA 2023(c)",
|
71 |
-
|
72 |
-
error_message=error_message_fn
|
73 |
)
|
74 |
|
75 |
iface.launch()
|
|
|
10 |
generator = pipeline('text-generation', model="salomonsky/deepSP")
|
11 |
tokenizer = GPT2Tokenizer.from_pretrained('salomonsky/deepSP')
|
12 |
|
13 |
+
def generate_output(text, image):
|
14 |
prompt = ""
|
15 |
input_tokens = tokenizer.encode(text, add_special_tokens=False)
|
16 |
input_text = tokenizer.decode(input_tokens)
|
17 |
gpt2_output = generator(input_text, max_length=20, do_sample=True, temperature=0.9)
|
|
|
|
|
|
|
18 |
generated_text = gpt2_output[0]['generated_text']
|
19 |
generated_text = generated_text.replace(input_text, "").strip()
|
20 |
|
21 |
+
tts = gTTS(generated_text, lang='es')
|
22 |
+
temp_audio_path = "temp_audio.mp3"
|
23 |
+
tts.save(temp_audio_path)
|
24 |
+
audio_path = "audio.wav"
|
25 |
+
audio = AudioSegment.from_mp3(temp_audio_path)
|
26 |
+
audio.export(audio_path, format="wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
command = f"python3 inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face {image} --audio audio.wav --outfile video.mp4 --nosmooth"
|
29 |
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
30 |
if process.returncode != 0:
|
31 |
+
error_message = process.stderr.decode("utf-8")
|
32 |
+
return None, error_message
|
33 |
|
34 |
output_video_path = "video.mp4"
|
|
|
|
|
35 |
os.remove(temp_audio_path)
|
36 |
|
37 |
if os.path.isfile(output_video_path):
|
38 |
return output_video_path, None
|
39 |
|
40 |
+
return None, "No se pudo generar el video"
|
41 |
|
42 |
+
choices = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg"]
|
43 |
+
thumbnail_width = "50px"
|
|
|
|
|
|
|
44 |
|
45 |
iface = gr.Interface(
|
46 |
fn=generate_output,
|
47 |
+
inputs=[
|
48 |
+
gr.inputs.Textbox(lines=1, placeholder='Escribe tu nombre para presentarte con Andrea...'),
|
49 |
+
gr.inputs.Radio(choices, label="Selecciona una imagen:")
|
50 |
+
],
|
51 |
outputs=[
|
52 |
gr.outputs.Video(label="Respuesta de Andrea (un minuto aproximadamente)"),
|
53 |
+
gr.outputs.Textbox(label="Mensaje de error", type="auto")
|
54 |
],
|
55 |
title="Andrea - Humanoid Chatbot IA 2023(c)",
|
56 |
+
thumbnail_width=thumbnail_width
|
|
|
57 |
)
|
58 |
|
59 |
iface.launch()
|