lauraibnz commited on
Commit
24b2aa0
1 Parent(s): 6d27823

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -15
app.py CHANGED
@@ -10,34 +10,46 @@ else:
10
  device = "cpu"
11
  torch_dtype = torch.float32
12
 
13
- controlnet = ControlNetModel.from_pretrained("lauraibnz/midi-audioldm", torch_dtype=torch_dtype)
14
- pipe = AudioLDMControlNetPipeline.from_pretrained("cvssp/audioldm-m-full", controlnet=controlnet, torch_dtype=torch_dtype)
 
 
15
  pipe = pipe.to(device)
16
  generator = torch.Generator(device)
17
 
 
18
  def predict(midi_file=None, prompt="", negative_prompt="", audio_length_in_s=5, random_seed=0, controlnet_conditioning_scale=1, num_inference_steps=20, guess_mode=False):
19
  midi_file = midi_file.name
20
  midi = PrettyMIDI(midi_file)
21
  audio = pipe(
22
  prompt,
23
  negative_prompt=negative_prompt,
24
- midi=midi,
25
- audio_length_in_s=audio_length_in_s,
26
- num_inference_steps=num_inference_steps,
27
  controlnet_conditioning_scale=float(controlnet_conditioning_scale),
28
  guess_mode=guess_mode,
29
  generator=generator.manual_seed(int(random_seed)),
30
  )
31
  return (16000, audio.audios.T)
32
 
33
- demo = gr.Interface(fn=predict, inputs=[
34
- gr.File(file_types=[".mid"]),
35
- "text",
36
- gr.Textbox(label="negative prompt"),
37
- gr.Slider(0, 30, value=5, step=5, label="duration (seconds)"),
38
- gr.Number(value=0, label="seed"),
39
- gr.Slider(0.0, 1.0, value=1.0, step=0.1, label="conditioning scale"),
40
- gr.Slider(0, 50, value=20, step=0.1, label="inference steps"),
41
- gr.Checkbox(label="guess mode")
42
- ], outputs="audio", examples=[["S00.mid", "piano", "", 10, 0, 1.0, 20, False]], cache_examples=True, title="🎹 MIDI-AudioLDM", description="MIDI-AudioLDM is a MIDI-conditioned text-to-audio model based on the project [AudioLDM](https://huggingface.co/spaces/haoheliu/audioldm-text-to-audio-generation). The model has been conditioned using the ControlNet architecture and has been developed within Hugging Face’s [🧨 Diffusers](https://huggingface.co/docs/diffusers/) framework. Once trained, MIDI-AudioLDM accepts a MIDI file and a text prompt as inputs and returns an audio file, which is an interpretation of the MIDI based on the given text description. This enables detailed control over different musical aspects such as notes, mood and timbre.", theme=gr.themes.Base())
 
 
 
 
 
 
 
 
 
43
  demo.launch()
 
10
  device = "cpu"
11
  torch_dtype = torch.float32
12
 
13
+ controlnet = ControlNetModel.from_pretrained(
14
+ "lauraibnz/midi-audioldm", torch_dtype=torch_dtype)
15
+ pipe = AudioLDMControlNetPipeline.from_pretrained(
16
+ "cvssp/audioldm-m-full", controlnet=controlnet, torch_dtype=torch_dtype)
17
  pipe = pipe.to(device)
18
  generator = torch.Generator(device)
19
 
20
+
21
  def predict(midi_file=None, prompt="", negative_prompt="", audio_length_in_s=5, random_seed=0, controlnet_conditioning_scale=1, num_inference_steps=20, guess_mode=False):
22
  midi_file = midi_file.name
23
  midi = PrettyMIDI(midi_file)
24
  audio = pipe(
25
  prompt,
26
  negative_prompt=negative_prompt,
27
+ midi=midi,
28
+ audio_length_in_s=audio_length_in_s,
29
+ num_inference_steps=num_inference_steps,
30
  controlnet_conditioning_scale=float(controlnet_conditioning_scale),
31
  guess_mode=guess_mode,
32
  generator=generator.manual_seed(int(random_seed)),
33
  )
34
  return (16000, audio.audios.T)
35
 
36
+
37
+ demo = gr.Interface(
38
+ fn=predict, inputs=[
39
+ gr.File(file_types=[".mid"]),
40
+ "text",
41
+ gr.Textbox(label="negative prompt"),
42
+ gr.Slider(0, 30, value=5, step=5, label="duration (seconds)"),
43
+ gr.Number(value=0, label="seed"),
44
+ gr.Slider(0.0, 1.0, value=1.0, step=0.1, label="conditioning scale"),
45
+ gr.Slider(0, 50, value=20, step=0.1, label="inference steps"),
46
+ gr.Checkbox(label="guess mode")
47
+ ],
48
+ outputs="audio",
49
+ examples=[["S00.mid", "piano", "", 10, 1, 1.0, 20, False]],
50
+ cache_examples=True,
51
+ title="🎹 MIDI-AudioLDM",
52
+ description="MIDI-AudioLDM is a MIDI-conditioned text-to-audio model based on the project [AudioLDM](https://huggingface.co/spaces/haoheliu/audioldm-text-to-audio-generation). The model has been conditioned using the ControlNet architecture and has been developed within Hugging Face’s [🧨 Diffusers](https://huggingface.co/docs/diffusers/) framework. Once trained, MIDI-AudioLDM accepts a MIDI file and a text prompt as inputs and returns an audio file, which is an interpretation of the MIDI based on the given text description. This enables detailed control over different musical aspects such as notes, mood and timbre.",
53
+ theme=gr.themes.Base()
54
+ )
55
  demo.launch()