harp-dev commited on
Commit
fb903a9
·
verified ·
1 Parent(s): ce8de21

Keep the rendered file past process_fn and stop reaching for output_components

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1,7 +1,7 @@
1
  from __future__ import annotations
2
 
3
  from pathlib import Path
4
- from tempfile import TemporaryDirectory
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
- with TemporaryDirectory(prefix="dexter-") as tmp:
31
- output = Path(tmp) / "performance.mid"
32
- try:
33
- render(source, output, int(seed))
34
- except Exception as exc:
35
- raise gr.Error(f"DExter inference failed: {exc}") from exc
36
- return output_components[0].move_resource_to_block_cache(str(output))
 
 
 
 
 
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__":