Spaces:
Running on Zero
Running on Zero
Keep the rendered file past process_fn and stop reaching for output_components
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
from pathlib import Path
|
| 4 |
-
from tempfile import
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
import spaces
|
|
@@ -27,13 +27,18 @@ def process_fn(xml_path: str | None, use_example: bool, seed: int) -> str:
|
|
| 27 |
if not xml_path and not use_example:
|
| 28 |
raise gr.Error("Upload a MusicXML score or select the example.")
|
| 29 |
source = xml_path or str(EXAMPLE)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
from pathlib import Path
|
| 4 |
+
from tempfile import mkdtemp
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
import spaces
|
|
|
|
| 27 |
if not xml_path and not use_example:
|
| 28 |
raise gr.Error("Upload a MusicXML score or select the example.")
|
| 29 |
source = xml_path or str(EXAMPLE)
|
| 30 |
+
# mkdtemp, not a context manager: that would delete the directory on exit,
|
| 31 |
+
# taking the rendered file with it before the caller can read it, which is
|
| 32 |
+
# what the block-cache call here was working around. That also reached for
|
| 33 |
+
# output_components, which exists only under __main__ and so is undefined
|
| 34 |
+
# in the worker process that imports this module.
|
| 35 |
+
output = Path(mkdtemp(prefix="dexter-")) / "performance.mid"
|
| 36 |
+
try:
|
| 37 |
+
render(source, output, int(seed))
|
| 38 |
+
except Exception as exc:
|
| 39 |
+
raise gr.Error(f"DExter inference failed: {exc}") from exc
|
| 40 |
+
|
| 41 |
+
return str(output)
|
| 42 |
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|