Alvaro del Castillo
commited on
Commit
·
d3340ef
1
Parent(s):
0a05e15
Initial Audiveris Space
Browse files- Dockerfile +46 -0
- README.md +7 -5
- app.py +38 -0
Dockerfile
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 || apt-get install -y -f && \
|
10 |
+
apt-get clean
|
11 |
+
|
12 |
+
|
13 |
+
## Download and install Audiveris deb package once patched
|
14 |
+
|
15 |
+
RUN wget https://github.com/Audiveris/audiveris/releases/download/5.6.1/Audiveris-5.6.1-ubuntu24.04-x86_64.deb
|
16 |
+
|
17 |
+
## Patch the deb package to work without GUI
|
18 |
+
# Unpack the .deb
|
19 |
+
RUN dpkg-deb -R Audiveris-5.6.1-ubuntu24.04-x86_64.deb /tmp/audiveris
|
20 |
+
|
21 |
+
# Disable post-install script (replace with no-op)
|
22 |
+
RUN echo -e '#!/bin/sh\nexit 0' > /tmp/audiveris/DEBIAN/postinst
|
23 |
+
RUN chmod +x /tmp/audiveris/DEBIAN/postinst
|
24 |
+
|
25 |
+
# Repack the deb
|
26 |
+
RUN dpkg-deb -b /tmp/audiveris /tmp/audiveris-fixed.deb
|
27 |
+
|
28 |
+
# Install the modified deb
|
29 |
+
RUN apt-get install --fix-missing -y /tmp/audiveris-fixed.deb || apt-get install --fix-missing -y -f
|
30 |
+
|
31 |
+
|
32 |
+
RUN rm Audiveris-5.6.1-ubuntu24.04-x86_64.deb
|
33 |
+
|
34 |
+
## Install Gradio MCP
|
35 |
+
RUN apt-get install --fix-missing -y python3 python3-pip || apt-get install -y -f
|
36 |
+
# TODO: use a python virtual environment
|
37 |
+
RUN pip install --break-system-packages gradio[mcp]
|
38 |
+
|
39 |
+
## Clean
|
40 |
+
RUN apt-get clean
|
41 |
+
|
42 |
+
## Copy MCP server and execute it
|
43 |
+
COPY app.py /app/app.py
|
44 |
+
WORKDIR /app
|
45 |
+
|
46 |
+
CMD ["python3", "app.py"]
|
README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 💻
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk:
|
|
|
|
|
7 |
pinned: false
|
8 |
license: apache-2.0
|
9 |
-
short_description:
|
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: gradio
|
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 |
---
|
13 |
|
14 |
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 |
+
|