Spaces:
Running
Running
Multi page app works.
Browse files- app.py +8 -0
- app/__init__.py +0 -0
- app/streamlit_meta_prompt.py +170 -171
- guidelines/streamlit.md +80 -0
app.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
pg = st.navigation([
|
4 |
+
st.Page("app/streamlit_sample_generator.py", title="Sample Generator", icon=":material/text_snippet:"),
|
5 |
+
st.Page("app/streamlit_meta_prompt.py", title="Meta Prompt", icon=":material/auto_fix_high:"),
|
6 |
+
])
|
7 |
+
|
8 |
+
pg.run()
|
app/__init__.py
ADDED
File without changes
|
app/streamlit_meta_prompt.py
CHANGED
@@ -460,175 +460,174 @@ with st.sidebar:
|
|
460 |
max_output_age_input = st.number_input("Max Output Age", 1, 10, 2, 1)
|
461 |
aggressive_exploration_input = st.checkbox("Aggressive Exploration", False)
|
462 |
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
expert_prompt_initial_developer_model_name_input
|
517 |
-
)
|
518 |
-
expert_prompt_acceptance_criteria_model_name = (
|
519 |
-
expert_prompt_acceptance_criteria_model_name_input
|
520 |
-
)
|
521 |
-
expert_prompt_developer_model_name = expert_prompt_developer_model_name_input
|
522 |
-
expert_prompt_executor_model_name = expert_prompt_executor_model_name_input
|
523 |
-
expert_prompt_output_history_analyzer_model_name = (
|
524 |
-
expert_prompt_output_history_analyzer_model_name_input
|
525 |
-
)
|
526 |
-
expert_prompt_analyzer_model_name = expert_prompt_analyzer_model_name_input
|
527 |
-
expert_prompt_suggester_model_name = expert_prompt_suggester_model_name_input
|
528 |
-
|
529 |
-
prompt_template_group = prompt_template_group_input
|
530 |
-
recursion_limit = recursion_limit_input
|
531 |
-
max_output_age = max_output_age_input
|
532 |
-
aggressive_exploration = aggressive_exploration_input
|
533 |
-
|
534 |
-
data_editor_data = st.data_editor(
|
535 |
-
[{"user_message": "", "expected_output": ""}],
|
536 |
-
column_config={
|
537 |
-
"user_message": st.column_config.TextColumn("User Message"),
|
538 |
-
"expected_output": st.column_config.TextColumn("Expected Output"),
|
539 |
-
},
|
540 |
-
hide_index=True,
|
541 |
-
use_container_width=True,
|
542 |
)
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
460 |
max_output_age_input = st.number_input("Max Output Age", 1, 10, 2, 1)
|
461 |
aggressive_exploration_input = st.checkbox("Aggressive Exploration", False)
|
462 |
|
463 |
+
# Initialize session state
|
464 |
+
if 'initial_system_message' not in st.session_state:
|
465 |
+
st.session_state.initial_system_message = ""
|
466 |
+
if 'initial_acceptance_criteria' not in st.session_state:
|
467 |
+
st.session_state.initial_acceptance_criteria = ""
|
468 |
+
if 'system_message_output' not in st.session_state:
|
469 |
+
st.session_state.system_message_output = ""
|
470 |
+
if 'output' not in st.session_state:
|
471 |
+
st.session_state.output = ""
|
472 |
+
if 'analysis' not in st.session_state:
|
473 |
+
st.session_state.analysis = ""
|
474 |
+
if 'acceptance_criteria_output' not in st.session_state:
|
475 |
+
st.session_state.acceptance_criteria_output = ""
|
476 |
+
if 'chat_log' not in st.session_state:
|
477 |
+
st.session_state.chat_log = []
|
478 |
+
|
479 |
+
def copy_system_message():
|
480 |
+
if 'system_message_output' in st.session_state:
|
481 |
+
st.session_state.initial_system_message = st.session_state.system_message_output
|
482 |
+
|
483 |
+
def copy_acceptance_criteria():
|
484 |
+
if 'acceptance_criteria_output' in st.session_state:
|
485 |
+
st.session_state.initial_acceptance_criteria = st.session_state.acceptance_criteria_output
|
486 |
+
|
487 |
+
def clear_session_state():
|
488 |
+
for key in st.session_state.keys():
|
489 |
+
del st.session_state[key]
|
490 |
+
|
491 |
+
if active_model_tab == "Simple":
|
492 |
+
simple_model_name = simple_model_name_input
|
493 |
+
advanced_executor_model_name = None
|
494 |
+
expert_prompt_initial_developer_model_name = None
|
495 |
+
expert_prompt_acceptance_criteria_model_name = None
|
496 |
+
expert_prompt_developer_model_name = None
|
497 |
+
expert_prompt_executor_model_name = None
|
498 |
+
expert_prompt_output_history_analyzer_model_name = None
|
499 |
+
expert_prompt_analyzer_model_name = None
|
500 |
+
expert_prompt_suggester_model_name = None
|
501 |
+
elif active_model_tab == "Advanced":
|
502 |
+
simple_model_name = None
|
503 |
+
advanced_executor_model_name = advanced_executor_model_name_input
|
504 |
+
expert_prompt_initial_developer_model_name = None
|
505 |
+
expert_prompt_acceptance_criteria_model_name = None
|
506 |
+
expert_prompt_developer_model_name = None
|
507 |
+
expert_prompt_executor_model_name = None
|
508 |
+
expert_prompt_output_history_analyzer_model_name = None
|
509 |
+
expert_prompt_analyzer_model_name = None
|
510 |
+
expert_prompt_suggester_model_name = None
|
511 |
+
else: # Expert
|
512 |
+
simple_model_name = None
|
513 |
+
advanced_executor_model_name = None
|
514 |
+
expert_prompt_initial_developer_model_name = (
|
515 |
+
expert_prompt_initial_developer_model_name_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
)
|
517 |
+
expert_prompt_acceptance_criteria_model_name = (
|
518 |
+
expert_prompt_acceptance_criteria_model_name_input
|
519 |
+
)
|
520 |
+
expert_prompt_developer_model_name = expert_prompt_developer_model_name_input
|
521 |
+
expert_prompt_executor_model_name = expert_prompt_executor_model_name_input
|
522 |
+
expert_prompt_output_history_analyzer_model_name = (
|
523 |
+
expert_prompt_output_history_analyzer_model_name_input
|
524 |
+
)
|
525 |
+
expert_prompt_analyzer_model_name = expert_prompt_analyzer_model_name_input
|
526 |
+
expert_prompt_suggester_model_name = expert_prompt_suggester_model_name_input
|
527 |
+
|
528 |
+
prompt_template_group = prompt_template_group_input
|
529 |
+
recursion_limit = recursion_limit_input
|
530 |
+
max_output_age = max_output_age_input
|
531 |
+
aggressive_exploration = aggressive_exploration_input
|
532 |
+
|
533 |
+
data_editor_data = st.data_editor(
|
534 |
+
[{"user_message": "", "expected_output": ""}],
|
535 |
+
column_config={
|
536 |
+
"user_message": st.column_config.TextColumn("User Message"),
|
537 |
+
"expected_output": st.column_config.TextColumn("Expected Output"),
|
538 |
+
},
|
539 |
+
hide_index=True,
|
540 |
+
use_container_width=True,
|
541 |
+
)
|
542 |
+
|
543 |
+
col1, col2 = st.columns(2)
|
544 |
+
|
545 |
+
with col1:
|
546 |
+
with st.expander("Advanced Inputs"):
|
547 |
+
initial_system_message = st.text_area("Initial System Message", st.session_state.initial_system_message).strip()
|
548 |
+
acceptance_criteria = st.text_area("Acceptance Criteria", st.session_state.initial_acceptance_criteria).strip()
|
549 |
+
|
550 |
+
col1_1, col1_2 = st.columns(2)
|
551 |
+
with col1_1:
|
552 |
+
generate_button_clicked = st.button("Generate", type="primary")
|
553 |
+
with col1_2:
|
554 |
+
clear_button_clicked = st.button("Clear", on_click=clear_session_state)
|
555 |
+
|
556 |
+
with col2:
|
557 |
+
if generate_button_clicked:
|
558 |
+
try:
|
559 |
+
user_message = data_editor_data[0]["user_message"].strip()
|
560 |
+
expected_output = data_editor_data[0]["expected_output"].strip()
|
561 |
+
|
562 |
+
if active_model_tab == "Simple":
|
563 |
+
system_message, output, analysis, acceptance_criteria, chat_log = process_message_with_single_llm(
|
564 |
+
user_message,
|
565 |
+
expected_output,
|
566 |
+
acceptance_criteria,
|
567 |
+
initial_system_message,
|
568 |
+
recursion_limit,
|
569 |
+
max_output_age,
|
570 |
+
simple_model_name,
|
571 |
+
prompt_template_group,
|
572 |
+
aggressive_exploration,
|
573 |
+
)
|
574 |
+
elif active_model_tab == "Advanced":
|
575 |
+
system_message, output, analysis, acceptance_criteria, chat_log = process_message_with_2_llms(
|
576 |
+
user_message,
|
577 |
+
expected_output,
|
578 |
+
acceptance_criteria,
|
579 |
+
initial_system_message,
|
580 |
+
recursion_limit,
|
581 |
+
max_output_age,
|
582 |
+
advanced_optimizer_model_name_input,
|
583 |
+
advanced_executor_model_name_input,
|
584 |
+
prompt_template_group,
|
585 |
+
aggressive_exploration,
|
586 |
+
)
|
587 |
+
else: # Expert
|
588 |
+
system_message, output, analysis, acceptance_criteria, chat_log = process_message_with_expert_llms(
|
589 |
+
user_message,
|
590 |
+
expected_output,
|
591 |
+
acceptance_criteria,
|
592 |
+
initial_system_message,
|
593 |
+
recursion_limit,
|
594 |
+
max_output_age,
|
595 |
+
expert_prompt_initial_developer_model_name,
|
596 |
+
expert_prompt_initial_developer_temperature_input,
|
597 |
+
expert_prompt_acceptance_criteria_model_name,
|
598 |
+
expert_prompt_acceptance_criteria_temperature_input,
|
599 |
+
expert_prompt_developer_model_name,
|
600 |
+
expert_prompt_developer_temperature_input,
|
601 |
+
expert_prompt_executor_model_name,
|
602 |
+
expert_prompt_executor_temperature_input,
|
603 |
+
expert_prompt_output_history_analyzer_model_name,
|
604 |
+
expert_prompt_output_history_analyzer_temperature_input,
|
605 |
+
expert_prompt_analyzer_model_name,
|
606 |
+
expert_prompt_analyzer_temperature_input,
|
607 |
+
expert_prompt_suggester_model_name,
|
608 |
+
expert_prompt_suggester_temperature_input,
|
609 |
+
prompt_template_group,
|
610 |
+
aggressive_exploration,
|
611 |
+
)
|
612 |
+
|
613 |
+
st.session_state.system_message_output = system_message
|
614 |
+
st.session_state.output = output
|
615 |
+
st.session_state.analysis = analysis
|
616 |
+
st.session_state.acceptance_criteria_output = acceptance_criteria
|
617 |
+
st.session_state.chat_log = chat_log
|
618 |
+
|
619 |
+
except Exception as e:
|
620 |
+
st.error(f"Error: {e}")
|
621 |
+
|
622 |
+
st.text_area("System Message",
|
623 |
+
key="system_message_output", height=100)
|
624 |
+
st.button("Copy System Message", key="copy_system_message",
|
625 |
+
on_click=copy_system_message)
|
626 |
+
acceptance_criteria_output = st.text_area(
|
627 |
+
"Acceptance Criteria", key="acceptance_criteria_output", height=100)
|
628 |
+
st.button("Copy Acceptance Criteria", key="copy_acceptance_criteria",
|
629 |
+
on_click=copy_acceptance_criteria)
|
630 |
+
st.text_area("Output", st.session_state.output, height=100)
|
631 |
+
st.text_area("Analysis", st.session_state.analysis, height=100)
|
632 |
+
|
633 |
+
st.json(st.session_state.chat_log)
|
guidelines/streamlit.md
CHANGED
@@ -511,6 +511,86 @@ st.slider('Select a value', 0, 100, key='slider_value', on_change=on_change)
|
|
511 |
|
512 |
By leveraging these components and callbacks, you can create interactive and dynamic Streamlit applications that respond to user inputs and actions.
|
513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
514 |
## 6. State Management
|
515 |
|
516 |
### Framework's Approach to State Management
|
|
|
511 |
|
512 |
By leveraging these components and callbacks, you can create interactive and dynamic Streamlit applications that respond to user inputs and actions.
|
513 |
|
514 |
+
### Multipage apps
|
515 |
+
|
516 |
+
Streamlit offers two primary methods for creating multipage apps: using the `pages/` directory for a quick setup or leveraging `st.Page` and `st.navigation` for more customization.
|
517 |
+
|
518 |
+
#### Overview
|
519 |
+
|
520 |
+
- **Using `pages/` Directory**: Place Python files in a `pages/` directory next to your entrypoint file. Streamlit automatically creates pages based on these files and populates a navigation menu in the sidebar.
|
521 |
+
- **Example**:
|
522 |
+
```
|
523 |
+
your_working_directory/
|
524 |
+
βββ pages/
|
525 |
+
β βββ a_page.py
|
526 |
+
β βββ another_page.py
|
527 |
+
βββ your_homepage.py
|
528 |
+
```
|
529 |
+
- **Run**: `streamlit run your_homepage.py`
|
530 |
+
|
531 |
+
- **Using `st.Page` and `st.navigation`**: This method offers more flexibility. Define pages using `st.Page` and configure navigation with `st.navigation` in your entrypoint file.
|
532 |
+
- **Example**:
|
533 |
+
```python
|
534 |
+
import streamlit as st
|
535 |
+
pg = st.navigation([st.Page("page_1.py"), st.Page("page_2.py")])
|
536 |
+
pg.run()
|
537 |
+
```
|
538 |
+
|
539 |
+
#### Page Terminology
|
540 |
+
|
541 |
+
- **Page Source**: Python file or callable function.
|
542 |
+
- **Page Label**: Identifies the page in the navigation menu.
|
543 |
+
- **Page Title**: HTML `<title>` element content.
|
544 |
+
- **Page URL Pathname**: Relative path from the root URL.
|
545 |
+
- **Page Icons**: Favicon and icon next to the page label.
|
546 |
+
|
547 |
+
#### Navigation
|
548 |
+
|
549 |
+
- **Default Navigation**: Appears in the sidebar.
|
550 |
+
- **Custom Navigation**: Use `st.page_link` to build a custom menu.
|
551 |
+
- **Programmatic Navigation**: Use `st.switch_page`.
|
552 |
+
|
553 |
+
#### Widget Statefulness
|
554 |
+
|
555 |
+
Widgets reset to default values when switching pages. To maintain state:
|
556 |
+
|
557 |
+
- **Option 1**: Place widgets in the entrypoint file (only works with `st.Page` and `st.navigation`).
|
558 |
+
- **Example**:
|
559 |
+
```python
|
560 |
+
import streamlit as st
|
561 |
+
pg = st.navigation([st.Page("page_1.py"), st.Page("page_2.py")])
|
562 |
+
st.sidebar.selectbox("Group", ["A", "B", "C"], key="group")
|
563 |
+
st.sidebar.slider("Size", 1, 5, key="size")
|
564 |
+
pg.run()
|
565 |
+
```
|
566 |
+
|
567 |
+
- **Option 2**: Use a separate key in `st.session_state` to save widget values.
|
568 |
+
- **Example**:
|
569 |
+
```python
|
570 |
+
import streamlit as st
|
571 |
+
def store_value(key):
|
572 |
+
st.session_state[key] = st.session_state["_" + key]
|
573 |
+
def load_value(key):
|
574 |
+
st.session_state["_" + key] = st.session_state[key]
|
575 |
+
load_value("my_key")
|
576 |
+
st.number_input("Number of filters", key="_my_key", on_change=store_value, args=["my_key"])
|
577 |
+
```
|
578 |
+
|
579 |
+
- **Option 3**: Ensure widget values persist by checking `st.session_state` at the top of each page.
|
580 |
+
- **Example**:
|
581 |
+
```python
|
582 |
+
if "my_key" in st.session_state:
|
583 |
+
st.session_state.my_key = st.session_state.my_key
|
584 |
+
```
|
585 |
+
|
586 |
+
For more details, refer to the [Streamlit documentation](https://docs.streamlit.io/develop/concepts/multipage-apps).
|
587 |
+
|
588 |
+
_forum_
|
589 |
+
|
590 |
+
### Still have questions?
|
591 |
+
|
592 |
+
Our [forums](https://discuss.streamlit.io/) are full of helpful information and Streamlit experts.
|
593 |
+
|
594 |
## 6. State Management
|
595 |
|
596 |
### Framework's Approach to State Management
|