File size: 4,700 Bytes
8bfbed4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a24b35
 
8c79f36
 
 
 
 
 
 
 
 
 
 
4bede9c
 
8c79f36
8bfbed4
8c79f36
8bfbed4
8c79f36
 
8bfbed4
 
 
 
 
8c79f36
 
975577a
8bfbed4
975577a
 
 
 
8c79f36
8bfbed4
8c79f36
 
 
a7d9d0c
a25c576
 
 
 
 
a7d9d0c
572791b
975577a
8bfbed4
 
8c79f36
 
8bfbed4
 
8c79f36
8bfbed4
 
 
a25c576
8c79f36
 
 
 
8bfbed4
8c79f36
8bfbed4
 
8c79f36
 
 
8bfbed4
e0e4a15
 
975577a
 
4d4096e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# import streamlit as st
# import os
# from utils.demo import load_video, ctc_decode
# from utils.two_stream_infer import load_model
# import os
# from scripts.extract_lip_coordinates import generate_lip_coordinates
# import options as opt

# st.set_page_config(layout="wide")

# model = load_model()

# st.title("Lipreading final year project Demo")

# st.info(
#     "The inference speed is very slow on Huggingface spaces due to it being processed entirely on CPU ",
#     icon="ℹ️",
# )
# # Generating a list of options or videos
# options = os.listdir(os.path.join("app_input"))
# selected_video = st.selectbox("Choose video", options)

# col1, col2 = st.columns(2)


# with col1:
#     file_path = os.path.join("app_input", selected_video)
#     video_name = selected_video.split(".")[0]
#     os.system(f"ffmpeg -i {file_path} -vcodec libx264 {video_name}.mp4 -y")

#     # Rendering inside of the app
#     video = open(f"{video_name}.mp4", "rb")
#     video_bytes = video.read()
#     st.video(video_bytes)


# with col1, st.spinner("Splitting video into frames"):
#     video, img_p, files = load_video(f"{video_name}.mp4", opt.device)
#     prediction_video = video
#     st.markdown(f"Frames Generated:\n{files}")
#     frames_generated = True
# with col1, st.spinner("Generating Lip Landmark Coordinates"):
#     coordinates = generate_lip_coordinates(f"{video_name}_samples")
#     prediction_coordinates = coordinates
#     st.markdown(f"Coordinates Generated:\n{coordinates}")
#     coordinates_generated = True

# with col2:
#     st.info("Ready to make prediction!")
#     generate = st.button("Generate")
#     if generate:
#         with col2, st.spinner("Generating..."):
#             y = model(
#                 prediction_video[None, ...].to(opt.device),
#                 prediction_coordinates[None, ...].to(opt.device),
#             )
#             txt = ctc_decode(y[0])
#             st.text(txt[-1])
            
# st.info("Author ©️ : wissem karous ")
# st.info("Made with ❤️  ")

###########################

import streamlit as st
import os
from utils.demo import load_video, ctc_decode
from utils.two_stream_infer import load_model
from scripts.extract_lip_coordinates import generate_lip_coordinates
import options as opt

st.set_page_config(layout="wide")

model = load_model()

st.title("Lipreading End-Of-Year Project Demo :")



# Generating a list of options or videos
options = sorted(os.listdir(os.path.join("app_input")))  # Ensure the list is sorted
selected_video = st.selectbox("Choose video", options)

# Find the index of the selected video and calculate the index of the next video
selected_index = options.index(selected_video)
next_video_index = (selected_index + 1) % len(options)  # Ensures looping back to start
next_video = options[next_video_index]

col1, col2 = st.columns(2)

# Function to display video in a column
def display_video(column, video_path, video_name):
    os.system(f"ffmpeg -i {video_path} -vcodec libx264 {video_name}.mp4 -y")
    video = open(f"{video_name}.mp4", "rb")
    video_bytes = video.read()
    column.video(video_bytes)

# Displaying the selected video in the first column
with col1:
    file_path = os.path.join("app_input", selected_video)
    video_name = selected_video.split(".")[0]
    display_video(col1, file_path, video_name)
# Displaying the next video in the second column
with col2:
    st.info("Expected Result !")
    next_file_path = os.path.join("app_input", next_video)
    next_video_name = next_video.split(".")[0]
    display_video(col2, next_file_path, next_video_name )


# Assuming further processing (like generating predictions) is only intended for the first (selected) video
with col1, st.spinner("Processing video..."):
    video, img_p, files = load_video(f"{video_name}.mp4", opt.device)
    coordinates = generate_lip_coordinates(f"{video_name}_samples")
    # Assuming 'frames_generated' and 'coordinates_generated' are used for control flow or further processing
    frames_generated = True
    coordinates_generated = True
    if frames_generated and coordinates_generated:
        st.markdown(f"Frames Generated for {video_name}:\n{files}")
        st.markdown(f"Coordinates Generated for {video_name}:\n{coordinates}")

with col2:
    st.info("Ready to make prediction!")
    generate = st.button("Generate")
    if generate:
        with st.spinner("Generating..."):
            y = model(
                video[None, ...].to(opt.device),
                coordinates[None, ...].to(opt.device),
            )
            txt = ctc_decode(y[0])
            st.text(txt[-1])

st.info("Author ©️ : Wissem Karous ")
st.info("Made with ❤️")
##################