Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,9 +18,13 @@ def generate_subtitles(video_path, target_language):
|
|
18 |
with open("temp_audio.wav", "rb") as audio_file:
|
19 |
transcription = asr(audio_file)["text"]
|
20 |
|
21 |
-
# Translate transcription to the target language
|
|
|
22 |
translation_pipeline = pipeline('translation', model='facebook/m2m100_418M')
|
23 |
-
translated_subtitles = translation_pipeline(
|
|
|
|
|
|
|
24 |
|
25 |
# Return subtitles (text for now)
|
26 |
subtitles = f"Original: {transcription}\nTranslated: {translated_subtitles}"
|
@@ -36,7 +40,20 @@ interface = gr.Interface(
|
|
36 |
fn=subtitle_video,
|
37 |
inputs=[
|
38 |
gr.Video(label="Upload Video"),
|
39 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
],
|
41 |
outputs="text",
|
42 |
title="Automatic Video Subtitler & Translator"
|
|
|
18 |
with open("temp_audio.wav", "rb") as audio_file:
|
19 |
transcription = asr(audio_file)["text"]
|
20 |
|
21 |
+
# Translate transcription to the target language using M2M100
|
22 |
+
# The forced_bos_token_id is set based on the target language
|
23 |
translation_pipeline = pipeline('translation', model='facebook/m2m100_418M')
|
24 |
+
translated_subtitles = translation_pipeline(
|
25 |
+
transcription,
|
26 |
+
forced_bos_token_id=translation_pipeline.tokenizer.get_lang_id(target_language)
|
27 |
+
)[0]["translation_text"]
|
28 |
|
29 |
# Return subtitles (text for now)
|
30 |
subtitles = f"Original: {transcription}\nTranslated: {translated_subtitles}"
|
|
|
40 |
fn=subtitle_video,
|
41 |
inputs=[
|
42 |
gr.Video(label="Upload Video"),
|
43 |
+
gr.Dropdown( # Dropdown for language selection
|
44 |
+
label="Choose Target Language",
|
45 |
+
choices=[
|
46 |
+
"fa", # Persian
|
47 |
+
"fr", # French
|
48 |
+
"es", # Spanish
|
49 |
+
"de", # German
|
50 |
+
"zh", # Chinese
|
51 |
+
"ar", # Arabic
|
52 |
+
"hi", # Hindi
|
53 |
+
"ru" # Russian
|
54 |
+
],
|
55 |
+
value="fa", # Default to Persian
|
56 |
+
),
|
57 |
],
|
58 |
outputs="text",
|
59 |
title="Automatic Video Subtitler & Translator"
|