File size: 1,620 Bytes
f773cb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from pyharp import *

from symusic import Synthesizer, BuiltInSF3, dump_wav
import gradio as gr
import audiotools


# Create a ModelCard
model_card = ModelCard(
    name='MIDI Synthesizer',
    description="A MIDI synthesizer example for HARP v3.",
    author='TEAMuP',
    tags=["example", "midi", "synthesizer", "v3"]
)

# Define the process function
def process_fn(
    input_midi_path: str,
    pitch_shift_amount: int
) -> str:

    midi = load_midi(input_midi_path)

    # Create a synthesizer with default settings
    synthesizer = Synthesizer(
        sf_path=BuiltInSF3.MuseScoreGeneral().path(download=True),
        sample_rate=44100,
        quality=4 # Default quality setting
    )

    data = synthesizer.render(midi, stereo=True)
    audio = audiotools.AudioSignal(data, sample_rate=44100)

    output_audio_path = str(save_audio(audio))

    return output_audio_path

# Build Gradio endpoint
with gr.Blocks() as demo:
    # Define input Gradio Components
    input_components = [
        gr.File(type="filepath",
                label="Input Midi",
                file_types=[".mid", ".midi"])
        .harp_required(True),
    ]

    # Define output Gradio Components
    output_components = [
        gr.Audio(type="filepath",
                label="Output Audio")
        .set_info("The synthesized audio."),
    ]

    # Build a HARP-compatible endpoint
    app = build_endpoint(
        model_card=model_card,
        input_components=input_components,
        output_components=output_components,
        process_fn=process_fn,
    )

demo.queue().launch(share=True, show_error=False, pwa=True)