JaMugen commited on
Commit
94fe496
·
1 Parent(s): e382b48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -37
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import subprocess
3
  import sys
 
4
 
5
  def install_libraries():
6
  try:
@@ -23,54 +24,32 @@ def main():
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:
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><th class='translated'>Translated</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>"
57
- f"<td class='translated'>{translated_captions[i]}</td></tr>",
58
- unsafe_allow_html=True,
59
- )
60
 
61
- st.write("</table>", unsafe_allow_html=True)
 
 
62
 
63
- # Navigation buttons
64
- col1, col2, col3 = st.columns([1, 8, 1])
65
- if col1.button("Previous") and start_index > 0:
66
- start_index -= 6
67
- end_index -= 6
68
- st.session_state['start_index'] = start_index
69
 
70
- if col3.button("Next") and end_index < len(captions_list):
71
- start_index += 6
72
- end_index += 6
73
- st.session_state['start_index'] = start_index
74
 
75
  if __name__ == "__main__":
76
  main()
 
1
  import streamlit as st
2
  import subprocess
3
  import sys
4
+ import pandas as pd
5
 
6
  def install_libraries():
7
  try:
 
24
  st.title("Translate YouTube Video to French")
25
 
26
  url = st.text_input("Enter YouTube Video URL")
 
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
+ captions_list = []
33
+ translated_timestamps = []
34
  for line in captions.split("\n"):
35
  if line.strip():
36
  timestamp, text = line.split(" ", 1)
37
+ captions_list.append({"Original Timestamp": timestamp, "Original": text})
 
 
 
 
 
38
 
39
+ for line in translated_captions.split("\n"):
40
+ if line.strip():
41
+ timestamp, text = line.split(" ", 1)
42
+ translated_timestamps.append(timestamp)
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ df = pd.DataFrame(captions_list)
45
+ df['Translated Timestamp'] = translated_timestamps
46
+ df['Translated'] = translated_captions.split("\n")
47
 
48
+ st.write("## Caption Table")
49
+ st.write(df)
 
 
 
 
50
 
51
+ else:
52
+ st.write("Provided URL did not contain captions or translations")
 
 
53
 
54
  if __name__ == "__main__":
55
  main()