File size: 2,073 Bytes
03efdb0
f40b1d5
53d347a
94fe496
e382b48
f40b1d5
 
 
 
4e2556a
b05155b
918b61c
6bcdc45
2eb2ca3
03efdb0
f40b1d5
 
 
 
03efdb0
7178a38
03efdb0
 
3449301
03efdb0
 
cd60d27
03efdb0
cd60d27
03efdb0
b91e7bc
86741dd
dd57dd7
94fe496
 
8dcf37f
 
 
c919e72
e878da1
94fe496
81185be
 
 
 
1fbad0f
86741dd
 
 
94fe496
 
cd60d27
284ce8a
cd60d27
e382b48
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 Milestone5API
    
    # Title 
    st.title("Translate YouTube Video to French")
    
    url = st.text_input("Enter YouTube Video URL")
    
    if url:
        captions, translated_captions, original_file, translated_file, video_path = Milestone5API.download_video_transcript(url)
  
        if captions and translated_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_translated_captions = [line.split(' ', 2)[-1] for line in translated_captions]
            df['Translated'] = trimmed_translated_captions
            
            st.write(df[['Timestamp', 'Original','Translated']])
            if video_path:
                st.video(video_path)
            else:
                st.write("No video found for the given URL")
        else:
            st.write("Provided URL did not contain captions or translations")

    
if __name__ == "__main__":
    main()