Spaces:
Runtime error
Runtime error
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#! /usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
|
4 |
+
# Copyright 2023 Imperial College London (Pingchuan Ma)
|
5 |
+
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
6 |
+
import os
|
7 |
+
import datetime
|
8 |
+
import subprocess
|
9 |
+
import gradio as gr
|
10 |
+
from pipelines.pipeline import InferencePipeline
|
11 |
+
|
12 |
+
FFMPEG_COMMAND = "-loglevel error -y -r 25 -pix_fmt yuv420p -f mp4"
|
13 |
+
pipelines = {
|
14 |
+
"VSR": InferencePipeline("./configs/LRS3_V_WER19.1.ini", device="cuda:0", face_track=True, detector="retinaface"),
|
15 |
+
"VSR(fast)": InferencePipeline("./configs/LRS3_V_WER19.1.ini", device="cuda:0", face_track=True, detector="mediapipe"),
|
16 |
+
"ASR": InferencePipeline("./configs/LRS3_A_WER1.0.ini", device="cuda:0", face_track=True, detector="retinaface"),
|
17 |
+
"AVSR": InferencePipeline("./configs/LRS3_AV_WER0.9.ini", device="cuda:0", face_track=True, detector="retinaface"),
|
18 |
+
"AVSR(fast)": InferencePipeline("./configs/LRS3_AV_WER0.9.ini", device="cuda:0", face_track=True, detector="mediapipe")
|
19 |
+
}
|
20 |
+
print("Step 0. Model has been loaded.")
|
21 |
+
|
22 |
+
def fn(pipeline_type, filename):
|
23 |
+
directory = "./tmp_video"
|
24 |
+
if not os.path.exists(directory):
|
25 |
+
os.makedirs(directory)
|
26 |
+
now = datetime.datetime.now()
|
27 |
+
timestamp = now.strftime("%Y-%m-%d_%H-%M-%S")
|
28 |
+
dst_filename = f"{directory}/file_{timestamp}.mp4"
|
29 |
+
command_string = f"ffmpeg -i {filename} {FFMPEG_COMMAND} {dst_filename}"
|
30 |
+
print("Step 0. Video has been uploaded.")
|
31 |
+
os.system(command_string)
|
32 |
+
selected_pipeline_instance = pipelines[pipeline_type]
|
33 |
+
print("Step 1. Video has been converted.")
|
34 |
+
landmarks = selected_pipeline_instance.process_landmarks(dst_filename, landmarks_filename=None)
|
35 |
+
print("Step 2. Landmarks have been detected.")
|
36 |
+
data = selected_pipeline_instance.dataloader.load_data(dst_filename, landmarks)
|
37 |
+
print("Step 3. Data has been preprocessed.")
|
38 |
+
transcript = selected_pipeline_instance.model.infer(data)
|
39 |
+
print("Step 4. Inference has been done.")
|
40 |
+
print(f"transcript: {transcript}")
|
41 |
+
return transcript
|
42 |
+
|
43 |
+
demo = gr.Blocks()
|
44 |
+
|
45 |
+
with demo:
|
46 |
+
gr.HTML(
|
47 |
+
"""
|
48 |
+
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
49 |
+
<div
|
50 |
+
style="
|
51 |
+
display: inline-flex;
|
52 |
+
align-items: center;
|
53 |
+
gap: 0.8rem;
|
54 |
+
font-size: 1.75rem;
|
55 |
+
"
|
56 |
+
>
|
57 |
+
<h1 style="font-weight: 900; margin-bottom: 7px; line-height: normal;">
|
58 |
+
Auto-AVSR: Audio-Visual Speech Recognition with Automatic Labels
|
59 |
+
</h1>
|
60 |
+
</div>
|
61 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
62 |
+
</p>
|
63 |
+
</div>
|
64 |
+
"""
|
65 |
+
)
|
66 |
+
dropdown_list = gr.inputs.Dropdown(["VSR", "ASR", "AVSR", "VSR(fast)", "AVSR(fast)"], label="model")
|
67 |
+
video_file = gr.Video(label="INPUT VIDEO", include_audio=True)
|
68 |
+
text = gr.Textbox(label="PREDICTION")
|
69 |
+
btn = gr.Button("Submit").style(full_width=True)
|
70 |
+
|
71 |
+
btn.click(fn, inputs=[dropdown_list, video_file], outputs=text)
|
72 |
+
|
73 |
+
with gr.Accordion("Additional information", open=False):
|
74 |
+
gr.HTML(
|
75 |
+
"""
|
76 |
+
<div class="acknowledgments">
|
77 |
+
<p> We share this demo only for non-commercial purposes. </p>
|
78 |
+
</div>
|
79 |
+
"""
|
80 |
+
)
|
81 |
+
|
82 |
+
demo.launch(share=True)
|