pachet commited on
Commit
f3df7ae
·
1 Parent(s): 0535b3d

Update Dockerfile and app.py

Browse files
Files changed (2) hide show
  1. Dockerfile +11 -26
  2. app.py +30 -14
Dockerfile CHANGED
@@ -1,34 +1,19 @@
1
- # Use a Python 3.11 base image
2
- FROM python:3.11-slim
3
 
4
- # Install necessary dependencies for building Verovio and Python bindings
5
  RUN apt-get update && apt-get install -y \
6
- git cmake g++ pkg-config curl swig make \
7
- libglib2.0-dev libxml2-dev libzip-dev \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
- # Clone the Verovio repository and its submodules
11
- WORKDIR /verovio
12
- RUN git clone --recurse-submodules https://github.com/rism-digital/verovio.git .
13
-
14
- # Build the command-line tool (Verovio C++ code)
15
- WORKDIR /verovio/tools
16
- RUN cmake ../cmake -DWITH_PYTHON=ON -DCMAKE_BUILD_TYPE=Release \
17
- && make -j$(nproc) \
18
- && make install
19
-
20
- # Build and install the Python bindings for Verovio
21
- WORKDIR /verovio
22
- RUN python3 setup.py build_ext --inplace \
23
- && python3 setup.py install
24
-
25
- # Install Python dependencies (gradio, etc.)
26
  RUN pip install gradio
27
 
28
- # Set up the working directory for your app
29
  WORKDIR /app
30
- COPY app.py example.mei /app/
 
31
 
32
- # Expose port 7860 and run the app
33
- EXPOSE 7860
34
- CMD ["python", "app.py"]
 
1
+ FROM python:3.12-slim
 
2
 
3
+ # Install pip + Gradio dependencies
4
  RUN apt-get update && apt-get install -y \
5
+ swig g++ cmake make \
6
+ libglib2.0-0 libxml2 libzip4 libcurl4 \
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
+ # Install Python packages
10
+ RUN pip install --upgrade pip
11
+ RUN pip install verovio
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  RUN pip install gradio
13
 
14
+ # Copy app and MEI file
15
  WORKDIR /app
16
+ COPY app.py .
17
+ COPY example.mei .
18
 
19
+ CMD ["python3", "app.py"]
 
 
app.py CHANGED
@@ -1,20 +1,36 @@
1
- import gradio as gr
2
  import verovio
 
 
 
 
 
 
 
 
 
3
 
4
- def render_mei(mei_code):
5
  tk = verovio.toolkit()
6
- tk.loadData(mei_code)
7
- return tk.renderToSVG()
8
 
9
- with open("example.mei") as f:
10
- default_mei = f.read()
 
 
 
 
 
 
 
11
 
12
- demo = gr.Interface(
13
- fn=render_mei,
14
- inputs=gr.Textbox(lines=20, label="MEI Input", value=default_mei),
15
- outputs=gr.HTML(label="Rendered SVG"),
16
- title="Verovio Score Renderer (via verovio)"
17
- )
 
 
18
 
19
- if __name__ == "__main__":
20
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
1
  import verovio
2
+ import gradio as gr
3
+ import os
4
+
5
+ def get_verovio_resource_path():
6
+ for path in verovio.__path__:
7
+ candidate = os.path.join(path, "data")
8
+ if os.path.exists(candidate):
9
+ return candidate
10
+ return None
11
 
12
+ def render_mei(mei_path):
13
  tk = verovio.toolkit()
 
 
14
 
15
+ # Set resource path explicitly
16
+ resource_path = get_verovio_resource_path()
17
+ print("[Debug] Using resource path:", resource_path)
18
+ if resource_path:
19
+ try:
20
+ tk.setResourcePath(resource_path)
21
+ # tk.setOptions({ "resourcePath": resource_path })
22
+ except Exception as e:
23
+ print("[Error] Failed to set resourcePath:", e)
24
 
25
+ with open(mei_path, "r", encoding="utf-8") as f:
26
+ mei_data = f.read()
27
+
28
+ try:
29
+ tk.loadData(mei_data)
30
+ return tk.renderToSVG(1)
31
+ except Exception as e:
32
+ return f"<pre>Rendering failed:\n{e}</pre>"
33
 
34
+ gr.Interface(fn=render_mei, inputs=gr.File(type="filepath"), outputs=gr.HTML()).launch(
35
+ server_name="0.0.0.0", server_port=7860
36
+ )