Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import subprocess
|
| 3 |
-
import pandas as pd
|
| 4 |
|
| 5 |
def install_libraries():
|
| 6 |
try:
|
|
@@ -13,15 +12,19 @@ def install_libraries():
|
|
| 13 |
install_libraries()
|
| 14 |
|
| 15 |
def main():
|
|
|
|
| 16 |
import Milestone5API
|
|
|
|
|
|
|
| 17 |
st.title("Translate YouTube Video to French")
|
| 18 |
|
| 19 |
url = st.text_input("Enter YouTube Video URL")
|
| 20 |
-
captions_list = []
|
| 21 |
|
| 22 |
if url:
|
| 23 |
captions = Milestone5API.download_video_transcript(url)
|
| 24 |
if captions:
|
|
|
|
| 25 |
for line in captions.split("\n"):
|
| 26 |
if line.strip():
|
| 27 |
timestamp, text = line.split(" ", 1)
|
|
@@ -32,26 +35,36 @@ def main():
|
|
| 32 |
start_index = st.session_state.get('start_index', 0)
|
| 33 |
end_index = start_index + 6
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
st.write("## Caption Table")
|
| 38 |
-
|
| 39 |
with open("styles.css", "r") as f:
|
| 40 |
css = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
st.
|
| 43 |
-
|
| 44 |
-
st.table(df[['Timestamp', 'Original']].iloc[start_index:end_index])
|
| 45 |
|
|
|
|
| 46 |
col1, col2, col3 = st.columns([1, 8, 1])
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import subprocess
|
|
|
|
| 3 |
|
| 4 |
def install_libraries():
|
| 5 |
try:
|
|
|
|
| 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)
|
|
|
|
| 35 |
start_index = st.session_state.get('start_index', 0)
|
| 36 |
end_index = start_index + 6
|
| 37 |
|
| 38 |
+
# Display caption table with CSS class names
|
|
|
|
| 39 |
st.write("## Caption Table")
|
|
|
|
| 40 |
with open("styles.css", "r") as f:
|
| 41 |
css = f.read()
|
| 42 |
+
st.markdown(f"<style>{css}</style>", unsafe_allow_html=True))
|
| 43 |
+
st.write(
|
| 44 |
+
"<table><tr><th class='timestamp'>Timestamp</th><th class='original'>Original</th></tr>",
|
| 45 |
+
unsafe_allow_html=True,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
for i in range(start_index, min(end_index, len(captions_list))):
|
| 49 |
+
st.write(
|
| 50 |
+
f"<tr><td class='timestamp'>{captions_list[i]['Timestamp']}</td>"
|
| 51 |
+
f"<td class='original'>{captions_list[i]['Original']}</td></tr>",
|
| 52 |
+
unsafe_allow_html=True,
|
| 53 |
+
)
|
| 54 |
|
| 55 |
+
st.write("</table>", unsafe_allow_html=True)
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# Navigation buttons
|
| 58 |
col1, col2, col3 = st.columns([1, 8, 1])
|
| 59 |
+
if col1.button("Previous") and start_index > 0:
|
| 60 |
+
start_index -= 6
|
| 61 |
+
end_index -= 6
|
| 62 |
+
st.session_state['start_index'] = start_index
|
| 63 |
+
|
| 64 |
+
if col3.button("Next") and end_index < len(captions_list):
|
| 65 |
+
start_index += 6
|
| 66 |
+
end_index += 6
|
| 67 |
+
st.session_state['start_index'] = start_index
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
main()
|