victor HF staff commited on
Commit
2401abf
·
1 Parent(s): d12417e

refactor: Sanitize filenames to prevent FFMPEG input errors

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -49,7 +49,8 @@ def get_files_infos(files):
49
  file_path = Path(file.name)
50
  info = {}
51
  info["size"] = os.path.getsize(file_path)
52
- info["name"] = file_path.name
 
53
  file_extension = file_path.suffix
54
 
55
  if file_extension in (".mp4", ".avi", ".mkv", ".mov"):
@@ -203,10 +204,11 @@ def update(files, prompt, top_p=1, temperature=1):
203
  if args[0] != "ffmpeg":
204
  raise Exception("Command does not start with ffmpeg")
205
  temp_dir = tempfile.mkdtemp()
206
- # copy files to temp dir
207
  for file in files:
208
  file_path = Path(file.name)
209
- shutil.copy(file_path, temp_dir)
 
210
 
211
  # test if ffmpeg command is valid dry run
212
  ffmpg_dry_run = subprocess.run(
 
49
  file_path = Path(file.name)
50
  info = {}
51
  info["size"] = os.path.getsize(file_path)
52
+ # Sanitize filename by replacing spaces with underscores
53
+ info["name"] = file_path.name.replace(" ", "_")
54
  file_extension = file_path.suffix
55
 
56
  if file_extension in (".mp4", ".avi", ".mkv", ".mov"):
 
204
  if args[0] != "ffmpeg":
205
  raise Exception("Command does not start with ffmpeg")
206
  temp_dir = tempfile.mkdtemp()
207
+ # copy files to temp dir with sanitized names
208
  for file in files:
209
  file_path = Path(file.name)
210
+ sanitized_name = file_path.name.replace(" ", "_")
211
+ shutil.copy(file_path, Path(temp_dir) / sanitized_name)
212
 
213
  # test if ffmpeg command is valid dry run
214
  ffmpg_dry_run = subprocess.run(