Simon Strandgaard commited on
Commit
ec06ad9
·
1 Parent(s): 7492910

generate_run_id() added

Browse files
src/plan/app_text2plan.py CHANGED
@@ -7,13 +7,13 @@ import subprocess
7
  import time
8
  import sys
9
  import threading
10
- from datetime import datetime
11
  from math import ceil
12
  import shutil
13
  import zipfile
14
  import copy
15
 
16
  from src.llm_factory import get_available_llms
 
17
  from src.plan.filenames import FilenameEnum
18
  from src.plan.plan_file import PlanFile
19
  from src.plan.speedvsdetail import SpeedVsDetailEnum
@@ -156,7 +156,9 @@ def run_planner(submit_or_retry_button, plan_prompt, llm_model, speedvsdetail, s
156
  raise Exception(f"The run path is supposed to exist from an earlier run. However the no run path exists: {run_path}")
157
 
158
  elif submit_or_retry == "submit":
159
- run_id = datetime.now().strftime("%Y%m%d_%H%M%S")
 
 
160
  run_path = os.path.join("run", run_id)
161
  absolute_path_to_run_dir = os.path.abspath(run_path)
162
 
 
7
  import time
8
  import sys
9
  import threading
 
10
  from math import ceil
11
  import shutil
12
  import zipfile
13
  import copy
14
 
15
  from src.llm_factory import get_available_llms
16
+ from src.plan.generate_run_id import generate_run_id
17
  from src.plan.filenames import FilenameEnum
18
  from src.plan.plan_file import PlanFile
19
  from src.plan.speedvsdetail import SpeedVsDetailEnum
 
156
  raise Exception(f"The run path is supposed to exist from an earlier run. However the no run path exists: {run_path}")
157
 
158
  elif submit_or_retry == "submit":
159
+ # use_uuid = True # TODO: determine if the app is running on huggingface spaces
160
+ use_uuid = False
161
+ run_id = generate_run_id(use_uuid)
162
  run_path = os.path.join("run", run_id)
163
  absolute_path_to_run_dir = os.path.abspath(run_path)
164
 
src/plan/generate_run_id.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import uuid
3
+
4
+ def generate_run_id(use_uuid: bool):
5
+ """
6
+ Generates a unique ID, either a UUID or a timestamp.
7
+
8
+ In a multi user environment, use UUID to avoid conflicts.
9
+ In a single user environment, use timestamp for human readability.
10
+ """
11
+ if use_uuid:
12
+ return str(uuid.uuid4())
13
+ else:
14
+ return datetime.now().strftime("%Y%m%d_%H%M%S")
15
+
16
+ if __name__ == "__main__":
17
+ print(generate_run_id(use_uuid=True))
18
+ print(generate_run_id(use_uuid=False))