-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstreamlit.py
81 lines (65 loc) · 2.46 KB
/
streamlit.py
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
import requests
from time import sleep
from utils import send_to_assembly
from utils import dubbing
from utils import create_zip
import streamlit as st
with st.sidebar:
tk_assembly = st.text_input("TOKEN ASSEMBLY AI", type="password")
tk_api_audio = st.text_input("TOKEN API AUDIO", type="password")
speed = st.slider("Select the voice speed", 50, 120, 80)
voice = st.selectbox("Which voice you want?", ("liam", "sonia", "aria", "ryan"))
st.title(
""" Dubbing AI
End-to-end dubbing video system.
"""
)
p_name = st.text_input("Insert a name for this Project")
uploaded_file = st.file_uploader("Choose a video")
if uploaded_file is not None:
bytes_data = uploaded_file.getvalue()
with open(f'{uploaded_file.name}', 'wb') as wfile:
wfile.write(bytes_data)
st.video(bytes_data)
if st.button("Dubbing"):
if not tk_assembly or not tk_api_audio :
st.error('Both Tokens must be provided')
st.stop()
with st.spinner("Waiting for subtitle generation..."):
headers, sub_endpoint = send_to_assembly(bytes_data, auth=tk_assembly)
polling_response = requests.get(sub_endpoint, headers=headers)
while polling_response.json()["status"] != "completed":
sleep(5)
print("Transcript processing ...")
try:
polling_response = requests.get(sub_endpoint, headers=headers)
except:
print("Failed transcription")
st.success("Subtitle generated, now I am dubbing your video")
response_srt = requests.get(f"{sub_endpoint}/srt", headers=headers)
subtitle = response_srt.text.split("\n")
with open(f"{p_name}.srt", "w") as _file:
_file.write(response_srt.text)
with st.spinner("Waiting for dubbing..."):
final_video, audio_file = dubbing(
p_name,
subtitle,
uploaded_file.name,
speed=speed,
voice=voice,
auth=tk_api_audio,
)
video_file = open(f"{final_video}", "rb")
video_bytes = video_file.read()
st.success("Your video is ready!")
st.video(video_bytes)
create_zip(p_name, f'{p_name}.srt',
final_video, audio_file)
st.write("Click here to download the generated files")
with open(f"{p_name}.zip", "rb") as fp:
btn = st.download_button(
label="Download ZIP",
data=fp,
file_name="mydubbedvideo.zip",
mime="application/zip"
)