Spaces:
Paused
Paused
Commit
·
740becd
1
Parent(s):
7efc9e4
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,9 +22,15 @@ whisper_model = WhisperModel("large-v2", device="cuda", compute_type="float16")
|
|
| 22 |
|
| 23 |
def process_video(Video, target_language):
|
| 24 |
print("Iniciando process_video")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
audio_file = tempfile.NamedTemporaryFile(suffix=".wav").name
|
| 26 |
print("Executando FFmpeg para extração de áudio")
|
| 27 |
run(["ffmpeg", "-i", Video, audio_file])
|
|
|
|
| 28 |
print("Iniciando transcrição com Whisper")
|
| 29 |
segments, _ = whisper_model.transcribe(audio_file, beam_size=5)
|
| 30 |
segments = list(segments)
|
|
@@ -57,6 +63,15 @@ def process_video(Video, target_language):
|
|
| 57 |
outfile.write(translated_text + "\n")
|
| 58 |
else:
|
| 59 |
outfile.write("\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
if os.path.exists(temp_transcript_file.name):
|
| 61 |
print(f"Arquivo de legenda criado: {temp_transcript_file.name}")
|
| 62 |
if os.path.getsize(temp_transcript_file.name) > 0:
|
|
@@ -65,13 +80,18 @@ def process_video(Video, target_language):
|
|
| 65 |
print("O arquivo de legenda está vazio.")
|
| 66 |
else:
|
| 67 |
print("Arquivo de legenda não foi criado.")
|
| 68 |
-
|
| 69 |
output_video = "output_video.mp4"
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
os.unlink(temp_transcript_file.name)
|
| 76 |
os.unlink(temp_translated_file.name)
|
| 77 |
print("process_video concluído com sucesso")
|
|
|
|
| 22 |
|
| 23 |
def process_video(Video, target_language):
|
| 24 |
print("Iniciando process_video")
|
| 25 |
+
|
| 26 |
+
print("Checking FFmpeg availability...")
|
| 27 |
+
run(["ffmpeg", "-version"])
|
| 28 |
+
|
| 29 |
+
|
| 30 |
audio_file = tempfile.NamedTemporaryFile(suffix=".wav").name
|
| 31 |
print("Executando FFmpeg para extração de áudio")
|
| 32 |
run(["ffmpeg", "-i", Video, audio_file])
|
| 33 |
+
|
| 34 |
print("Iniciando transcrição com Whisper")
|
| 35 |
segments, _ = whisper_model.transcribe(audio_file, beam_size=5)
|
| 36 |
segments = list(segments)
|
|
|
|
| 63 |
outfile.write(translated_text + "\n")
|
| 64 |
else:
|
| 65 |
outfile.write("\n")
|
| 66 |
+
if os.path.exists(temp_transcript_file.name):
|
| 67 |
+
print(f"Subtitle file exists: {temp_transcript_file.name}")
|
| 68 |
+
if os.access(temp_transcript_file.name, os.R_OK):
|
| 69 |
+
print("Subtitle file is readable.")
|
| 70 |
+
else:
|
| 71 |
+
print("Subtitle file is not readable.")
|
| 72 |
+
else:
|
| 73 |
+
print("Subtitle file does not exist.")
|
| 74 |
+
|
| 75 |
if os.path.exists(temp_transcript_file.name):
|
| 76 |
print(f"Arquivo de legenda criado: {temp_transcript_file.name}")
|
| 77 |
if os.path.getsize(temp_transcript_file.name) > 0:
|
|
|
|
| 80 |
print("O arquivo de legenda está vazio.")
|
| 81 |
else:
|
| 82 |
print("Arquivo de legenda não foi criado.")
|
| 83 |
+
|
| 84 |
output_video = "output_video.mp4"
|
| 85 |
+
print("Validating FFmpeg command for subtitle embedding...")
|
| 86 |
+
try:
|
| 87 |
+
result = run(["ffmpeg", "-i", Video, "-vf", f"subtitles={temp_translated_file.name}", output_video])
|
| 88 |
+
if result.returncode == 0:
|
| 89 |
+
print("FFmpeg executed successfully.")
|
| 90 |
+
else:
|
| 91 |
+
print(f"FFmpeg failed with return code {result.returncode}.")
|
| 92 |
+
except Exception as e:
|
| 93 |
+
print(f"Exception occurred: {e}")
|
| 94 |
+
|
| 95 |
os.unlink(temp_transcript_file.name)
|
| 96 |
os.unlink(temp_translated_file.name)
|
| 97 |
print("process_video concluído com sucesso")
|