TrueAl commited on
Commit
0ec40a9
·
1 Parent(s): 1ba148a

fix for data dir on hf space

Browse files
Files changed (2) hide show
  1. app.py +5 -1
  2. runs.py +6 -0
app.py CHANGED
@@ -26,6 +26,7 @@ from runs import (
26
  RunResult,
27
  create_run,
28
  ensure_data_dirs,
 
29
  load_runs,
30
  save_output_video,
31
  save_run,
@@ -198,4 +199,7 @@ with gr.Blocks(title="Kaleidoscope") as demo:
198
  demo.queue()
199
 
200
  if __name__ == "__main__":
201
- demo.launch()
 
 
 
 
26
  RunResult,
27
  create_run,
28
  ensure_data_dirs,
29
+ get_data_dir,
30
  load_runs,
31
  save_output_video,
32
  save_run,
 
199
  demo.queue()
200
 
201
  if __name__ == "__main__":
202
+ # /data (on a Hugging Face Space) lives outside the cwd and the system
203
+ # temp dir, so Gradio refuses to serve run files from it unless the
204
+ # directory is explicitly allow-listed here.
205
+ demo.launch(allowed_paths=[get_data_dir()])
runs.py CHANGED
@@ -56,6 +56,12 @@ def ensure_data_dirs() -> None:
56
  os.makedirs(RUNS_DIR, exist_ok=True)
57
 
58
 
 
 
 
 
 
 
59
  def create_run(image_path: str) -> tuple[str, str, str]:
60
  """Creates a new run directory and copies the uploaded image into it as the input.
61
 
 
56
  os.makedirs(RUNS_DIR, exist_ok=True)
57
 
58
 
59
+ def get_data_dir() -> str:
60
+ """Returns the data directory actually in use (call after
61
+ ensure_data_dirs(), since it may fall back to a local directory)."""
62
+ return DATA_DIR
63
+
64
+
65
  def create_run(image_path: str) -> tuple[str, str, str]:
66
  """Creates a new run directory and copies the uploaded image into it as the input.
67