|
import gradio as gr |
|
import subprocess |
|
import os |
|
|
|
def recognize_music(pdf_file): |
|
"""Converts a PDF file to a Music score |
|
|
|
Args: |
|
pdf_file: the file with the PDF file |
|
|
|
Returns: |
|
the path were the MusicXML file is generated |
|
""" |
|
audiveris = "/opt/audiveris/bin/Audiveris" |
|
output_dir = "/tmp/output" |
|
pdf_file_path = pdf_file.name |
|
pdf_file_name = os.path.basename(pdf_file.name) |
|
musicXml_file_name = os.path.splitext(pdf_file_name)[0]+".mxl" |
|
output_file = output_dir + "/" + musicXml_file_name |
|
|
|
cmd = [ |
|
audiveris, "-batch", "-export", "-output", output_dir, pdf_file_path |
|
] |
|
|
|
result = subprocess.run(cmd, capture_output=True, text=True) |
|
|
|
print (f"Done. Music score file saved to {output_file}\n\n{result.stdout}\n{result.stderr}") |
|
|
|
return output_file |
|
|
|
audiveris = gr.Interface( |
|
fn=recognize_music, |
|
inputs=gr.File(file_types=[".pdf"], label="Upload PDF music score"), |
|
outputs=gr.File(label="Download MusicXML file"), |
|
description="Upload a PDF music socre and create a MusicXML file from it.", |
|
) |
|
audiveris.launch(server_name="0.0.0.0", mcp_server=True, share=True) |
|
|
|
|