Spaces:
Sleeping
Sleeping
| import verovio | |
| import gradio as gr | |
| import os | |
| def get_verovio_resource_path(): | |
| for path in verovio.__path__: | |
| candidate = os.path.join(path, "data") | |
| if os.path.exists(candidate): | |
| return candidate | |
| return None | |
| def render_mei(mei_path): | |
| tk = verovio.toolkit() | |
| # Set resource path explicitly | |
| resource_path = get_verovio_resource_path() | |
| print(f"resource path: {os.listdir(resource_path)}") | |
| print("[Debug] Using resource path:", resource_path) | |
| if resource_path: | |
| try: | |
| tk.setResourcePath(resource_path) | |
| except Exception as e: | |
| print("[Error] Failed to set resourcePath:", e) | |
| # print(tk.getOptions()) | |
| options = {"pageHeight": 2000, "pageWidth": 3000, "scale": 60, "header": "none"} | |
| tk.setOptions(options) | |
| tk.redoLayout() | |
| with open(mei_path, "r", encoding="utf-8") as f: | |
| mei_data = f.read() | |
| try: | |
| tk.loadData(mei_data) | |
| res = tk.renderToSVG(1) | |
| return res | |
| except Exception as e: | |
| return f"<pre>Rendering failed:\n{e}</pre>" | |
| gr.Interface(fn=render_mei, inputs=gr.File(type="filepath"), outputs=gr.HTML()).launch( | |
| server_name="0.0.0.0", server_port=7860 | |
| ) | |