CS370-M5 / app.py
kya5's picture
app.py
55db946
raw
history blame contribute delete
No virus
1.93 kB
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()