kya5 commited on
Commit
55db946
1 Parent(s): 9dd924a
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import subprocess
3
+ import sys
4
+ import pandas as pd
5
+
6
+ def install_libraries():
7
+ try:
8
+ subprocess.check_call(['pip', 'install', 'pytube'])
9
+ subprocess.check_call(['pip', 'install', 'youtube_transcript_api'])
10
+ subprocess.check_call(['pip', 'install', 'TTS'])
11
+ subprocess.run(['pip', 'install', 'opencv-python'])
12
+ subprocess.check_call(['pip', 'install', 'moviepy'])
13
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'torch'])
14
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'transformers'])
15
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'sentencepiece'])
16
+ print("Libraries installed successfully!")
17
+ except subprocess.CalledProcessError as e:
18
+ print("Error during installation:", e)
19
+
20
+ install_libraries()
21
+
22
+ def main():
23
+ # Importing after ensuring dependencies are installed
24
+ import translation_api
25
+
26
+ # Title
27
+ st.title("youtube video to japanese")
28
+
29
+ url = st.text_input("enter youtube url")
30
+
31
+ if url:
32
+ captions, t_captions, og_file, t_file, video = translation_api.download_video_transcript(url)
33
+
34
+ if captions and t_captions:
35
+ captions_list = []
36
+ for line in captions.split("\n"):
37
+ if line.strip():
38
+ timestamp, text = line.split(" ", 1)
39
+ captions_list.append({"Timestamp": timestamp, "Original": text})
40
+
41
+ df = pd.DataFrame(captions_list)
42
+ trimmed_captions = [line.split(' ', 2)[-1] for line in t_captions]
43
+ df['Translated'] = trimmed_captions
44
+
45
+ st.write(df[['Timestamp', 'Original','Translated']])
46
+ if video_path:
47
+ st.video(video_path)
48
+ else:
49
+ st.write("no video found")
50
+ else:
51
+ st.write("error 404")
52
+
53
+
54
+ if __name__ == "__main__":
55
+ main()