|
11 | 11 | import gc |
12 | 12 | from copy import deepcopy |
13 | 13 | import time |
| 14 | +import shutil |
| 15 | +import tempfile |
14 | 16 |
|
15 | 17 | from modules.uvr.music_separator import MusicSeparator |
16 | 18 | from modules.utils.paths import (WHISPER_MODELS_DIR, DIARIZATION_MODELS_DIR, OUTPUT_DIR, DEFAULT_PARAMETERS_CONFIG_PATH, |
@@ -258,37 +260,47 @@ def transcribe_file(self, |
258 | 260 | if files and isinstance(files[0], gr.utils.NamedString): |
259 | 261 | files = [file.name for file in files] |
260 | 262 |
|
| 263 | + |
| 264 | + progress(0, desc="getting input files") |
261 | 265 | files_info = {} |
262 | | - for file in files: |
263 | | - transcribed_segments, time_for_task = self.run( |
264 | | - file, |
265 | | - progress, |
266 | | - file_format, |
267 | | - add_timestamp, |
268 | | - *pipeline_params, |
269 | | - ) |
270 | | - |
271 | | - file_name, file_ext = os.path.splitext(os.path.basename(file)) |
272 | | - if save_same_dir and input_folder_path: |
273 | | - output_dir = os.path.dirname(file) |
| 266 | + with tempfile.TemporaryDirectory(dir=".", prefix="_tmp_input") as tmp_folder: |
| 267 | + tmp_files = [] |
| 268 | + for f in files: |
| 269 | + if "PYTEST_CURRENT_TEST" in os.environ: |
| 270 | + # during tests we do not want to move/delete our input files |
| 271 | + tmp_files.append(shutil.copy(f, tmp_folder)) |
| 272 | + else: |
| 273 | + tmp_files.append(shutil.move(f, tmp_folder)) |
| 274 | + for file in tmp_files: |
| 275 | + transcribed_segments, time_for_task = self.run( |
| 276 | + file, |
| 277 | + progress, |
| 278 | + file_format, |
| 279 | + add_timestamp, |
| 280 | + *pipeline_params, |
| 281 | + ) |
| 282 | + |
| 283 | + file_name, file_ext = os.path.splitext(os.path.basename(file)) |
| 284 | + if save_same_dir and input_folder_path: |
| 285 | + output_dir = os.path.dirname(file) |
| 286 | + subtitle, file_path = generate_file( |
| 287 | + output_dir=output_dir, |
| 288 | + output_file_name=file_name, |
| 289 | + output_format=file_format, |
| 290 | + result=transcribed_segments, |
| 291 | + add_timestamp=add_timestamp, |
| 292 | + **writer_options |
| 293 | + ) |
| 294 | + |
274 | 295 | subtitle, file_path = generate_file( |
275 | | - output_dir=output_dir, |
| 296 | + output_dir=self.output_dir, |
276 | 297 | output_file_name=file_name, |
277 | 298 | output_format=file_format, |
278 | 299 | result=transcribed_segments, |
279 | 300 | add_timestamp=add_timestamp, |
280 | 301 | **writer_options |
281 | 302 | ) |
282 | | - |
283 | | - subtitle, file_path = generate_file( |
284 | | - output_dir=self.output_dir, |
285 | | - output_file_name=file_name, |
286 | | - output_format=file_format, |
287 | | - result=transcribed_segments, |
288 | | - add_timestamp=add_timestamp, |
289 | | - **writer_options |
290 | | - ) |
291 | | - files_info[file_name] = {"subtitle": read_file(file_path), "time_for_task": time_for_task, "path": file_path} |
| 303 | + files_info[file_name] = {"subtitle": read_file(file_path), "time_for_task": time_for_task, "path": file_path} |
292 | 304 |
|
293 | 305 | total_result = '' |
294 | 306 | total_time = 0 |
|
0 commit comments