Spaces:
Paused
Paused
fix issue with reload of output video
Browse files- app.py +17 -3
- pipeline.py +11 -4
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from tqdm.asyncio import tqdm_asyncio
|
|
|
|
|
3 |
|
4 |
from pipeline import (
|
5 |
extract_audio_from_video,
|
@@ -20,7 +22,18 @@ async def process_video_translation(
|
|
20 |
|
21 |
total_stages = 6
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
with tqdm_asyncio(total=total_stages, desc="Processing video translation") as pbar:
|
25 |
|
26 |
# stage 1: extract audio from video
|
@@ -47,12 +60,13 @@ async def process_video_translation(
|
|
47 |
pbar.update(1)
|
48 |
|
49 |
progress(1.0, desc="Combining audio and video")
|
50 |
-
create_combined_output(input_video, output_audio, output_video)
|
51 |
pbar.update(1)
|
52 |
|
53 |
print("Video translation completed")
|
54 |
gr.Info(f"Video translation completed", duration=2)
|
55 |
|
|
|
56 |
return output_video
|
57 |
|
58 |
|
@@ -86,7 +100,7 @@ with gr.Blocks(
|
|
86 |
"""
|
87 |
<div style="display: flex; align-items: center; justify-content: center;">
|
88 |
<h1 style="font-size: 2em; font-weight: bold; margin-top: 1em;">
|
89 |
-
Video Dubbing
|
90 |
</h1>
|
91 |
</div>
|
92 |
|
|
|
1 |
import gradio as gr
|
2 |
from tqdm.asyncio import tqdm_asyncio
|
3 |
+
import os
|
4 |
+
import time
|
5 |
|
6 |
from pipeline import (
|
7 |
extract_audio_from_video,
|
|
|
22 |
|
23 |
total_stages = 6
|
24 |
|
25 |
+
# add time stamp to output video
|
26 |
+
timestamp = time.strftime("%M%S")
|
27 |
+
output_video = f"{input_video.split('.')[0]}_dubbed_{timestamp}.mp4"
|
28 |
+
|
29 |
+
# delete the output video if it exists
|
30 |
+
try:
|
31 |
+
os.remove(output_video)
|
32 |
+
print(f"Deleted existing output video: {output_video}")
|
33 |
+
except FileNotFoundError:
|
34 |
+
print(f"No existing output video found: {output_video}")
|
35 |
+
pass
|
36 |
+
|
37 |
with tqdm_asyncio(total=total_stages, desc="Processing video translation") as pbar:
|
38 |
|
39 |
# stage 1: extract audio from video
|
|
|
60 |
pbar.update(1)
|
61 |
|
62 |
progress(1.0, desc="Combining audio and video")
|
63 |
+
output_video = create_combined_output(input_video, output_audio, output_video)
|
64 |
pbar.update(1)
|
65 |
|
66 |
print("Video translation completed")
|
67 |
gr.Info(f"Video translation completed", duration=2)
|
68 |
|
69 |
+
print(f"Output video: {output_video}")
|
70 |
return output_video
|
71 |
|
72 |
|
|
|
100 |
"""
|
101 |
<div style="display: flex; align-items: center; justify-content: center;">
|
102 |
<h1 style="font-size: 2em; font-weight: bold; margin-top: 1em;">
|
103 |
+
African Language Video Dubbing POC
|
104 |
</h1>
|
105 |
</div>
|
106 |
|
pipeline.py
CHANGED
@@ -90,7 +90,7 @@ async def translation_main(sentences, url, headers, lang):
|
|
90 |
|
91 |
|
92 |
async def convert_text_to_speech(
|
93 |
-
session, tts_url, tts_header, text, speaker, semaphore, output_dir
|
94 |
):
|
95 |
speaker_dict = {"male": "twi_speaker_5", "female": "twi_speaker_7"}
|
96 |
speaker_id = speaker_dict[speaker]
|
@@ -100,7 +100,7 @@ async def convert_text_to_speech(
|
|
100 |
async with semaphore:
|
101 |
async with session.post(tts_url, headers=tts_header, json=data) as response:
|
102 |
response.raise_for_status()
|
103 |
-
output_path = os.path.join(output_dir, f"{
|
104 |
async with aiofiles.open(output_path, "wb") as file:
|
105 |
while True:
|
106 |
chunk = await response.content.read(16384)
|
@@ -120,9 +120,16 @@ async def tts_main(khaya_translations, speaker):
|
|
120 |
semaphore = asyncio.Semaphore(3)
|
121 |
tasks = [
|
122 |
convert_text_to_speech(
|
123 |
-
session,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
)
|
125 |
-
for sent in khaya_translations
|
126 |
]
|
127 |
output_files = []
|
128 |
for task in tqdm(
|
|
|
90 |
|
91 |
|
92 |
async def convert_text_to_speech(
|
93 |
+
session, tts_url, tts_header, text, text_index, speaker, semaphore, output_dir
|
94 |
):
|
95 |
speaker_dict = {"male": "twi_speaker_5", "female": "twi_speaker_7"}
|
96 |
speaker_id = speaker_dict[speaker]
|
|
|
100 |
async with semaphore:
|
101 |
async with session.post(tts_url, headers=tts_header, json=data) as response:
|
102 |
response.raise_for_status()
|
103 |
+
output_path = os.path.join(output_dir, f"{text_index}_tts.wav")
|
104 |
async with aiofiles.open(output_path, "wb") as file:
|
105 |
while True:
|
106 |
chunk = await response.content.read(16384)
|
|
|
120 |
semaphore = asyncio.Semaphore(3)
|
121 |
tasks = [
|
122 |
convert_text_to_speech(
|
123 |
+
session,
|
124 |
+
tts_url,
|
125 |
+
tts_header,
|
126 |
+
sent,
|
127 |
+
text_index,
|
128 |
+
speaker,
|
129 |
+
semaphore,
|
130 |
+
temp_dir,
|
131 |
)
|
132 |
+
for text_index, sent in enumerate(khaya_translations)
|
133 |
]
|
134 |
output_files = []
|
135 |
for task in tqdm(
|