File size: 1,700 Bytes
8d404bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import json

def app():
    st.header("Career Preferences")

    preferences_sections = [
        "Size of Organization",
        "Type of Organization",
        "Industry",
        "Department",
        "Function"
    ]

    preferences_questions = ["What I think I want", "What I know I don’t want"]

    # Initialize preferences sets in session state if it doesn't exist
    if 'preferences_sets' not in st.session_state:
        st.session_state.preferences_sets = [{}]

    # Function to add another set of preferences
    def add_another_set():
        st.session_state.preferences_sets.append({})

    # Display current sets of preferences
    for i, preferences_set in enumerate(st.session_state.preferences_sets):
        with st.expander(f"Preferences Set {i + 1}", expanded=True):
            for section in preferences_sections:
                st.subheader(section)
                for question in preferences_questions:
                    key = f"{section}_{question}_{i}"
                    st.session_state.preferences_sets[i][f"{section}: {question}"] = st.text_area(
                        label=question,
                        key=key,
                        value=preferences_set.get(f"{section}: {question}", "")
                    )

    st.button("Add More", on_click=add_another_set)

    if st.button('Save Preferences'):
        save_preferences()
        st.success('Preferences saved successfully!')

def save_preferences():
    """Save the preferences sets to a JSON file."""
    with open('preferences_sets.json', 'w') as file:
        json.dump(st.session_state['preferences_sets'], file, indent=4)

if __name__ == "__main__":
    app()