JaMugen commited on
Commit
8dcf37f
·
1 Parent(s): 03efdb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -42
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 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
70
- end_index -= 6
71
- st.session_state['start_index'] = start_index
72
 
73
- if col3.button("Next") and end_index < len(captions_list):
74
- start_index += 6
75
- end_index += 6
76
- st.session_state['start_index'] = start_index
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()