Hygee commited on
Commit
e717139
·
verified ·
1 Parent(s): 755c02f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirement.txt +5 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from unidecode import unidecode
4
+ from musc.model import PretrainedModel
5
+ from unidecode import unidecode
6
+ import os
7
+ import sys
8
+ import torch
9
+ import json
10
+ #from yt_dlp import YoutubeDL
11
+ sys.path.append('MUSC_violin')
12
+ from MUSC_violin import musc
13
+
14
+ # Function to transcribe the WAV file and generate the MIDI file
15
+ def transcribe_and_generate_midi(wav_file_path, model, batch_size=32, postprocessing='spotify'):
16
+ midi, _, title = model.transcribe_wav(wav_file_path, batch_size=batch_size, postprocessing=postprocessing)
17
+
18
+ # Write the MIDI file
19
+ midi_file_name = unidecode(title) + '.mid'
20
+ midi.write(midi_file_name)
21
+
22
+ return midi_file_name, title
23
+
24
+ # Set up the Pretrained Model
25
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
26
+ model = PretrainedModel(instrument='violin').to(device)
27
+
28
+ # Streamlit UI
29
+ st.title("Violin to MIDI Converter")
30
+
31
+ uploaded_file = st.file_uploader("Upload your WAV file", type=["wav"])
32
+
33
+ if uploaded_file is not None:
34
+ st.write("File Uploaded Successfully!")
35
+ st.audio(uploaded_file, format='audio/wav')
36
+
37
+ if st.button("Convert to MIDI"):
38
+ try:
39
+ midi_file_name, title = transcribe_and_generate_midi(uploaded_file, model)
40
+ st.success(f"MIDI file generated successfully: {midi_file_name}")
41
+ st.audio(midi_file_name, format='audio/midi', label='Download MIDI')
42
+ except Exception as e:
43
+ st.error(f"Error: {str(e)}")
44
+ else:
45
+ st.info("Please upload a WAV file to convert to MIDI.")
requirement.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ yt-dlp
2
+ mir_eval
3
+ pretty_midi
4
+ unidecode
5
+ streamlit