Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
-
|
| 5 |
def install_libraries():
|
| 6 |
try:
|
| 7 |
subprocess.check_call(['pip', 'install', 'pytube'])
|
|
@@ -27,53 +27,49 @@ def main():
|
|
| 27 |
|
| 28 |
if url:
|
| 29 |
captions, translated_captions, original_file, translated_file = Milestone5API.download_video_transcript(url)
|
| 30 |
-
|
| 31 |
-
if captions
|
| 32 |
-
# Parse captions
|
| 33 |
-
for
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
start_index = st.session_state.get('start_index', 0)
|
| 44 |
-
end_index = start_index + 6
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
st.write(
|
| 52 |
-
"<
|
|
|
|
| 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 |
-
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
|
| 78 |
if __name__ == "__main__":
|
| 79 |
-
main()
|
|
|
|
| 1 |
+
User
|
| 2 |
import streamlit as st
|
| 3 |
import subprocess
|
| 4 |
import sys
|
|
|
|
| 5 |
def install_libraries():
|
| 6 |
try:
|
| 7 |
subprocess.check_call(['pip', 'install', 'pytube'])
|
|
|
|
| 27 |
|
| 28 |
if url:
|
| 29 |
captions, translated_captions, original_file, translated_file = Milestone5API.download_video_transcript(url)
|
| 30 |
+
print (translated_text)
|
| 31 |
+
if captions:
|
| 32 |
+
# Parse captions from the API response
|
| 33 |
+
for line in captions.split("\n"):
|
| 34 |
+
if line.strip():
|
| 35 |
+
timestamp, text = line.split(" ", 1)
|
| 36 |
+
captions_list.append({"Timestamp": timestamp, "Original": text})
|
| 37 |
+
else:
|
| 38 |
+
st.write("Provided URL did not contain captions")
|
| 39 |
+
|
| 40 |
+
start_index = st.session_state.get('start_index', 0)
|
| 41 |
+
end_index = start_index + 6
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Display caption table with CSS class names
|
| 44 |
+
st.write("## Caption Table")
|
| 45 |
+
with open("styles.css", "r") as f:
|
| 46 |
+
css = f.read()
|
| 47 |
+
st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
|
| 48 |
+
st.write(
|
| 49 |
+
"<table><tr><th class='timestamp'>Timestamp</th><th class='original'>Original</th></tr>",
|
| 50 |
+
unsafe_allow_html=True,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
for i in range(start_index, min(end_index, len(captions_list))):
|
| 54 |
st.write(
|
| 55 |
+
f"<tr><td class='timestamp'>{captions_list[i]['Timestamp']}</td>"
|
| 56 |
+
f"<td class='original'>{captions_list[i]['Original']}</td></tr>",
|
| 57 |
unsafe_allow_html=True,
|
| 58 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
st.write("</table>", unsafe_allow_html=True)
|
| 61 |
|
| 62 |
+
# Navigation buttons
|
| 63 |
+
col1, col2, col3 = st.columns([1, 8, 1])
|
| 64 |
+
if col1.button("Previous") and start_index > 0:
|
| 65 |
+
start_index -= 6
|
| 66 |
+
end_index -= 6
|
| 67 |
+
st.session_state['start_index'] = start_index
|
| 68 |
|
| 69 |
+
if col3.button("Next") and end_index < len(captions_list):
|
| 70 |
+
start_index += 6
|
| 71 |
+
end_index += 6
|
| 72 |
+
st.session_state['start_index'] = start_index
|
| 73 |
|
| 74 |
if __name__ == "__main__":
|
| 75 |
+
main()
|