kamau1 commited on
Commit
4e21277
Β·
verified Β·
1 Parent(s): 71d0a3a

Update pages/03_πŸ“_Upload_Video_File_and_Transcript.py

Browse files
pages/03_πŸ“_Upload_Video_File_and_Transcript.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from streamlit_lottie import st_lottie
3
  from utils import write_vtt, write_srt
 
4
  import ffmpeg
5
  import requests
6
  from typing import Iterator
@@ -10,7 +11,10 @@ import pathlib
10
  import os
11
 
12
 
13
- st.set_page_config(page_title="Auto Subtitled Video Generator", page_icon=":movie_camera:", layout="wide")
 
 
 
14
 
15
  # Define a function that we can use to load lottie files from a link.
16
  @st.cache(allow_output_mutation=True)
@@ -36,7 +40,7 @@ with col1:
36
 
37
  with col2:
38
  st.write("""
39
- ## Auto Subtitled Video Generator
40
  ##### ➠ Upload a video file and a transcript as .srt or .vtt file and get a video with subtitles.
41
  ##### ➠ Processing time will increase as the video length increases. """)
42
 
@@ -62,6 +66,32 @@ def split_video_audio(uploaded_file):
62
  audio = ffmpeg.output(audio, f"{save_dir}/output.wav", acodec="pcm_s16le", ac=1, ar="16k")
63
  ffmpeg.run(audio, overwrite_output=True)
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  def main():
67
  uploaded_video = st.file_uploader("Upload Video File", type=["mp4", "avi", "mov", "mkv"])
 
1
  import streamlit as st
2
  from streamlit_lottie import st_lottie
3
  from utils import write_vtt, write_srt
4
+ from flores200_codes import flores_codes
5
  import ffmpeg
6
  import requests
7
  from typing import Iterator
 
11
  import os
12
 
13
 
14
+ st.set_page_config(page_title="Captions", page_icon=":movie_camera:", layout="wide")
15
+
16
+ # Sema Translator
17
+ Public_Url = 'https://lewiskimaru-helloworld.hf.space' #endpoint
18
 
19
  # Define a function that we can use to load lottie files from a link.
20
  @st.cache(allow_output_mutation=True)
 
40
 
41
  with col2:
42
  st.write("""
43
+ ## Sema Captions
44
  ##### ➠ Upload a video file and a transcript as .srt or .vtt file and get a video with subtitles.
45
  ##### ➠ Processing time will increase as the video length increases. """)
46
 
 
66
  audio = ffmpeg.output(audio, f"{save_dir}/output.wav", acodec="pcm_s16le", ac=1, ar="16k")
67
  ffmpeg.run(audio, overwrite_output=True)
68
 
69
+ def translate(userinput, target_lang, source_lang=None):
70
+ if source_lang:
71
+ url = f"{Public_Url}/translate_enter/"
72
+ data = {
73
+ "userinput": userinput,
74
+ "source_lang": source_lang,
75
+ "target_lang": target_lang,
76
+ }
77
+ response = requests.post(url, json=data)
78
+ result = response.json()
79
+ print(type(result))
80
+ source_lange = source_lang
81
+ translation = result['translated_text']
82
+
83
+ else:
84
+ url = f"{Public_Url}/translate_detect/"
85
+ data = {
86
+ "userinput": userinput,
87
+ "target_lang": target_lang,
88
+ }
89
+
90
+ response = requests.post(url, json=data)
91
+ result = response.json()
92
+ source_lange = result['source_language']
93
+ translation = result['translated_text']
94
+ return source_lange, translation
95
 
96
  def main():
97
  uploaded_video = st.file_uploader("Upload Video File", type=["mp4", "avi", "mov", "mkv"])