Spaces:
Sleeping
Sleeping
Add Dockerfile, app.py, and example.mei
Browse files- Dockerfile +29 -0
- app.py +31 -0
- example.mei +28 -0
Dockerfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
# Install system dependencies
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
git cmake g++ pkg-config curl \
|
| 6 |
+
libglib2.0-dev libxml2-dev libzip-dev zlib1g-dev \
|
| 7 |
+
libfreetype6-dev libpng-dev \
|
| 8 |
+
libfmt-dev libspdlog-dev \
|
| 9 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
+
|
| 11 |
+
# Clone Verovio and checkout tag
|
| 12 |
+
WORKDIR /verovio
|
| 13 |
+
RUN git clone https://github.com/rism-digital/verovio.git .
|
| 14 |
+
RUN git checkout tags/version-5.1.0 --detach
|
| 15 |
+
|
| 16 |
+
# Build Verovio from tools/, using cmake/
|
| 17 |
+
WORKDIR /verovio/tools
|
| 18 |
+
RUN cmake ../cmake -DCMAKE_BUILD_TYPE=Release
|
| 19 |
+
RUN make -j$(nproc)
|
| 20 |
+
RUN make install
|
| 21 |
+
|
| 22 |
+
# Set up Gradio app
|
| 23 |
+
WORKDIR /app
|
| 24 |
+
COPY app.py .
|
| 25 |
+
COPY example.mei .
|
| 26 |
+
RUN pip install gradio
|
| 27 |
+
|
| 28 |
+
EXPOSE 7860
|
| 29 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import uuid
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def render_mei(mei_code):
|
| 7 |
+
temp_in = f"/tmp/{uuid.uuid4()}.mei"
|
| 8 |
+
temp_out = temp_in.replace(".mei", ".svg")
|
| 9 |
+
|
| 10 |
+
with open(temp_in, "w") as f:
|
| 11 |
+
f.write(mei_code)
|
| 12 |
+
|
| 13 |
+
subprocess.run(["verovio", temp_in, "-o", temp_out])
|
| 14 |
+
|
| 15 |
+
with open(temp_out, "r") as f:
|
| 16 |
+
svg = f.read()
|
| 17 |
+
|
| 18 |
+
return svg
|
| 19 |
+
|
| 20 |
+
with open("example.mei") as f:
|
| 21 |
+
default_mei = f.read()
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=render_mei,
|
| 25 |
+
inputs=gr.Textbox(lines=20, label="Enter MEI", value=default_mei),
|
| 26 |
+
outputs=gr.HTML(label="Rendered SVG Score"),
|
| 27 |
+
title="Verovio MEI Viewer"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
example.mei
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<mei xmlns="http://www.music-encoding.org/ns/mei" meiversion="4.0.0">
|
| 3 |
+
<music>
|
| 4 |
+
<body>
|
| 5 |
+
<mdiv>
|
| 6 |
+
<score>
|
| 7 |
+
<scoreDef>
|
| 8 |
+
<staffGrp>
|
| 9 |
+
<staffDef n="1" lines="5"/>
|
| 10 |
+
</staffGrp>
|
| 11 |
+
</scoreDef>
|
| 12 |
+
<section>
|
| 13 |
+
<measure n="1">
|
| 14 |
+
<staff n="1">
|
| 15 |
+
<layer n="1">
|
| 16 |
+
<note pname="c" oct="4" dur="4"/>
|
| 17 |
+
<note pname="d" oct="4" dur="4"/>
|
| 18 |
+
<note pname="e" oct="4" dur="4"/>
|
| 19 |
+
<note pname="f" oct="4" dur="4"/>
|
| 20 |
+
</layer>
|
| 21 |
+
</staff>
|
| 22 |
+
</measure>
|
| 23 |
+
</section>
|
| 24 |
+
</score>
|
| 25 |
+
</mdiv>
|
| 26 |
+
</body>
|
| 27 |
+
</music>
|
| 28 |
+
</mei>
|