Spaces:
Running
Running
Commit
路
05d3cbf
1
Parent(s):
fa81432
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
+
from gtts import gTTS
|
5 |
+
from pydub import AudioSegment
|
6 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer, pipeline
|
7 |
+
|
8 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "true"
|
9 |
+
generator = pipeline('text-generation', model="salomonsky/deepSP")
|
10 |
+
|
11 |
+
def generate_output(text):
|
12 |
+
prompt = ""
|
13 |
+
input_text = prompt + ""
|
14 |
+
gpt2_output = generator(input_text, max_length=20, do_sample=True, temperature=0.9)
|
15 |
+
generated_text = gpt2_output[0]['generated_text']
|
16 |
+
generated_text = generated_text.replace(input_text, "").strip()
|
17 |
+
|
18 |
+
tts = gTTS(generated_text, lang='es')
|
19 |
+
temp_audio_path = "temp_audio.mp3"
|
20 |
+
tts.save(temp_audio_path)
|
21 |
+
audio_path = "audio.wav"
|
22 |
+
audio = AudioSegment.from_mp3(temp_audio_path)
|
23 |
+
audio.export(audio_path, format="wav")
|
24 |
+
|
25 |
+
command = f"python3 inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face face.jpg --audio audio.wav --outfile video.mp4 --nosmooth"
|
26 |
+
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
27 |
+
if process.returncode != 0:
|
28 |
+
return None
|
29 |
+
|
30 |
+
output_video_path = "video.mp4"
|
31 |
+
os.remove(temp_audio_path)
|
32 |
+
|
33 |
+
if os.path.isfile(output_video_path):
|
34 |
+
return output_video_path
|
35 |
+
|
36 |
+
return None
|
37 |
+
|
38 |
+
iface = gr.Interface(
|
39 |
+
fn=generate_output,
|
40 |
+
inputs=gr.inputs.Textbox(lines=1, placeholder='Escribe tu nombre para presentarte con Andrea...'),
|
41 |
+
outputs=[
|
42 |
+
gr.outputs.Video(label="Respuesta de Andrea (un minuto aproximadamente)")
|
43 |
+
],
|
44 |
+
title="Andrea - Humanoid Chatbot IA 2023(c)",
|
45 |
+
)
|
46 |
+
|
47 |
+
iface.launch()
|