Simon Strandgaard
commited on
Commit
·
56f6df1
1
Parent(s):
60e8dd8
BrowserState's secret is no longer hardcoded, but use the HUGGINGFACE_SPACES_BROWSERSTATE_SECRET env.
Browse files- app.py +1 -5
- src/plan/app_text2plan.py +6 -2
app.py
CHANGED
@@ -1,13 +1,9 @@
|
|
1 |
"""
|
2 |
During development, to mimic the same behavior as on Hugging Face Spaces.
|
3 |
-
PROMPT> IS_HUGGINGFACE_SPACES=true python app.py
|
4 |
|
5 |
TEST-COMMIT: to make hugging face spaces rebuild. Again.
|
6 |
"""
|
7 |
if __name__ == "__main__":
|
8 |
-
# from src.huggingface_spaces.print_gradio_info import print_gradio_info
|
9 |
-
# print_gradio_info()
|
10 |
from src.plan.app_text2plan import run_app_text2plan
|
11 |
run_app_text2plan()
|
12 |
-
# from src.huggingface_spaces.app_state4 import demo
|
13 |
-
# demo.launch()
|
|
|
1 |
"""
|
2 |
During development, to mimic the same behavior as on Hugging Face Spaces.
|
3 |
+
PROMPT> IS_HUGGINGFACE_SPACES=true HUGGINGFACE_SPACES_BROWSERSTATE_SECRET=random123 python app.py
|
4 |
|
5 |
TEST-COMMIT: to make hugging face spaces rebuild. Again.
|
6 |
"""
|
7 |
if __name__ == "__main__":
|
|
|
|
|
8 |
from src.plan.app_text2plan import run_app_text2plan
|
9 |
run_app_text2plan()
|
|
|
|
src/plan/app_text2plan.py
CHANGED
@@ -3,7 +3,7 @@ Start the UI in single user mode.
|
|
3 |
PROMPT> python -m src.plan.app_text2plan
|
4 |
|
5 |
Start the UI in multi user mode, as on: Hugging Face Spaces.
|
6 |
-
PROMPT> IS_HUGGINGFACE_SPACES=true python -m src.plan.app_text2plan
|
7 |
"""
|
8 |
import gradio as gr
|
9 |
import os
|
@@ -25,6 +25,7 @@ from src.prompt.prompt_catalog import PromptCatalog
|
|
25 |
from src.purge.purge_old_runs import start_purge_scheduler
|
26 |
from src.utils.get_env_as_string import get_env_as_string
|
27 |
from src.huggingface_spaces.is_huggingface_spaces import is_huggingface_spaces
|
|
|
28 |
from src.utils.time_since_last_modification import time_since_last_modification
|
29 |
|
30 |
# Slightly different behavior when running inside Hugging Face Spaces, where it's not possible to open a file explorer.
|
@@ -40,6 +41,7 @@ class Config:
|
|
40 |
allow_only_openrouter_models: bool
|
41 |
run_planner_check_api_key_is_provided: bool
|
42 |
enable_purge_old_runs: bool
|
|
|
43 |
|
44 |
CONFIG_LOCAL = Config(
|
45 |
use_uuid_as_run_id=False,
|
@@ -49,6 +51,7 @@ CONFIG_LOCAL = Config(
|
|
49 |
allow_only_openrouter_models=False,
|
50 |
run_planner_check_api_key_is_provided=False,
|
51 |
enable_purge_old_runs=False,
|
|
|
52 |
)
|
53 |
CONFIG_HUGGINGFACE_SPACES = Config(
|
54 |
use_uuid_as_run_id=True,
|
@@ -58,6 +61,7 @@ CONFIG_HUGGINGFACE_SPACES = Config(
|
|
58 |
allow_only_openrouter_models=True,
|
59 |
run_planner_check_api_key_is_provided=True,
|
60 |
enable_purge_old_runs=True,
|
|
|
61 |
)
|
62 |
|
63 |
CONFIG = CONFIG_HUGGINGFACE_SPACES if IS_HUGGINGFACE_SPACES else CONFIG_LOCAL
|
@@ -471,7 +475,7 @@ with gr.Blocks(title="PlanExe") as demo_text2plan:
|
|
471 |
|
472 |
# Manage the state of the current user
|
473 |
session_state = gr.State(SessionState())
|
474 |
-
browser_state = gr.BrowserState("", storage_key="
|
475 |
|
476 |
# Submit and Retry buttons call run_planner and update the state.
|
477 |
submit_btn.click(
|
|
|
3 |
PROMPT> python -m src.plan.app_text2plan
|
4 |
|
5 |
Start the UI in multi user mode, as on: Hugging Face Spaces.
|
6 |
+
PROMPT> IS_HUGGINGFACE_SPACES=true HUGGINGFACE_SPACES_BROWSERSTATE_SECRET=random123 python -m src.plan.app_text2plan
|
7 |
"""
|
8 |
import gradio as gr
|
9 |
import os
|
|
|
25 |
from src.purge.purge_old_runs import start_purge_scheduler
|
26 |
from src.utils.get_env_as_string import get_env_as_string
|
27 |
from src.huggingface_spaces.is_huggingface_spaces import is_huggingface_spaces
|
28 |
+
from src.huggingface_spaces.huggingface_spaces_browserstate_secret import huggingface_spaces_browserstate_secret
|
29 |
from src.utils.time_since_last_modification import time_since_last_modification
|
30 |
|
31 |
# Slightly different behavior when running inside Hugging Face Spaces, where it's not possible to open a file explorer.
|
|
|
41 |
allow_only_openrouter_models: bool
|
42 |
run_planner_check_api_key_is_provided: bool
|
43 |
enable_purge_old_runs: bool
|
44 |
+
browser_state_secret: str
|
45 |
|
46 |
CONFIG_LOCAL = Config(
|
47 |
use_uuid_as_run_id=False,
|
|
|
51 |
allow_only_openrouter_models=False,
|
52 |
run_planner_check_api_key_is_provided=False,
|
53 |
enable_purge_old_runs=False,
|
54 |
+
browser_state_secret=None, # Not used in local mode
|
55 |
)
|
56 |
CONFIG_HUGGINGFACE_SPACES = Config(
|
57 |
use_uuid_as_run_id=True,
|
|
|
61 |
allow_only_openrouter_models=True,
|
62 |
run_planner_check_api_key_is_provided=True,
|
63 |
enable_purge_old_runs=True,
|
64 |
+
browser_state_secret=huggingface_spaces_browserstate_secret(),
|
65 |
)
|
66 |
|
67 |
CONFIG = CONFIG_HUGGINGFACE_SPACES if IS_HUGGINGFACE_SPACES else CONFIG_LOCAL
|
|
|
475 |
|
476 |
# Manage the state of the current user
|
477 |
session_state = gr.State(SessionState())
|
478 |
+
browser_state = gr.BrowserState("", storage_key="PlanExeStorage1", secret=CONFIG.browser_state_secret)
|
479 |
|
480 |
# Submit and Retry buttons call run_planner and update the state.
|
481 |
submit_btn.click(
|