File size: 1,762 Bytes
5c3b728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from pyharp import *

import gradio as gr


model_card = ModelCard(
    name='MIDI Pitch Shifter',
    description='Use the slider to shift the pitch of the input MIDI file.',
    author='xribene',
    tags=['midi', 'pitch', 'shift'],
    midi_in=True,
    midi_out=True
)

# <YOUR MODEL INITIALIZATION CODE HERE>


def process_fn(input_midi_path, pitch_shift_amount):
    """
    This function defines the MIDI processing steps
    Args:
        input_midi_path (str): the MIDI filepath to be processed.
        <YOUR_KWARGS>: additional keyword arguments necessary for processing.
            NOTE: These should correspond to and match order of UI elements defined below.
    Returns:
        output_midi_path (str): the filepath of the processed MIDI.
    """

    """
    <YOUR MIDI LOADING CODE HERE>
    # Load MIDI at specified path using symusic
    """
    midi = load_midi(input_midi_path)

    """
    <YOUR MIDI PROCESSING CODE HERE>
    # Perform a trivial operation (i.e. pitch-shifting)
    """
    for t in midi.tracks:
        for n in t.notes:
            n.pitch += int(pitch_shift_amount)

    """
    <YOUR MIDI SAVING CODE HERE>
    # Save processed MIDI and obtain default path
    """
    output_midi_path = save_midi(midi, None)

    return output_midi_path


# Build Gradio endpoint
with gr.Blocks() as demo:
    # Define Gradio Components
    components = [
        gr.Slider(
            minimum=-24, 
            maximum=24, 
            step=1, 
            value=0, 
            label="Pitch Shift (semitones)"
        ),
    ]

    # Build endpoint
    app = build_endpoint(model_card=model_card,
                         components=components,
                         process_fn=process_fn)

demo.queue()
demo.launch(share=True)