Spaces:
Sleeping
Sleeping
| 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() | |