Benjamin Bossan commited on
Commit
564d114
·
1 Parent(s): ba2892a

Change cwd in app to avoid overriding files

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -4,6 +4,8 @@ This ties together the different parts of the app.
4
 
5
  """
6
 
 
 
7
  from pathlib import Path
8
  from tempfile import mkdtemp
9
  from typing import Literal
@@ -15,6 +17,13 @@ from edit import edit_input_form
15
  from start import start_input_form
16
 
17
 
 
 
 
 
 
 
 
18
  # Create a hf_path, which is where the repo will be created locally. When the
19
  # session is created, copy the dummy cat.png file there and make it the cwd
20
  if "hf_path" not in st.session_state:
 
4
 
5
  """
6
 
7
+ import os
8
+ import shutil
9
  from pathlib import Path
10
  from tempfile import mkdtemp
11
  from typing import Literal
 
17
  from start import start_input_form
18
 
19
 
20
+ # Change cwd to a temporary path
21
+ if "work_dir" not in st.session_state:
22
+ work_dir = Path(mkdtemp(prefix="skops-"))
23
+ shutil.copy2("cat.png", work_dir / "cat.png")
24
+ os.chdir(work_dir)
25
+ st.session_state.work_dir = work_dir
26
+
27
  # Create a hf_path, which is where the repo will be created locally. When the
28
  # session is created, copy the dummy cat.png file there and make it the cwd
29
  if "hf_path" not in st.session_state: