Reubencf commited on
Commit
3efc2c4
·
verified ·
1 Parent(s): 6a2826a

Deploy Kiku-Engine

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -681,7 +681,7 @@ def _words(vocal_path):
681
  mono, _ = librosa.load(vocal_path, sr=16000, mono=True)
682
  with torch.inference_mode():
683
  heard = whisper()({"raw": mono, "sampling_rate": 16000}, return_timestamps=True,
684
- chunk_length_s=30, batch_size=8)
685
  lines = []
686
  for chunk in heard.get("chunks") or []:
687
  text = " ".join((chunk.get("text") or "").split())
@@ -730,9 +730,9 @@ def _read_take(audio, words=False, separate="auto"):
730
  return found
731
 
732
 
733
- def render_time(abc, style, lyrics, cot, seed, clock=None, duration=0.0, strip_voice=False,
734
  split_parts=False, **kwargs):
735
- seconds = min(MAX_SCORE, float(duration or 0) or 60)
736
  total = 45 + int(seconds * 0.9) + cold("yue2", 180)
737
  if clock:
738
  total += 30 + int(seconds * 0.45) + cold("sheetsage", 90)
@@ -742,8 +742,9 @@ def render_time(abc, style, lyrics, cot, seed, clock=None, duration=0.0, strip_v
742
 
743
 
744
  @spaces.GPU(duration=render_time)
745
- def _render_score(abc, style, lyrics, cot, seed, clock=None, duration=0.0, strip_voice=False,
746
  split_parts=False):
 
747
  """YuE2 plays the score; the result is then locked to `clock` when given."""
748
  import librosa
749
  job = job_dir()
@@ -764,13 +765,13 @@ def _render_score(abc, style, lyrics, cot, seed, clock=None, duration=0.0, strip
764
  score = scores.read(abc)
765
  heard = sync.bar_starts(beats, len(score.bars), len(mono) / 24000.0)
766
  if heard:
767
- warped, lock = sync.lock(audio, tools.SR, score, clock, heard, float(duration))
768
  report.update(lock)
769
  if warped is not None:
770
  audio, report["locked"] = warped, True
771
  if not report["locked"]:
772
  # No trustworthy bar match: start it on the first bar and let it run.
773
- audio = tools.shift(audio, float(clock[0]), tools.SR, length=int(float(duration) * tools.SR))
774
  path = tools.write(audio, str(job / "played.wav"))
775
  parts = [None, None, None]
776
  if split_parts:
@@ -849,7 +850,7 @@ def restage(audio, style, lyrics, voice, harmony, abc, clock, edits, seed, progr
849
  words = scores.lyric_tags(score)
850
  prompt = "Instrumental, %s, %d BPM, %s." % (described, score.bpm, ", ".join(INSTRUMENTAL))
851
  progress(0.4, desc="YuE2 is playing it")
852
- path, _, report = _render_score(text, prompt, words, cot, seed, clock=clock, duration=duration)
853
  elapsed = round(time.monotonic() - started)
854
  status = "Finished in %dm %ds / %s / %d BPM" % (elapsed // 60, elapsed % 60,
855
  scores.key_words(score.bars[0].key), score.bpm)
@@ -882,7 +883,7 @@ def band_score(audio, style, separate, balance, split_parts, abc, clock, edits,
882
  prompt = "Instrumental, %s, %d BPM, %s." % (described, band.bpm, ", ".join(INSTRUMENTAL))
883
  progress(0.4, desc="YuE2 is playing your chords")
884
  path, parts, report = _render_score(text, prompt, scores.lyric_tags(band), cot, seed, clock=clock,
885
- duration=duration, strip_voice=True,
886
  split_parts=bool(split_parts))
887
  job = job_dir()
888
  vocal_path = found["vocal"] if found else audio
 
681
  mono, _ = librosa.load(vocal_path, sr=16000, mono=True)
682
  with torch.inference_mode():
683
  heard = whisper()({"raw": mono, "sampling_rate": 16000}, return_timestamps=True,
684
+ chunk_length_s=30, batch_size=8, generate_kwargs={"task": "transcribe"})
685
  lines = []
686
  for chunk in heard.get("chunks") or []:
687
  text = " ".join((chunk.get("text") or "").split())
 
730
  return found
731
 
732
 
733
+ def render_time(abc, style, lyrics, cot, seed, clock=None, span=0.0, strip_voice=False,
734
  split_parts=False, **kwargs):
735
+ seconds = min(MAX_SCORE, float(span or 0) or 60)
736
  total = 45 + int(seconds * 0.9) + cold("yue2", 180)
737
  if clock:
738
  total += 30 + int(seconds * 0.45) + cold("sheetsage", 90)
 
742
 
743
 
744
  @spaces.GPU(duration=render_time)
745
+ def _render_score(abc, style, lyrics, cot, seed, clock=None, span=0.0, strip_voice=False,
746
  split_parts=False):
747
+ # `span` is the output length. It cannot be called `duration`: ZeroGPU reserves that keyword.
748
  """YuE2 plays the score; the result is then locked to `clock` when given."""
749
  import librosa
750
  job = job_dir()
 
765
  score = scores.read(abc)
766
  heard = sync.bar_starts(beats, len(score.bars), len(mono) / 24000.0)
767
  if heard:
768
+ warped, lock = sync.lock(audio, tools.SR, score, clock, heard, float(span))
769
  report.update(lock)
770
  if warped is not None:
771
  audio, report["locked"] = warped, True
772
  if not report["locked"]:
773
  # No trustworthy bar match: start it on the first bar and let it run.
774
+ audio = tools.shift(audio, float(clock[0]), tools.SR, length=int(float(span) * tools.SR))
775
  path = tools.write(audio, str(job / "played.wav"))
776
  parts = [None, None, None]
777
  if split_parts:
 
850
  words = scores.lyric_tags(score)
851
  prompt = "Instrumental, %s, %d BPM, %s." % (described, score.bpm, ", ".join(INSTRUMENTAL))
852
  progress(0.4, desc="YuE2 is playing it")
853
+ path, _, report = _render_score(text, prompt, words, cot, seed, clock=clock, span=duration)
854
  elapsed = round(time.monotonic() - started)
855
  status = "Finished in %dm %ds / %s / %d BPM" % (elapsed // 60, elapsed % 60,
856
  scores.key_words(score.bars[0].key), score.bpm)
 
883
  prompt = "Instrumental, %s, %d BPM, %s." % (described, band.bpm, ", ".join(INSTRUMENTAL))
884
  progress(0.4, desc="YuE2 is playing your chords")
885
  path, parts, report = _render_score(text, prompt, scores.lyric_tags(band), cot, seed, clock=clock,
886
+ span=duration, strip_voice=True,
887
  split_parts=bool(split_parts))
888
  job = job_dir()
889
  vocal_path = found["vocal"] if found else audio