lauraibnz commited on
Commit
ffa9e1a
1 Parent(s): c7696fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -22,10 +22,14 @@ pipe = AudioLDMControlNetPipeline.from_pretrained(
22
  pipe = pipe.to(device)
23
  generator = torch.Generator(device)
24
 
25
- def predict(midi_file=None, prompt="", neg_prompt="", duration=10, seed=0, cond=1, inf=20, guidance_scale=2.5, guess=False):
26
  if isinstance(midi_file, _TemporaryFileWrapper):
27
  midi_file = midi_file.name
28
  midi = PrettyMIDI(midi_file)
 
 
 
 
29
  audio = pipe(
30
  prompt,
31
  negative_prompt=neg_prompt,
@@ -49,11 +53,7 @@ def synthesize(midi_file=None):
49
 
50
  def run_example(midi_file=None, prompt="", neg_prompt="", duration=None, seed=0, cond=1, inf=20, guidance_scale=2.5, guess=False):
51
  midi_synth = synthesize(midi_file)
52
- if not duration or duration == 0:
53
- print("Duration", duration)
54
- duration = midi_synth[1].shape[0]/SAMPLE_RATE
55
- print("New duration", duration)
56
- gen_audio = predict(midi_file, prompt, neg_prompt, duration, seed, cond, inf, guidance_scale, guess)
57
  return midi_synth, gen_audio
58
 
59
  with gr.Blocks(title="🎹 MIDI-AudioLDM", theme=gr.themes.Base(text_size=gr.themes.sizes.text_md, font=[gr.themes.GoogleFont("Nunito Sans")])) as demo:
@@ -83,7 +83,7 @@ with gr.Blocks(title="🎹 MIDI-AudioLDM", theme=gr.themes.Base(text_size=gr.the
83
  cond = gr.Slider(0.0, 1.0, value=1.0, step=0.1, label="conditioning scale", info="Choose a value between 0 and 1. The larger the more it will take the conditioning into account. Lower values are recommended for more creative prompts.")
84
  guess = gr.Checkbox(label="guess mode", info="Optionally select guess mode. If so, the model will try to recognize the content of the MIDI without the need of a text prompt.")
85
  btn = gr.Button("Generate")
86
- btn.click(predict, inputs=[midi, prompt, neg_prompt, duration, seed, cond, inf, guidance_scale, guess], outputs=[audio])
87
  gr.Examples(examples=[["S00.mid", "piano", "", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "violin", "", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "woman singing, studio recording", "noise", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "jazz band, clean", "noise", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "choir", "noise, percussion", 10, 48, 1.0, 20, 2.5, False]], inputs=[midi, prompt, neg_prompt, duration, seed, cond, inf, guidance_scale, guess], fn=run_example, outputs=[midi_synth, audio], cache_examples=True)
88
 
89
  demo.launch()
 
22
  pipe = pipe.to(device)
23
  generator = torch.Generator(device)
24
 
25
+ def predict(midi_file=None, midi_synth=None, prompt="", neg_prompt="", duration=None, seed=0, cond=1, inf=20, guidance_scale=2.5, guess=False):
26
  if isinstance(midi_file, _TemporaryFileWrapper):
27
  midi_file = midi_file.name
28
  midi = PrettyMIDI(midi_file)
29
+ if not duration or duration == 0:
30
+ print("Duration", duration)
31
+ duration = midi_synth[1].shape[0]/SAMPLE_RATE
32
+ print("New duration", duration)
33
  audio = pipe(
34
  prompt,
35
  negative_prompt=neg_prompt,
 
53
 
54
  def run_example(midi_file=None, prompt="", neg_prompt="", duration=None, seed=0, cond=1, inf=20, guidance_scale=2.5, guess=False):
55
  midi_synth = synthesize(midi_file)
56
+ gen_audio = predict(midi_file, midi_synth, prompt, neg_prompt, duration, seed, cond, inf, guidance_scale, guess)
 
 
 
 
57
  return midi_synth, gen_audio
58
 
59
  with gr.Blocks(title="🎹 MIDI-AudioLDM", theme=gr.themes.Base(text_size=gr.themes.sizes.text_md, font=[gr.themes.GoogleFont("Nunito Sans")])) as demo:
 
83
  cond = gr.Slider(0.0, 1.0, value=1.0, step=0.1, label="conditioning scale", info="Choose a value between 0 and 1. The larger the more it will take the conditioning into account. Lower values are recommended for more creative prompts.")
84
  guess = gr.Checkbox(label="guess mode", info="Optionally select guess mode. If so, the model will try to recognize the content of the MIDI without the need of a text prompt.")
85
  btn = gr.Button("Generate")
86
+ btn.click(predict, inputs=[midi, midi_synth, prompt, neg_prompt, duration, seed, cond, inf, guidance_scale, guess], outputs=[audio])
87
  gr.Examples(examples=[["S00.mid", "piano", "", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "violin", "", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "woman singing, studio recording", "noise", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "jazz band, clean", "noise", 10, 48, 1.0, 20, 2.5, False], ["S00.mid", "choir", "noise, percussion", 10, 48, 1.0, 20, 2.5, False]], inputs=[midi, prompt, neg_prompt, duration, seed, cond, inf, guidance_scale, guess], fn=run_example, outputs=[midi_synth, audio], cache_examples=True)
88
 
89
  demo.launch()