Surn commited on
Commit
74894bc
1 Parent(s): 132d237

Hack fix to prevent massive song edits

Browse files
Files changed (2) hide show
  1. app.py +5 -3
  2. audiocraft/utils/extend.py +2 -2
app.py CHANGED
@@ -85,7 +85,7 @@ def load_melody_filepath(melody_filepath, title):
85
  #$Union[str, os.PathLike]
86
  symbols = ['_', '.', '-']
87
  if melody_filepath is None:
88
- return None, title
89
 
90
  if (title is None) or ("MusicGen" in title) or (title == ""):
91
  melody_name, melody_extension = get_filename_from_filepath(melody_filepath)
@@ -114,7 +114,9 @@ def load_melody(melody, prompt_index):
114
  def predict(model, text, melody, melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, overlap=1, prompt_index = 0, include_title = True, include_settings = True):
115
  global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
116
  output_segments = None
117
- melody_name, melody_extension = get_filename_from_filepath(melody_filepath)
 
 
118
  INTERRUPTED = False
119
  INTERRUPTING = False
120
  if temperature < 0:
@@ -237,7 +239,7 @@ def predict(model, text, melody, melody_filepath, duration, dimension, topk, top
237
  output = output.detach().cpu().float()[0]
238
 
239
  with NamedTemporaryFile("wb", suffix=".wav", delete=False) as file:
240
- video_description = f"{text}\n Duration: {str(initial_duration)} Dimension: {dimension}\n Top-k:{topk} Top-p:{topp}\n Randomness:{temperature}\n cfg:{cfg_coef} overlap: {overlap}\n Seed: {seed}\n Model: {model}\n Melody Condition:{melody_name}\n Prompt index: {prompt_index}"
241
  if include_settings or include_title:
242
  background = add_settings_to_image(title if include_title else "", video_description if include_settings else "", background_path=background, font=settings_font, font_color=settings_font_color)
243
  audio_write(
 
85
  #$Union[str, os.PathLike]
86
  symbols = ['_', '.', '-']
87
  if melody_filepath is None:
88
+ return None, title
89
 
90
  if (title is None) or ("MusicGen" in title) or (title == ""):
91
  melody_name, melody_extension = get_filename_from_filepath(melody_filepath)
 
114
  def predict(model, text, melody, melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, overlap=1, prompt_index = 0, include_title = True, include_settings = True):
115
  global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
116
  output_segments = None
117
+ melody_name = "Not Used"
118
+ if melody_filepath:
119
+ melody_name, melody_extension = get_filename_from_filepath(melody_filepath)
120
  INTERRUPTED = False
121
  INTERRUPTING = False
122
  if temperature < 0:
 
239
  output = output.detach().cpu().float()[0]
240
 
241
  with NamedTemporaryFile("wb", suffix=".wav", delete=False) as file:
242
+ video_description = f"{text}\n Duration: {str(initial_duration)} Dimension: {dimension}\n Top-k:{topk} Top-p:{topp}\n Randomness:{temperature}\n cfg:{cfg_coef} overlap: {overlap}\n Seed: {seed}\n Model: {model}\n Melody Condition:{melody_name}\n Sample Segment: {prompt_index}"
243
  if include_settings or include_title:
244
  background = add_settings_to_image(title if include_title else "", video_description if include_settings else "", background_path=background, font=settings_font, font_color=settings_font_color)
245
  audio_write(
audiocraft/utils/extend.py CHANGED
@@ -17,9 +17,9 @@ INTERRUPTING = False
17
 
18
  def separate_audio_segments(audio, segment_duration=30, overlap=1):
19
  sr, audio_data = audio[0], audio[1]
20
-
21
- total_samples = len(audio_data)
22
  segment_samples = sr * segment_duration
 
23
  overlap_samples = sr * overlap
24
 
25
  segments = []
 
17
 
18
  def separate_audio_segments(audio, segment_duration=30, overlap=1):
19
  sr, audio_data = audio[0], audio[1]
20
+
 
21
  segment_samples = sr * segment_duration
22
+ total_samples = max(min((len(audio_data) // segment_samples), 25), 0)
23
  overlap_samples = sr * overlap
24
 
25
  segments = []