vitaliy-sharandin
commited on
Commit
•
b3c41ef
1
Parent(s):
9110e67
Update app.py
Browse files
app.py
CHANGED
@@ -267,10 +267,47 @@ def translate_video(video_path, youtube_link, target_language, speaker_model):
|
|
267 |
if youtube_link:
|
268 |
video_path = download_youtube_video(youtube_link)
|
269 |
dubbed_video = video_translation(video_path, target_language, speaker_model, HF_TOKEN, DEEPL_TOKEN)
|
|
|
270 |
except Exception as e:
|
271 |
print(f"An error occurred: {e}")
|
272 |
raise e
|
273 |
-
return gr.components.Video(dubbed_video)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
|
275 |
def clear_inputs():
|
276 |
return None, "", None, None
|
@@ -287,12 +324,16 @@ css = """
|
|
287 |
"""
|
288 |
|
289 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
|
|
|
|
|
290 |
gr.Markdown("<h1 style='text-align: center;'>🌐AI Video Translation</h2>")
|
291 |
gr.Markdown("<h3 style='text-align: center;'>Currently supported languages are: English, Polish, Ukrainian, and Russian</h3>")
|
292 |
|
293 |
with gr.Row():
|
294 |
with gr.Column(elem_classes=["column-frame"]):
|
295 |
gr.Markdown("<h2 style='text-align: center;'>Inputs</h3>")
|
|
|
296 |
video = gr.Video(label="Upload a video file")
|
297 |
gr.Markdown("<h3 style='text-align: center;'>OR</h3>")
|
298 |
youtube_link = gr.Textbox(label="Paste YouTube link")
|
@@ -312,7 +353,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
312 |
translate_btn.click(
|
313 |
fn=translate_video,
|
314 |
inputs=[video, youtube_link, target_language, speaker_model],
|
315 |
-
outputs=output_video
|
316 |
)
|
317 |
|
318 |
clear_btn.click(
|
|
|
267 |
if youtube_link:
|
268 |
video_path = download_youtube_video(youtube_link)
|
269 |
dubbed_video = video_translation(video_path, target_language, speaker_model, HF_TOKEN, DEEPL_TOKEN)
|
270 |
+
translation_limit_info = translation_limit()
|
271 |
except Exception as e:
|
272 |
print(f"An error occurred: {e}")
|
273 |
raise e
|
274 |
+
return translation_limit_info, gr.components.Video(dubbed_video)
|
275 |
+
|
276 |
+
|
277 |
+
def translation_limit():
|
278 |
+
translator = deepl.Translator(DEEPL_TOKEN)
|
279 |
+
usage = translator.get_usage()
|
280 |
+
if usage.character.valid:
|
281 |
+
characters_used = usage.character.count
|
282 |
+
minutes_used = int(characters_used / 150) # Assuming 150 characters per minute, converted to int
|
283 |
+
max_minutes = int(usage.character.limit / 150) # Converted to int
|
284 |
+
percent_used = (minutes_used / max_minutes) * 100
|
285 |
+
|
286 |
+
# Formatting the output for hours and minutes
|
287 |
+
used_time_str = f"{minutes_used} min used"
|
288 |
+
max_time_str = f"{max_minutes} min total"
|
289 |
+
if minutes_used >= 60:
|
290 |
+
hours_used = minutes_used // 60
|
291 |
+
minutes_used = minutes_used % 60
|
292 |
+
used_time_str = f"{hours_used} hrs, {minutes_used} min used"
|
293 |
+
if max_minutes >= 60:
|
294 |
+
hours_max = max_minutes // 60
|
295 |
+
remaining_minutes_max = max_minutes % 60
|
296 |
+
max_time_str = f"{hours_max} hrs, {remaining_minutes_max} min total"
|
297 |
+
|
298 |
+
progress_bar_html = (
|
299 |
+
"<div style='width: 100%; background-color: #ddd; position: relative; text-align: center; "
|
300 |
+
"line-height: 2em; font-size: 0.9em;'>"
|
301 |
+
"<div style='position: absolute; width: 100%; left: 0; top: 0;'>"
|
302 |
+
f"{used_time_str} / {max_time_str}"
|
303 |
+
"</div>"
|
304 |
+
f"<div style='height: 2em; background-color: #4caf50; width: {percent_used}%;'>"
|
305 |
+
"</div>"
|
306 |
+
"</div>"
|
307 |
+
)
|
308 |
+
return progress_bar_html
|
309 |
+
else:
|
310 |
+
return "<div style='color: red; text-align: center;'>Translation limit is reached</div>"
|
311 |
|
312 |
def clear_inputs():
|
313 |
return None, "", None, None
|
|
|
324 |
"""
|
325 |
|
326 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
327 |
+
|
328 |
+
initial_usage_info = translation_limit()
|
329 |
+
|
330 |
gr.Markdown("<h1 style='text-align: center;'>🌐AI Video Translation</h2>")
|
331 |
gr.Markdown("<h3 style='text-align: center;'>Currently supported languages are: English, Polish, Ukrainian, and Russian</h3>")
|
332 |
|
333 |
with gr.Row():
|
334 |
with gr.Column(elem_classes=["column-frame"]):
|
335 |
gr.Markdown("<h2 style='text-align: center;'>Inputs</h3>")
|
336 |
+
translation_limit_info = gr.Markdown(initial_usage_info)
|
337 |
video = gr.Video(label="Upload a video file")
|
338 |
gr.Markdown("<h3 style='text-align: center;'>OR</h3>")
|
339 |
youtube_link = gr.Textbox(label="Paste YouTube link")
|
|
|
353 |
translate_btn.click(
|
354 |
fn=translate_video,
|
355 |
inputs=[video, youtube_link, target_language, speaker_model],
|
356 |
+
outputs=[translation_limit_info, output_video]
|
357 |
)
|
358 |
|
359 |
clear_btn.click(
|