Simon Strandgaard commited on
Commit
ff3a23b
·
1 Parent(s): a145e10

Use 2 different configurations depending on if the app runs on localhost or on huggingface spaces

Browse files
Files changed (1) hide show
  1. src/plan/app_text2plan.py +19 -4
src/plan/app_text2plan.py CHANGED
@@ -11,6 +11,7 @@ import subprocess
11
  import time
12
  import sys
13
  import threading
 
14
  from math import ceil
15
  from src.llm_factory import get_available_llms
16
  from src.plan.generate_run_id import generate_run_id
@@ -27,6 +28,22 @@ from src.utils.time_since_last_modification import time_since_last_modification
27
  # And it's multi-user, so we need to keep track of the state for each user.
28
  IS_HUGGINGFACE_SPACES = is_huggingface_spaces()
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  MODULE_PATH_PIPELINE = "src.plan.run_plan_pipeline"
31
  DEFAULT_PROMPT_UUID = "4dc34d55-0d0d-4e9d-92f4-23765f49dd29"
32
 
@@ -148,9 +165,7 @@ def run_planner(submit_or_retry_button, plan_prompt, session_state: SessionState
148
  raise Exception(f"The run path is supposed to exist from an earlier run. However the no run path exists: {run_path}")
149
 
150
  elif submit_or_retry == "submit":
151
- # use_uuid = True # TODO: determine if the app is running on huggingface spaces
152
- use_uuid = False
153
- run_id = generate_run_id(use_uuid)
154
  run_path = os.path.join("run", run_id)
155
  absolute_path_to_run_dir = os.path.abspath(run_path)
156
 
@@ -365,7 +380,7 @@ with gr.Blocks(title="PlanExe") as demo_text2plan:
365
  submit_btn = gr.Button("Submit", variant='primary')
366
  stop_btn = gr.Button("Stop")
367
  retry_btn = gr.Button("Retry")
368
- open_dir_btn = gr.Button("Open Output Dir")
369
 
370
  output_markdown = gr.Markdown("Output will appear here...")
371
  status_markdown = gr.Markdown("Status messages will appear here...")
 
11
  import time
12
  import sys
13
  import threading
14
+ from dataclasses import dataclass
15
  from math import ceil
16
  from src.llm_factory import get_available_llms
17
  from src.plan.generate_run_id import generate_run_id
 
28
  # And it's multi-user, so we need to keep track of the state for each user.
29
  IS_HUGGINGFACE_SPACES = is_huggingface_spaces()
30
 
31
+ @dataclass
32
+ class Config:
33
+ use_uuid_as_run_id: bool
34
+ enable_open_output_dir_button: bool
35
+
36
+ CONFIG_LOCAL = Config(
37
+ use_uuid_as_run_id=False,
38
+ enable_open_output_dir_button=True
39
+ )
40
+ CONFIG_HUGGINGFACE_SPACES = Config(
41
+ use_uuid_as_run_id=True,
42
+ enable_open_output_dir_button=False
43
+ )
44
+
45
+ CONFIG = CONFIG_HUGGINGFACE_SPACES if IS_HUGGINGFACE_SPACES else CONFIG_LOCAL
46
+
47
  MODULE_PATH_PIPELINE = "src.plan.run_plan_pipeline"
48
  DEFAULT_PROMPT_UUID = "4dc34d55-0d0d-4e9d-92f4-23765f49dd29"
49
 
 
165
  raise Exception(f"The run path is supposed to exist from an earlier run. However the no run path exists: {run_path}")
166
 
167
  elif submit_or_retry == "submit":
168
+ run_id = generate_run_id(CONFIG.use_uuid_as_run_id)
 
 
169
  run_path = os.path.join("run", run_id)
170
  absolute_path_to_run_dir = os.path.abspath(run_path)
171
 
 
380
  submit_btn = gr.Button("Submit", variant='primary')
381
  stop_btn = gr.Button("Stop")
382
  retry_btn = gr.Button("Retry")
383
+ open_dir_btn = gr.Button("Open Output Dir", visible=CONFIG.enable_open_output_dir_button)
384
 
385
  output_markdown = gr.Markdown("Output will appear here...")
386
  status_markdown = gr.Markdown("Status messages will appear here...")