Spaces:
Paused
Paused
Commit ·
640aa41
1
Parent(s): fabf10e
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ import stat
|
|
| 11 |
import uuid
|
| 12 |
import subprocess
|
| 13 |
|
| 14 |
-
|
| 15 |
ZipFile("ffmpeg.zip").extractall()
|
| 16 |
st = os.stat('ffmpeg')
|
| 17 |
os.chmod('ffmpeg', st.st_mode | stat.S_IEXEC)
|
|
@@ -25,19 +24,19 @@ whisper_model = WhisperModel("large-v2", device="cuda", compute_type="float16")
|
|
| 25 |
|
| 26 |
def process_video(Video, target_language):
|
| 27 |
print("Iniciando process_video")
|
| 28 |
-
|
| 29 |
print("Checking FFmpeg availability...")
|
| 30 |
run(["ffmpeg", "-version"])
|
| 31 |
|
| 32 |
|
| 33 |
-
audio_file = f"{
|
| 34 |
run(["ffmpeg", "-i", Video, audio_file])
|
| 35 |
|
| 36 |
# Transcription with Whisper.
|
| 37 |
print("Iniciando transcrição com Whisper")
|
| 38 |
segments, _ = whisper_model.transcribe(audio_file, beam_size=5)
|
| 39 |
segments = list(segments)
|
| 40 |
-
transcript_file = f"{
|
| 41 |
|
| 42 |
# Create a list to hold the translated lines.
|
| 43 |
translated_lines = []
|
|
@@ -81,7 +80,7 @@ def process_video(Video, target_language):
|
|
| 81 |
# Write the translated lines back into the original file.
|
| 82 |
f.writelines(translated_lines)
|
| 83 |
|
| 84 |
-
output_video = "
|
| 85 |
# Debugging: Validate FFmpeg command for subtitle embedding
|
| 86 |
print("Validating FFmpeg command for subtitle embedding...")
|
| 87 |
print(f"Translated SRT file: {transcript_file}")
|
|
@@ -105,7 +104,7 @@ def process_video(Video, target_language):
|
|
| 105 |
print("process_video concluído com sucesso")
|
| 106 |
os.unlink(audio_file)
|
| 107 |
os.unlink(transcript_file)
|
| 108 |
-
|
| 109 |
return output_video
|
| 110 |
|
| 111 |
iface = gr.Interface(
|
|
|
|
| 11 |
import uuid
|
| 12 |
import subprocess
|
| 13 |
|
|
|
|
| 14 |
ZipFile("ffmpeg.zip").extractall()
|
| 15 |
st = os.stat('ffmpeg')
|
| 16 |
os.chmod('ffmpeg', st.st_mode | stat.S_IEXEC)
|
|
|
|
| 24 |
|
| 25 |
def process_video(Video, target_language):
|
| 26 |
print("Iniciando process_video")
|
| 27 |
+
common_uuid = uuid.uuid4()
|
| 28 |
print("Checking FFmpeg availability...")
|
| 29 |
run(["ffmpeg", "-version"])
|
| 30 |
|
| 31 |
|
| 32 |
+
audio_file = f"{common_uuid}.wav"
|
| 33 |
run(["ffmpeg", "-i", Video, audio_file])
|
| 34 |
|
| 35 |
# Transcription with Whisper.
|
| 36 |
print("Iniciando transcrição com Whisper")
|
| 37 |
segments, _ = whisper_model.transcribe(audio_file, beam_size=5)
|
| 38 |
segments = list(segments)
|
| 39 |
+
transcript_file = f"{common_uuid}.srt"
|
| 40 |
|
| 41 |
# Create a list to hold the translated lines.
|
| 42 |
translated_lines = []
|
|
|
|
| 80 |
# Write the translated lines back into the original file.
|
| 81 |
f.writelines(translated_lines)
|
| 82 |
|
| 83 |
+
output_video = f"{common_uuid}_output_video.mp4"
|
| 84 |
# Debugging: Validate FFmpeg command for subtitle embedding
|
| 85 |
print("Validating FFmpeg command for subtitle embedding...")
|
| 86 |
print(f"Translated SRT file: {transcript_file}")
|
|
|
|
| 104 |
print("process_video concluído com sucesso")
|
| 105 |
os.unlink(audio_file)
|
| 106 |
os.unlink(transcript_file)
|
| 107 |
+
|
| 108 |
return output_video
|
| 109 |
|
| 110 |
iface = gr.Interface(
|