Awell00 commited on
Commit
ad69837
·
verified ·
1 Parent(s): 7b3ac0c

fix: formatted title

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -31,31 +31,25 @@ def handle_file_upload(file):
31
 
32
  filename = os.path.basename(file.name)
33
 
34
- # Regex to extract "Artist - Title" from various formats
35
  match = re.match(
36
- r'^(.*?)(?:\s*[-\[\(]\s*)(.*?)(?=\s*[\[\(\-]|$)', filename
37
  )
38
-
39
  if match:
40
- if '-' in match.group(1):
41
- # If the dash is in the first part, assume "Artist - Title"
42
- formatted_title = match.group(1).strip()
43
- else:
44
- # Otherwise, assume "Title - Artist"
45
- formatted_title = f"{match.group(2).strip()} - {match.group(1).strip()}"
46
  else:
47
- formatted_title = filename
 
48
 
49
- formatted_title = sanitize_filename(formatted_title.strip())
50
-
51
  input_path = os.path.join(INPUT_FOLDER, "wav", f"{formatted_title}.wav")
52
  os.makedirs(os.path.dirname(input_path), exist_ok=True)
53
-
54
  # Copy the uploaded file to the input folder
55
  shutil.copy(file.name, input_path)
56
-
57
- return input_path, formatted_title
58
 
 
59
 
60
  def run_inference(model_type, config_path, start_check_point, input_dir, output_dir, device_ids="0"):
61
  command = [
 
31
 
32
  filename = os.path.basename(file.name)
33
 
34
+ # This regex captures both "Artist - Title" and "Title - Artist" formats
35
  match = re.match(
36
+ r'^(.*? - .*?)\s*(?:[\(\[].*?[\)\]])?$', filename
37
  )
38
+
39
  if match:
40
+ # This directly captures the "Artist - Title" part
41
+ formatted_title = match.group(1).strip()
 
 
 
 
42
  else:
43
+ # If no match, fallback to the original filename
44
+ formatted_title = sanitize_filename(filename.strip())
45
 
 
 
46
  input_path = os.path.join(INPUT_FOLDER, "wav", f"{formatted_title}.wav")
47
  os.makedirs(os.path.dirname(input_path), exist_ok=True)
48
+
49
  # Copy the uploaded file to the input folder
50
  shutil.copy(file.name, input_path)
 
 
51
 
52
+ return input_path, formatted_title
53
 
54
  def run_inference(model_type, config_path, start_check_point, input_dir, output_dir, device_ids="0"):
55
  command = [