Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
| 3 |
|
|
@@ -7,53 +8,62 @@ def install_libraries():
|
|
| 7 |
subprocess.check_call(['pip', 'install', 'youtube_transcript_api'])
|
| 8 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'torch'])
|
| 9 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'transformers'])
|
| 10 |
-
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'sentencepiece'])
|
| 11 |
print("Libraries installed successfully!")
|
| 12 |
except subprocess.CalledProcessError as e:
|
| 13 |
print("Error during installation:", e)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
install_libraries()
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
import Milestone5API
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def download_transcripts(url):
|
| 24 |
-
return Milestone5API.download_video_transcript(url)
|
| 25 |
-
|
| 26 |
st.title("Translate YouTube Video to French")
|
|
|
|
| 27 |
url = st.text_input("Enter YouTube Video URL")
|
| 28 |
-
|
|
|
|
| 29 |
if url:
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
captions, translated_captions, _, _ = cached_data
|
| 33 |
-
|
| 34 |
if captions and translated_captions:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
for line, translated_line in zip(captions, translated_captions):
|
| 39 |
-
lang, timestamp, text = line.split(" ", 2)
|
| 40 |
lang_trans, _, text_trans = translated_line.split(" ", 2)
|
| 41 |
if lang.startswith("en:") or lang.startswith("fr:") and lang_trans.startswith("en:") or lang_trans.startswith("fr:"):
|
| 42 |
-
captions_list.append({
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
start_index = st.session_state.get('start_index', 0)
|
| 46 |
end_index = start_index + 6
|
| 47 |
|
|
|
|
| 48 |
st.write("## Caption Table")
|
| 49 |
-
df = pd.DataFrame(captions_list[start_index:end_index], columns=["Timestamp", "Original"])
|
| 50 |
-
df['Translated'] = translated_text[start_index:end_index]
|
| 51 |
-
|
| 52 |
with open("styles.css", "r") as f:
|
| 53 |
css = f.read()
|
| 54 |
st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
|
| 55 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
|
|
|
| 57 |
col1, col2, col3 = st.columns([1, 8, 1])
|
| 58 |
if col1.button("Previous") and start_index > 0:
|
| 59 |
start_index -= 6
|
|
@@ -66,4 +76,4 @@ def install_and_download(url):
|
|
| 66 |
st.session_state['start_index'] = start_index
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
-
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
|
|
|
|
| 8 |
subprocess.check_call(['pip', 'install', 'youtube_transcript_api'])
|
| 9 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'torch'])
|
| 10 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'transformers'])
|
| 11 |
+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'sentencepiece'])
|
| 12 |
print("Libraries installed successfully!")
|
| 13 |
except subprocess.CalledProcessError as e:
|
| 14 |
print("Error during installation:", e)
|
| 15 |
|
| 16 |
+
install_libraries()
|
|
|
|
| 17 |
|
| 18 |
+
def main():
|
| 19 |
+
# Importing after ensuring dependencies are installed
|
| 20 |
import Milestone5API
|
| 21 |
+
|
| 22 |
+
# Title
|
|
|
|
|
|
|
|
|
|
| 23 |
st.title("Translate YouTube Video to French")
|
| 24 |
+
|
| 25 |
url = st.text_input("Enter YouTube Video URL")
|
| 26 |
+
captions_list = [] # Initialize empty list for captions
|
| 27 |
+
|
| 28 |
if url:
|
| 29 |
+
captions, translated_captions, original_file, translated_file = Milestone5API.download_video_transcript(url)
|
| 30 |
+
|
|
|
|
|
|
|
| 31 |
if captions and translated_captions:
|
| 32 |
+
# Parse captions and translated captions
|
| 33 |
+
for original_line, translated_line in zip(captions, translated_captions):
|
| 34 |
+
lang, timestamp, text = original_line.split(" ", 2)
|
|
|
|
|
|
|
| 35 |
lang_trans, _, text_trans = translated_line.split(" ", 2)
|
| 36 |
if lang.startswith("en:") or lang.startswith("fr:") and lang_trans.startswith("en:") or lang_trans.startswith("fr:"):
|
| 37 |
+
captions_list.append({
|
| 38 |
+
"Timestamp": timestamp[4:],
|
| 39 |
+
"Original": text,
|
| 40 |
+
"Translated": text_trans
|
| 41 |
+
})
|
| 42 |
|
| 43 |
start_index = st.session_state.get('start_index', 0)
|
| 44 |
end_index = start_index + 6
|
| 45 |
|
| 46 |
+
# Display caption table with new columns
|
| 47 |
st.write("## Caption Table")
|
|
|
|
|
|
|
|
|
|
| 48 |
with open("styles.css", "r") as f:
|
| 49 |
css = f.read()
|
| 50 |
st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
|
| 51 |
+
st.write(
|
| 52 |
+
"<table><tr><th class='timestamp'>Timestamp</th><th class='original'>Original</th><th class='translated'>Translated</th></tr>",
|
| 53 |
+
unsafe_allow_html=True,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
for i in range(start_index, min(end_index, len(captions_list))):
|
| 57 |
+
st.write(
|
| 58 |
+
f"<tr><td class='timestamp'>{captions_list[i]['Timestamp']}</td>"
|
| 59 |
+
f"<td class='original'>{captions_list[i]['Original']}</td>"
|
| 60 |
+
f"<td class='translated'>{captions_list[i]['Translated']}</td></tr>",
|
| 61 |
+
unsafe_allow_html=True,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
st.write("</table>", unsafe_allow_html=True)
|
| 65 |
|
| 66 |
+
# Navigation buttons
|
| 67 |
col1, col2, col3 = st.columns([1, 8, 1])
|
| 68 |
if col1.button("Previous") and start_index > 0:
|
| 69 |
start_index -= 6
|
|
|
|
| 76 |
st.session_state['start_index'] = start_index
|
| 77 |
|
| 78 |
if __name__ == "__main__":
|
| 79 |
+
main()
|