File size: 1,932 Bytes
55db946
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import subprocess
import sys
import pandas as pd

def install_libraries():
    try:
        subprocess.check_call(['pip', 'install', 'pytube'])
        subprocess.check_call(['pip', 'install', 'youtube_transcript_api'])
        subprocess.check_call(['pip', 'install', 'TTS'])
        subprocess.run(['pip', 'install', 'opencv-python'])
        subprocess.check_call(['pip', 'install', 'moviepy'])
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'torch'])
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'transformers'])
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'sentencepiece']) 
        print("Libraries installed successfully!")
    except subprocess.CalledProcessError as e:
        print("Error during installation:", e)

install_libraries()

def main():
    # Importing after ensuring dependencies are installed
    import translation_api
    
    # Title 
    st.title("youtube video to japanese")
    
    url = st.text_input("enter youtube url")
    
    if url:
        captions, t_captions, og_file, t_file, video = translation_api.download_video_transcript(url)
  
        if captions and t_captions:
            captions_list = []
            for line in captions.split("\n"):
                if line.strip():
                    timestamp, text = line.split(" ", 1)
                    captions_list.append({"Timestamp": timestamp, "Original": text})

            df = pd.DataFrame(captions_list)
            trimmed_captions = [line.split(' ', 2)[-1] for line in t_captions]
            df['Translated'] = trimmed_captions
            
            st.write(df[['Timestamp', 'Original','Translated']])
            if video_path:
                st.video(video_path)
            else:
                st.write("no video found")
        else:
            st.write("error 404")

    
if __name__ == "__main__":
    main()