deven367 commited on
Commit
aadeb1f
1 Parent(s): e27cc7e
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from annotator.utils import *
3
+ st.set_page_config(layout='wide')
4
+ from fastcore.xtras import globtastic
5
+ from pathlib import Path
6
+ import subprocess
7
+
8
+ SRT_PATH = Path('srt')
9
+ if not SRT_PATH.exists(): SRT_PATH.mkdir(exist_ok=True)
10
+
11
+ AUDIO_PATH = Path('./audio')
12
+ if not AUDIO_PATH.exists(): AUDIO_PATH.mkdir(exist_ok=True)
13
+
14
+
15
+ def make_sidebar():
16
+ with st.sidebar:
17
+ st.write('App')
18
+ st.write('YouTube')
19
+
20
+
21
+ def main():
22
+ make_sidebar()
23
+ # st.write('This is it!')
24
+ url = st.text_input('Enter URL for the YT video')
25
+
26
+ if st.button('Generate SRT'):
27
+ audio_src = get_audio(url)
28
+ audio_src = globtastic(AUDIO_PATH, file_glob='*.mp3')[0]
29
+ result = annotate(audio_src)
30
+ df = df_from_result(result)
31
+
32
+ # st.write(result.get('segments', 'wrong key'))
33
+ st.write(df)
34
+ name = Path(audio_src).stem
35
+ s = generate_srt(df)
36
+ with working_directory(SRT_PATH):
37
+ write_srt(s, name)
38
+
39
+ with working_directory(SRT_PATH):
40
+ srt = globtastic('.', file_glob='*.srt')[0]
41
+ with open(srt) as f:
42
+ st.download_button('Download SRT', f, file_name=f'{name}.srt')
43
+
44
+ # subprocess.run(['rm', '-rf', 'audio'])
45
+ # subprocess.run(['rm', '-rf', 'srt'])
46
+
47
+
48
+ if __name__ == "__main__":
49
+ main()