Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#=====================================================
|
| 2 |
+
# https://huggingface.co/spaces/asigalov61/MIDI-Doctor
|
| 3 |
+
#=====================================================
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
Check and heal your MIDI :)
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
# -----------------------------
|
| 10 |
+
# CONFIGURATION & GLOBALS
|
| 11 |
+
# -----------------------------
|
| 12 |
+
SEP = '=' * 70
|
| 13 |
+
PDT = timezone('US/Pacific')
|
| 14 |
+
|
| 15 |
+
# -----------------------------
|
| 16 |
+
# PRINT START-UP INFO
|
| 17 |
+
# -----------------------------
|
| 18 |
+
def print_sep():
|
| 19 |
+
print(SEP)
|
| 20 |
+
|
| 21 |
+
print_sep()
|
| 22 |
+
print("MIDI Doctor Gradio App")
|
| 23 |
+
print_sep()
|
| 24 |
+
print("Loading modules...")
|
| 25 |
+
|
| 26 |
+
import mididoctor
|
| 27 |
+
|
| 28 |
+
print_sep()
|
| 29 |
+
print("Done loading modules!")
|
| 30 |
+
print_sep()
|
| 31 |
+
|
| 32 |
+
# -----------------------------
|
| 33 |
+
# MAIN FUNCTION
|
| 34 |
+
# -----------------------------
|
| 35 |
+
|
| 36 |
+
def Heal_MIDI(input_midi):
|
| 37 |
+
"""
|
| 38 |
+
Heal MIDI
|
| 39 |
+
"""
|
| 40 |
+
print_sep()
|
| 41 |
+
print("Request start time:", datetime.datetime.now(PDT).strftime("%Y-%m-%d %H:%M:%S"))
|
| 42 |
+
|
| 43 |
+
print_sep()
|
| 44 |
+
if input_midi is not None:
|
| 45 |
+
fn = os.path.basename(input_midi.name)
|
| 46 |
+
fn1 = fn.split('.')[0]
|
| 47 |
+
print('Input file name:', fn)
|
| 48 |
+
print_sep())
|
| 49 |
+
|
| 50 |
+
print('Healing MIDI...')
|
| 51 |
+
mididoctor.heal_midi(input_midi.name)
|
| 52 |
+
|
| 53 |
+
out_fname = './healed_midis/'+fn
|
| 54 |
+
|
| 55 |
+
print('Done!')
|
| 56 |
+
print_sep()
|
| 57 |
+
print("Request end time:", datetime.datetime.now(PDT).strftime("%Y-%m-%d %H:%M:%S"))
|
| 58 |
+
print_sep()
|
| 59 |
+
|
| 60 |
+
return out_fname
|
| 61 |
+
|
| 62 |
+
# -----------------------------
|
| 63 |
+
# GRADIO INTERFACE SETUP
|
| 64 |
+
# -----------------------------
|
| 65 |
+
with gr.Blocks() as demo:
|
| 66 |
+
|
| 67 |
+
gr.Markdown("<h1 style='text-align: left; margin-bottom: 1rem'>MIDI Doctor</h1>")
|
| 68 |
+
gr.Markdown("<h1 style='text-align: left; margin-bottom: 1rem'>Check and heal your MIDIs</h1>")
|
| 69 |
+
gr.HTML("""
|
| 70 |
+
Check out <a href="https://github.com/asigalov61/mididoctor">MIDI Doctor</a> on GitHub
|
| 71 |
+
<p>
|
| 72 |
+
<a href="https://huggingface.co/spaces/asigalov61/MIDI-Doctor?duplicate=true">
|
| 73 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-md.svg" alt="Duplicate in Hugging Face">
|
| 74 |
+
</a>
|
| 75 |
+
</p>
|
| 76 |
+
""")
|
| 77 |
+
|
| 78 |
+
gr.Markdown(
|
| 79 |
+
"""
|
| 80 |
+
## MIDI Doctor will check and heal
|
| 81 |
+
* MIDI signature
|
| 82 |
+
* MIDI channels range
|
| 83 |
+
* MIDI pitches range
|
| 84 |
+
* MIDI velocities range
|
| 85 |
+
* MIDI patch changes range
|
| 86 |
+
* Duplicate pitches
|
| 87 |
+
* Excessively short durations
|
| 88 |
+
* Excessively long durations
|
| 89 |
+
* Overlapping durations
|
| 90 |
+
* Text events consistency
|
| 91 |
+
* Excessively quiet dynamics
|
| 92 |
+
"""
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
gr.Markdown("## Upload your MIDI")
|
| 96 |
+
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
| 97 |
+
input_midi.upload()
|
| 98 |
+
|
| 99 |
+
generate_btn = gr.Button("Heal", variant="primary")
|
| 100 |
+
|
| 101 |
+
generated_MIDI_file = gr.File(label="Healed MIDI file")
|
| 102 |
+
|
| 103 |
+
generate_btn.click(
|
| 104 |
+
generate_music,
|
| 105 |
+
[input_midi],
|
| 106 |
+
Heal_MIDI
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
demo.launch()
|