Awell00 commited on
Commit
b9d3d3a
·
verified ·
1 Parent(s): 6bd24ce

fix: update the formatted name

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -28,16 +28,33 @@ def delete_input_files(input_dir):
28
  wav_file.unlink()
29
  print(f"Deleted {wav_file}")
30
 
31
- def analyze_filename_with_llm(filename):
32
- prompt = f"Extract the artist and song title from the following filename and format it as 'Artist - Title':\n\n{filename}"
33
-
34
- # Generate a response using the local model
35
- response = model(prompt, max_length=50, do_sample=False)[0]['generated_text']
36
-
37
- # Extract the first line of the response, which should be the "Artist - Title"
38
- artist_title = response.strip().split('\n')[0]
39
-
40
- return artist_title
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  def handle_file_upload(file):
43
  if file is None:
@@ -45,15 +62,13 @@ def handle_file_upload(file):
45
 
46
  filename = os.path.basename(file.name)
47
 
48
- # Use LLM to analyze the filename and return the formatted title
49
- formatted_title = analyze_filename_with_llm(filename)
50
 
51
  formatted_title = sanitize_filename(formatted_title.strip())
52
 
53
  input_path = os.path.join(INPUT_FOLDER, "wav", f"{formatted_title}.wav")
54
  os.makedirs(os.path.dirname(input_path), exist_ok=True)
55
 
56
- # Copy the uploaded file to the input folder
57
  shutil.copy(file.name, input_path)
58
 
59
  return input_path, formatted_title
 
28
  wav_file.unlink()
29
  print(f"Deleted {wav_file}")
30
 
31
+ def standardize_title(input_title):
32
+ title_cleaned = re.sub(r"[\(\[].*?[\)\]]", "", input_title)
33
+
34
+ unnecessary_words = ["official", "video", "hd", "4k", "lyrics", "music", "audio", "visualizer", "remix"]
35
+ title_cleaned = re.sub(r"\b(?:{})\b".format("|".join(unnecessary_words)), "", title_cleaned, flags=re.IGNORECASE)
36
+
37
+ parts = re.split(r"\s*-\s*|\s*,\s*", title_cleaned)
38
+
39
+ if len(parts) >= 2:
40
+ title_part = parts[-1].strip()
41
+ artist_part = ', '.join(parts[:-1]).strip()
42
+ else:
43
+ artist_part = "Unknown Artist"
44
+ title_part = title_cleaned.strip()
45
+
46
+ if "with" in input_title.lower() or "feat" in input_title.lower():
47
+ match = re.search(r"\((with|feat\.?) (.*?)\)", input_title, re.IGNORECASE)
48
+ if match:
49
+ additional_artist = match.group(2).strip()
50
+ artist_part = f"{artist_part}, {additional_artist}" if artist_part != "Unknown Artist" else additional_artist
51
+
52
+ artist_part = re.sub(r'\s+', ' ', artist_part).title()
53
+ title_part = re.sub(r'\s+', ' ', title_part).title()
54
+
55
+ standardized_output = f"{artist_part} - {title_part}"
56
+
57
+ return standardized_output.strip()
58
 
59
  def handle_file_upload(file):
60
  if file is None:
 
62
 
63
  filename = os.path.basename(file.name)
64
 
65
+ formatted_title = standardize_title(filename)
 
66
 
67
  formatted_title = sanitize_filename(formatted_title.strip())
68
 
69
  input_path = os.path.join(INPUT_FOLDER, "wav", f"{formatted_title}.wav")
70
  os.makedirs(os.path.dirname(input_path), exist_ok=True)
71
 
 
72
  shutil.copy(file.name, input_path)
73
 
74
  return input_path, formatted_title