Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from diffusers import AudioLDMControlNetPipeline, ControlNetModel
|
|
|
3 |
from pretty_midi import PrettyMIDI
|
|
|
4 |
import torch
|
5 |
import torchaudio
|
6 |
|
@@ -20,7 +22,8 @@ generator = torch.Generator(device)
|
|
20 |
|
21 |
|
22 |
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):
|
23 |
-
|
|
|
24 |
midi = PrettyMIDI(midi_file)
|
25 |
audio = pipe(
|
26 |
prompt,
|
@@ -56,7 +59,7 @@ with gr.Blocks(title="🎹 MIDI-AudioLDM", theme=gr.themes.Base(text_size=gr.the
|
|
56 |
guess = gr.Checkbox(label="guess mode")
|
57 |
btn = gr.Button("Generate")
|
58 |
btn.click(predict, inputs=[midi, prompt, neg_prompt, duration, seed, cond, inf, guess], outputs=[audio])
|
59 |
-
gr.Examples(examples=[[
|
60 |
|
61 |
# demo = gr.Interface(
|
62 |
# fn=predict, inputs=[
|
|
|
1 |
import gradio as gr
|
2 |
from diffusers import AudioLDMControlNetPipeline, ControlNetModel
|
3 |
+
import os
|
4 |
from pretty_midi import PrettyMIDI
|
5 |
+
import tempfile
|
6 |
import torch
|
7 |
import torchaudio
|
8 |
|
|
|
22 |
|
23 |
|
24 |
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):
|
25 |
+
if not os.path.exists(midi_file):
|
26 |
+
midi_file = midi_file.name
|
27 |
midi = PrettyMIDI(midi_file)
|
28 |
audio = pipe(
|
29 |
prompt,
|
|
|
59 |
guess = gr.Checkbox(label="guess mode")
|
60 |
btn = gr.Button("Generate")
|
61 |
btn.click(predict, inputs=[midi, prompt, neg_prompt, duration, seed, cond, inf, guess], outputs=[audio])
|
62 |
+
gr.Examples(examples=[["S00.mid", "piano", "", 10, 25, 1.0, 20, False]], inputs=[midi, prompt, neg_prompt, duration, seed, cond, inf, guess], fn=predict, outputs=audio)
|
63 |
|
64 |
# demo = gr.Interface(
|
65 |
# fn=predict, inputs=[
|