Spaces:
Runtime error
Runtime error
Commit ·
f773cb9
1
Parent(s): 6491919
initial commit
Browse files- .gitignore +1 -0
- app.py +63 -0
- requirements.txt +1 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
_outputs
|
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pyharp import *
|
| 2 |
+
|
| 3 |
+
from symusic import Synthesizer, BuiltInSF3, dump_wav
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import audiotools
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Create a ModelCard
|
| 9 |
+
model_card = ModelCard(
|
| 10 |
+
name='MIDI Synthesizer',
|
| 11 |
+
description="A MIDI synthesizer example for HARP v3.",
|
| 12 |
+
author='TEAMuP',
|
| 13 |
+
tags=["example", "midi", "synthesizer", "v3"]
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# Define the process function
|
| 17 |
+
def process_fn(
|
| 18 |
+
input_midi_path: str,
|
| 19 |
+
pitch_shift_amount: int
|
| 20 |
+
) -> str:
|
| 21 |
+
|
| 22 |
+
midi = load_midi(input_midi_path)
|
| 23 |
+
|
| 24 |
+
# Create a synthesizer with default settings
|
| 25 |
+
synthesizer = Synthesizer(
|
| 26 |
+
sf_path=BuiltInSF3.MuseScoreGeneral().path(download=True),
|
| 27 |
+
sample_rate=44100,
|
| 28 |
+
quality=4 # Default quality setting
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
data = synthesizer.render(midi, stereo=True)
|
| 32 |
+
audio = audiotools.AudioSignal(data, sample_rate=44100)
|
| 33 |
+
|
| 34 |
+
output_audio_path = str(save_audio(audio))
|
| 35 |
+
|
| 36 |
+
return output_audio_path
|
| 37 |
+
|
| 38 |
+
# Build Gradio endpoint
|
| 39 |
+
with gr.Blocks() as demo:
|
| 40 |
+
# Define input Gradio Components
|
| 41 |
+
input_components = [
|
| 42 |
+
gr.File(type="filepath",
|
| 43 |
+
label="Input Midi",
|
| 44 |
+
file_types=[".mid", ".midi"])
|
| 45 |
+
.harp_required(True),
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
# Define output Gradio Components
|
| 49 |
+
output_components = [
|
| 50 |
+
gr.Audio(type="filepath",
|
| 51 |
+
label="Output Audio")
|
| 52 |
+
.set_info("The synthesized audio."),
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
# Build a HARP-compatible endpoint
|
| 56 |
+
app = build_endpoint(
|
| 57 |
+
model_card=model_card,
|
| 58 |
+
input_components=input_components,
|
| 59 |
+
output_components=output_components,
|
| 60 |
+
process_fn=process_fn,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
demo.queue().launch(share=True, show_error=False, pwa=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
-e git+https://github.com/TEAMuP-dev/pyharp.git@develop#egg=pyharp
|