Nekochu commited on
Commit
4d9a556
·
1 Parent(s): 57df0f6

fix review: debug leak, int crash, rank mismatch, 0-byte skip, log cap, understand diag

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -143,7 +143,7 @@ def _caption_via_understand(audio_path, timeout=120):
143
  timeout=30,
144
  )
145
  if r.status_code != 200:
146
- logger.warning("[Caption] %s: /understand returned %d", fname, r.status_code)
147
  return None
148
  job_id = r.json().get("id")
149
  if not job_id:
@@ -185,14 +185,17 @@ def _run_pipeline(caption, lyrics, bpm, duration, seed, steps, output_format,
185
  req = {"caption": caption or "upbeat electronic dance music"}
186
  req["lyrics"] = lyrics if lyrics and lyrics.strip() else "[Instrumental]"
187
 
188
- if bpm and int(bpm) > 0:
189
- req["bpm"] = int(bpm)
190
- if duration and float(duration) > 0:
191
- req["duration"] = min(float(duration), 300)
192
- if seed is not None and int(seed) >= 0:
193
- req["seed"] = int(seed)
194
- if steps and int(steps) > 0:
195
- req["inference_steps"] = int(steps)
 
 
 
196
  if adapter:
197
  req["adapter"] = adapter
198
  if lm_model:
@@ -557,6 +560,8 @@ def gradio_main():
557
 
558
  def _log(msg):
559
  _train_log_lines.append(msg)
 
 
560
 
561
  def _log_text():
562
  return "\n".join(_train_log_lines)
@@ -577,7 +582,7 @@ def gradio_main():
577
 
578
  epochs = max(1, min(int(epochs), 1000))
579
  lr = float(lr)
580
- rank = max(1, min(int(rank), 64))
581
 
582
  work_dir = os.path.join(OUTPUT_DIR, "train_workspace", lora_name)
583
  os.makedirs(work_dir, exist_ok=True)
@@ -602,6 +607,9 @@ def gradio_main():
602
  dur = _lr.get_duration(path=src)
603
  except Exception:
604
  dur = 0.0
 
 
 
605
  remaining = MAX_TOTAL_AUDIO - total_dur
606
  if remaining <= 0:
607
  skipped_names.append(fname)
@@ -765,12 +773,10 @@ def gradio_main():
765
  _log("[OK] ace-server restarted successfully")
766
  else:
767
  _log("[WARN] ace-server may not have restarted -- check logs")
768
- # Debug: list what's in the adapter directory
769
  if os.path.isdir(adapter_out):
770
- contents = os.listdir(adapter_out)
771
- _log(f"[DEBUG] Adapter dir {adapter_out}: {contents}")
772
  else:
773
- _log(f"[DEBUG] Adapter dir {adapter_out} does NOT exist!")
774
  adapter_safetensors = os.path.join(adapter_out, "adapter_model.safetensors")
775
  if os.path.isfile(adapter_safetensors):
776
  # Copy to a temp file so Gradio doesn't try to validate /app paths
 
143
  timeout=30,
144
  )
145
  if r.status_code != 200:
146
+ logger.warning("[Caption] %s: /understand returned %d: %s", fname, r.status_code, r.text[:200])
147
  return None
148
  job_id = r.json().get("id")
149
  if not job_id:
 
185
  req = {"caption": caption or "upbeat electronic dance music"}
186
  req["lyrics"] = lyrics if lyrics and lyrics.strip() else "[Instrumental]"
187
 
188
+ try:
189
+ if bpm and int(float(bpm)) > 0:
190
+ req["bpm"] = int(float(bpm))
191
+ if duration and float(duration) > 0:
192
+ req["duration"] = min(float(duration), 300)
193
+ if seed is not None and int(float(seed)) >= 0:
194
+ req["seed"] = int(float(seed))
195
+ if steps and int(float(steps)) > 0:
196
+ req["inference_steps"] = int(float(steps))
197
+ except (ValueError, TypeError):
198
+ pass
199
  if adapter:
200
  req["adapter"] = adapter
201
  if lm_model:
 
560
 
561
  def _log(msg):
562
  _train_log_lines.append(msg)
563
+ if len(_train_log_lines) > 2000:
564
+ _train_log_lines[:] = _train_log_lines[-1000:]
565
 
566
  def _log_text():
567
  return "\n".join(_train_log_lines)
 
582
 
583
  epochs = max(1, min(int(epochs), 1000))
584
  lr = float(lr)
585
+ rank = max(1, min(int(rank), 128))
586
 
587
  work_dir = os.path.join(OUTPUT_DIR, "train_workspace", lora_name)
588
  os.makedirs(work_dir, exist_ok=True)
 
607
  dur = _lr.get_duration(path=src)
608
  except Exception:
609
  dur = 0.0
610
+ if dur <= 0:
611
+ skipped_names.append(f"{fname} (invalid/empty)")
612
+ continue
613
  remaining = MAX_TOTAL_AUDIO - total_dur
614
  if remaining <= 0:
615
  skipped_names.append(fname)
 
773
  _log("[OK] ace-server restarted successfully")
774
  else:
775
  _log("[WARN] ace-server may not have restarted -- check logs")
 
776
  if os.path.isdir(adapter_out):
777
+ logger.info("Adapter dir %s: %s", adapter_out, os.listdir(adapter_out))
 
778
  else:
779
+ logger.warning("Adapter dir %s does not exist", adapter_out)
780
  adapter_safetensors = os.path.join(adapter_out, "adapter_model.safetensors")
781
  if os.path.isfile(adapter_safetensors):
782
  # Copy to a temp file so Gradio doesn't try to validate /app paths