Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -19,6 +19,43 @@ from __future__ import annotations
|
|
| 19 |
import spaces # noqa: F401 (must come before torch; see module docstring)
|
| 20 |
|
| 21 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
import tempfile
|
| 23 |
|
| 24 |
import matplotlib
|
|
@@ -31,10 +68,6 @@ import partitura
|
|
| 31 |
from drum_dynamics.serve.models import Engine
|
| 32 |
from drum_dynamics.viz.playback import set_soundfont, _ensure_fluidsynth_discoverable
|
| 33 |
|
| 34 |
-
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 35 |
-
SF2 = os.path.join(HERE, "sf", "FluidR3_GM.sf2")
|
| 36 |
-
SR = 44100
|
| 37 |
-
|
| 38 |
# --- load once at module scope ------------------------------------------------
|
| 39 |
ENGINE = Engine.load(os.path.join(HERE, "models"))
|
| 40 |
LEVELS = ENGINE.levels()
|
|
|
|
| 19 |
import spaces # noqa: F401 (must come before torch; see module docstring)
|
| 20 |
|
| 21 |
import os
|
| 22 |
+
|
| 23 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 24 |
+
SF2 = os.path.join(HERE, "sf", "FluidR3_GM.sf2")
|
| 25 |
+
SR = 44100
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _preseed_partitura_soundfont() -> None:
|
| 29 |
+
"""Stop partitura from FTP-downloading a soundfont at import time.
|
| 30 |
+
|
| 31 |
+
partitura's top-level ``__init__`` imports its audio-export module, which -
|
| 32 |
+
when fluidsynth is importable and its bundled asset is missing - fetches a
|
| 33 |
+
MuseScore soundfont over FTP. HF Spaces block FTP egress, so that call hangs
|
| 34 |
+
and the app crashes on ``import partitura``. Pre-seed the asset (symlink our
|
| 35 |
+
bundled GM soundfont) so partitura finds it and skips the download. Must run
|
| 36 |
+
BEFORE ``import partitura``.
|
| 37 |
+
"""
|
| 38 |
+
import importlib.util
|
| 39 |
+
|
| 40 |
+
spec = importlib.util.find_spec("partitura") # locate without importing
|
| 41 |
+
if not spec or not spec.origin:
|
| 42 |
+
return
|
| 43 |
+
assets = os.path.join(os.path.dirname(spec.origin), "assets")
|
| 44 |
+
target = os.path.join(assets, "MuseScore_General.sf3")
|
| 45 |
+
if os.path.exists(target):
|
| 46 |
+
return
|
| 47 |
+
try:
|
| 48 |
+
os.makedirs(assets, exist_ok=True)
|
| 49 |
+
if os.path.exists(SF2):
|
| 50 |
+
os.symlink(SF2, target)
|
| 51 |
+
else:
|
| 52 |
+
open(target, "wb").close() # placeholder; partitura's synth is unused
|
| 53 |
+
except OSError:
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
_preseed_partitura_soundfont()
|
| 58 |
+
|
| 59 |
import tempfile
|
| 60 |
|
| 61 |
import matplotlib
|
|
|
|
| 68 |
from drum_dynamics.serve.models import Engine
|
| 69 |
from drum_dynamics.viz.playback import set_soundfont, _ensure_fluidsynth_discoverable
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# --- load once at module scope ------------------------------------------------
|
| 72 |
ENGINE = Engine.load(os.path.join(HERE, "models"))
|
| 73 |
LEVELS = ENGINE.levels()
|