Spaces:
Sleeping
Sleeping
Update Milestone5API.py
Browse files- Milestone5API.py +43 -43
Milestone5API.py
CHANGED
|
@@ -1,48 +1,48 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import re
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
def
|
| 7 |
try:
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
modified_title = yt.title.replace(" ", "_")
|
| 16 |
-
download_path = 'CS370_Milestone5/videos' # Updated path to CS370_Milestone5 repository
|
| 17 |
-
captions_path = 'CS370_Milestone5/captions' # Updated path to CS370_Milestone5 repository
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
file.write(captions)
|
| 38 |
-
|
| 39 |
-
# Delete video file after captions are saved
|
| 40 |
-
os.remove(video_file)
|
| 41 |
-
|
| 42 |
-
return captions
|
| 43 |
else:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import subprocess
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
def install_libraries():
|
| 5 |
try:
|
| 6 |
+
subprocess.check_call(['pip', 'install', 'pytube'])
|
| 7 |
+
subprocess.check_call(['pip', 'install', 'youtube_transcript_api'])
|
| 8 |
+
print("Libraries installed successfully!")
|
| 9 |
+
except subprocess.CalledProcessError as e:
|
| 10 |
+
print("Error during installation:", e)
|
| 11 |
|
| 12 |
+
install_libraries()
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
def main():
|
| 15 |
+
# Importing after ensuring dependencies are installed
|
| 16 |
+
import Milestone5API
|
| 17 |
+
|
| 18 |
+
# Title
|
| 19 |
+
st.title("Translate YouTube Video to French")
|
| 20 |
+
|
| 21 |
+
url = st.text_input("Enter YouTube Video URL")
|
| 22 |
+
captions_list = [] # Initialize empty list for captions
|
| 23 |
+
|
| 24 |
+
if url:
|
| 25 |
+
captions = Milestone5API.download_video_transcript(url)
|
| 26 |
+
if captions:
|
| 27 |
+
# Parse captions from the API response
|
| 28 |
+
for line in captions.split("\n"):
|
| 29 |
+
if line.strip():
|
| 30 |
+
timestamp, text = line.split(" ", 1)
|
| 31 |
+
captions_list.append({"Timestamp": timestamp, "Original": text})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
else:
|
| 33 |
+
st.write("Provided URL did not contain captions")
|
| 34 |
+
|
| 35 |
+
start_index = st.session_state.get('start_index', 0)
|
| 36 |
+
end_index = start_index + 6
|
| 37 |
+
|
| 38 |
+
st.write(
|
| 39 |
+
"<link rel='stylesheet' href='styles.css'>", unsafe_allow_html=True
|
| 40 |
+
)
|
| 41 |
+
st.write(
|
| 42 |
+
"<table><tr><th class='timestamp'>Timestamp</th><th class='original'>Original</th></tr>",
|
| 43 |
+
unsafe_allow_html=True,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
for i in range(start_index, min(end_index, len(captions_list))):
|
| 47 |
+
st.write(
|
| 48 |
+
f"<tr><td class=
|