Spaces:
Sleeping
Sleeping
Update 01_🎥_Input_YouTube_Link.py
Browse files- 01_🎥_Input_YouTube_Link.py +35 -5
01_🎥_Input_YouTube_Link.py
CHANGED
@@ -11,8 +11,9 @@ from io import StringIO
|
|
11 |
from utils import write_vtt, write_srt
|
12 |
import ffmpeg
|
13 |
from languages import LANGUAGES
|
|
|
14 |
|
15 |
-
st.set_page_config(page_title="
|
16 |
|
17 |
# Define a function that we can use to load lottie files from a link.
|
18 |
@st.cache()
|
@@ -29,10 +30,10 @@ with col1:
|
|
29 |
|
30 |
with col2:
|
31 |
st.write("""
|
32 |
-
##
|
33 |
##### Input a YouTube video link and get a video with subtitles.
|
34 |
###### ➠ If you want to transcribe the video in its original language, select the task as "Transcribe"
|
35 |
-
###### ➠ If you want to translate the subtitles to
|
36 |
###### I recommend starting with the base model and then experimenting with the larger models, the small and medium models often work well. """)
|
37 |
|
38 |
|
@@ -116,6 +117,32 @@ def get_language_code(language):
|
|
116 |
else:
|
117 |
raise ValueError("Language not supported")
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
def generate_subtitled_video(video, audio, transcript):
|
121 |
video_file = ffmpeg.input(video)
|
@@ -192,7 +219,10 @@ def main():
|
|
192 |
data=video_with_subs,
|
193 |
file_name=f"{title} with subtitles.mp4")
|
194 |
elif task == "Translate":
|
195 |
-
|
|
|
|
|
|
|
196 |
author, title, description, thumbnail, length, views = populate_metadata(link)
|
197 |
results = inference(link, loaded_model, task)
|
198 |
video = download_video(link)
|
@@ -255,4 +285,4 @@ def main():
|
|
255 |
|
256 |
if __name__ == "__main__":
|
257 |
main()
|
258 |
-
st.markdown("###### Made with :heart: by [@BatuhanYılmaz](https://github.com/BatuhanYilmaz26) [![this is an image link](https://i.imgur.com/thJhzOO.png)](https://www.buymeacoffee.com/batuhanylmz)")
|
|
|
11 |
from utils import write_vtt, write_srt
|
12 |
import ffmpeg
|
13 |
from languages import LANGUAGES
|
14 |
+
from flores200_codes import flores_codes
|
15 |
|
16 |
+
st.set_page_config(page_title="Sema Titles", page_icon="🎦", layout="wide")
|
17 |
|
18 |
# Define a function that we can use to load lottie files from a link.
|
19 |
@st.cache()
|
|
|
30 |
|
31 |
with col2:
|
32 |
st.write("""
|
33 |
+
## Sema-Titles
|
34 |
##### Input a YouTube video link and get a video with subtitles.
|
35 |
###### ➠ If you want to transcribe the video in its original language, select the task as "Transcribe"
|
36 |
+
###### ➠ If you want to translate the subtitles from English to any of the 200 supported languages, select the task as "Translate"
|
37 |
###### I recommend starting with the base model and then experimenting with the larger models, the small and medium models often work well. """)
|
38 |
|
39 |
|
|
|
117 |
else:
|
118 |
raise ValueError("Language not supported")
|
119 |
|
120 |
+
def translate(userinput, target_lang, source_lang=None):
|
121 |
+
if source_lang:
|
122 |
+
url = f"{Public_Url}/translate_enter/"
|
123 |
+
data = {
|
124 |
+
"userinput": userinput,
|
125 |
+
"source_lang": source_lang,
|
126 |
+
"target_lang": target_lang,
|
127 |
+
}
|
128 |
+
response = requests.post(url, json=data)
|
129 |
+
result = response.json()
|
130 |
+
print(type(result))
|
131 |
+
source_lange = source_lang
|
132 |
+
translation = result['translated_text']
|
133 |
+
|
134 |
+
else:
|
135 |
+
url = f"{Public_Url}/translate_detect/"
|
136 |
+
data = {
|
137 |
+
"userinput": userinput,
|
138 |
+
"target_lang": target_lang,
|
139 |
+
}
|
140 |
+
|
141 |
+
response = requests.post(url, json=data)
|
142 |
+
result = response.json()
|
143 |
+
source_lange = result['source_language']
|
144 |
+
translation = result['translated_text']
|
145 |
+
return source_lange, translation
|
146 |
|
147 |
def generate_subtitled_video(video, audio, transcript):
|
148 |
video_file = ffmpeg.input(video)
|
|
|
219 |
data=video_with_subs,
|
220 |
file_name=f"{title} with subtitles.mp4")
|
221 |
elif task == "Translate":
|
222 |
+
default_language = "French"
|
223 |
+
target = st.selectbox("Select Language", list(languages.keys()), index=list(languages.keys()).index(default_language))
|
224 |
+
target_code = languages[selected_language]
|
225 |
+
if st.button("Translate"):
|
226 |
author, title, description, thumbnail, length, views = populate_metadata(link)
|
227 |
results = inference(link, loaded_model, task)
|
228 |
video = download_video(link)
|
|
|
285 |
|
286 |
if __name__ == "__main__":
|
287 |
main()
|
288 |
+
#st.markdown("###### Made with :heart: by [@BatuhanYılmaz](https://github.com/BatuhanYilmaz26) [![this is an image link](https://i.imgur.com/thJhzOO.png)](https://www.buymeacoffee.com/batuhanylmz)")
|