Alvaro del Castillo commited on
Commit
43f7000
·
1 Parent(s): 694faf2

Initial version

Browse files
Files changed (3) hide show
  1. Dockerfile +45 -0
  2. README.md +8 -5
  3. app.py +38 -0
Dockerfile ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:24.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+
5
+ ## Install dependencies
6
+ RUN rm -rf /var/lib/apt/lists/* && \
7
+ apt-get clean && \
8
+ apt-get update && \
9
+ apt-get install --fix-missing -y wget unzip curl || apt-get install -y -f && \
10
+ apt-get clean
11
+
12
+ ## Download and install Audiveris deb package once patched
13
+
14
+ RUN wget https://github.com/Audiveris/audiveris/releases/download/5.6.1/Audiveris-5.6.1-ubuntu24.04-x86_64.deb
15
+
16
+ ## Patch the deb package to work without GUI
17
+ # Unpack the .deb
18
+ RUN dpkg-deb -R Audiveris-5.6.1-ubuntu24.04-x86_64.deb /tmp/audiveris
19
+
20
+ # Disable post-install script (replace with no-op)
21
+ RUN echo -e '#!/bin/sh\nexit 0' > /tmp/audiveris/DEBIAN/postinst
22
+ RUN chmod +x /tmp/audiveris/DEBIAN/postinst
23
+
24
+ # Repack the deb
25
+ RUN dpkg-deb -b /tmp/audiveris /tmp/audiveris-fixed.deb
26
+
27
+ # Install the modified deb
28
+ RUN apt-get install --fix-missing -y /tmp/audiveris-fixed.deb || apt-get install --fix-missing -y -f
29
+
30
+
31
+ RUN rm Audiveris-5.6.1-ubuntu24.04-x86_64.deb
32
+
33
+ ## Install Gradio MCP
34
+ RUN apt-get install --fix-missing -y python3 python3-pip || apt-get install -y -f
35
+ # TODO: use a python virtual environment
36
+ RUN pip install --break-system-packages gradio[mcp]
37
+
38
+ ## Clean
39
+ RUN apt-get clean
40
+
41
+ ## Copy MCP server and execute it
42
+ COPY app.py /app/app.py
43
+ WORKDIR /app
44
+
45
+ CMD ["python3", "app.py"]
README.md CHANGED
@@ -1,12 +1,15 @@
1
  ---
2
- title: Audiveris
3
- emoji: 📊
4
- colorFrom: red
5
- colorTo: indigo
6
  sdk: docker
 
 
7
  pinned: false
8
  license: apache-2.0
9
- short_description: Music PDF file to MusicXML converter
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Scores
3
+ emoji: 💻
4
+ colorFrom: pink
5
+ colorTo: red
6
  sdk: docker
7
+ sdk_version: 5.32.0
8
+ app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
+ short_description: Analyze music scores from PDF files
12
+ app_port: 7860
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
+
5
+ def recognize_music(pdf_file):
6
+ """Converts a PDF file to a Music score
7
+
8
+ Args:
9
+ pdf_file: the file with the PDF file
10
+
11
+ Returns:
12
+ the path were the MusicXML file is generated
13
+ """
14
+ audiveris = "/opt/audiveris/bin/Audiveris"
15
+ output_dir = "/tmp/output"
16
+ pdf_file_path = pdf_file.name
17
+ pdf_file_name = os.path.basename(pdf_file.name)
18
+ musicXml_file_name = os.path.splitext(pdf_file_name)[0]+".mxl"
19
+ output_file = output_dir + "/" + musicXml_file_name
20
+
21
+ cmd = [
22
+ audiveris, "-batch", "-export", "-output", output_dir, pdf_file_path
23
+ ]
24
+
25
+ result = subprocess.run(cmd, capture_output=True, text=True)
26
+
27
+ print (f"Done. Music score file saved to {output_file}\n\n{result.stdout}\n{result.stderr}")
28
+
29
+ return output_file
30
+
31
+ audiveris = gr.Interface(
32
+ fn=recognize_music,
33
+ inputs=gr.File(file_types=[".pdf"], label="Upload PDF music score"),
34
+ outputs=gr.File(label="Download MusicXML file"),
35
+ description="Upload a PDF music socre and create a MusicXML file from it.",
36
+ )
37
+ audiveris.launch(server_name="0.0.0.0", mcp_server=True)
38
+