JaMugen commited on
Commit
e4d3a3c
·
1 Parent(s): be90082

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -17,8 +17,7 @@ install_libraries()
17
  def main():
18
  # Importing after ensuring dependencies are installed
19
  import Milestone5API
20
-
21
- # Title
22
  st.title("Translate YouTube Video to French")
23
 
24
  url = st.text_input("Enter YouTube Video URL")
@@ -26,22 +25,25 @@ def main():
26
 
27
  if url:
28
  captions, translated_captions, original_file, translated_file = Milestone5API.download_video_transcript(url)
 
 
 
 
 
 
 
 
29
 
30
  if translated_captions:
31
- # Parse translated captions from the API response
32
- for line in translated_captions:
33
- if line.strip().startswith("fr:"):
34
- _, timestamp, text = line.partition(": ")[2].split(" ", 2)
35
- captions_list.append({"Timestamp": timestamp, "Translated": text})
 
 
 
36
 
37
- if captions_list:
38
- st.write("## Translated Captions")
39
- st.write("Timestamp - Translated Text")
40
- for caption in captions_list:
41
- st.write(f"{caption['Timestamp']} - {caption['Translated']}")
42
- else:
43
- st.write("No translated captions available")
44
-
45
  start_index = st.session_state.get('start_index', 0)
46
  end_index = start_index + 6
47
 
@@ -51,14 +53,15 @@ def main():
51
  css = f.read()
52
  st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
53
  st.write(
54
- "<table><tr><th class='timestamp'>Timestamp</th><th class='original'>Original</th></tr>",
55
  unsafe_allow_html=True,
56
  )
57
 
58
- for i in range(start_index, min(end_index, len(captions_list))):
59
  st.write(
60
- f"<tr><td class='timestamp'>{captions_list[i]['Timestamp']}</td>"
61
- f"<td class='original'>{captions_list[i]['Original']}</td></tr>",
 
62
  unsafe_allow_html=True,
63
  )
64
 
@@ -71,10 +74,10 @@ def main():
71
  end_index -= 6
72
  st.session_state['start_index'] = start_index
73
 
74
- if col3.button("Next") and end_index < len(captions_list):
75
  start_index += 6
76
  end_index += 6
77
  st.session_state['start_index'] = start_index
78
 
79
  if __name__ == "__main__":
80
- main()
 
17
  def main():
18
  # Importing after ensuring dependencies are installed
19
  import Milestone5API
20
+ # Title
 
21
  st.title("Translate YouTube Video to French")
22
 
23
  url = st.text_input("Enter YouTube Video URL")
 
25
 
26
  if url:
27
  captions, translated_captions, original_file, translated_file = Milestone5API.download_video_transcript(url)
28
+
29
+ if captions:
30
+ # Parse captions from the API response for original captions
31
+ for line in captions.split("\n"):
32
+ if line.strip():
33
+ lang, timestamp, text = line.split(" ", 2)
34
+ if lang == "en:" or lang == "fr:":
35
+ captions_list.append({"Timestamp": timestamp, "Language": lang, "Text": text})
36
 
37
  if translated_captions:
38
+ # Parse translated captions
39
+ translated_text = translated_captions.split("\n")
40
+ for i, line in enumerate(translated_text):
41
+ lang, timestamp, text = line.split(" ", 2)
42
+ if lang == "fr:" or lang == "en:": # Considering lines starting with "fr:" or "en:"
43
+ captions_list[i]["Translated"] = text
44
+
45
+ df = pd.DataFrame(captions_list)
46
 
 
 
 
 
 
 
 
 
47
  start_index = st.session_state.get('start_index', 0)
48
  end_index = start_index + 6
49
 
 
53
  css = f.read()
54
  st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
55
  st.write(
56
+ "<table><tr><th class='timestamp'>Timestamp</th><th class='original'>Original</th><th class='translated'>Translated</th></tr>",
57
  unsafe_allow_html=True,
58
  )
59
 
60
+ for i in range(start_index, min(end_index, len(df))):
61
  st.write(
62
+ f"<tr><td class='timestamp'>{df['Timestamp'][i]}</td>"
63
+ f"<td class='{df['Language'][i]}'>{df['Text'][i]}</td>"
64
+ f"<td class='{df['Language'][i]}'>{df['Translated'][i]}</td></tr>",
65
  unsafe_allow_html=True,
66
  )
67
 
 
74
  end_index -= 6
75
  st.session_state['start_index'] = start_index
76
 
77
+ if col3.button("Next") and end_index < len(df):
78
  start_index += 6
79
  end_index += 6
80
  st.session_state['start_index'] = start_index
81
 
82
  if __name__ == "__main__":
83
+ main()