File size: 2,292 Bytes
c6ce43e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
"""
Learn tab component for exploring cognitive distortions
"""

import gradio as gr


def create_learn_tab(translations, distortions_db):
    """Create the learn/education tab"""

    with gr.Column():
        gr.Markdown("### Explore Cognitive Distortions")
        gr.Markdown("Learn about common thinking patterns and how to work with them.")

        # Dropdown to select distortion
        distortion_names = [info['name'] for info in distortions_db.values()]
        selected = gr.Dropdown(
            choices=distortion_names,
            label=translations['select_distortion'],
            value=distortion_names[0] if distortion_names else None,
        )

        # Display area for distortion information
        with gr.Column():
            definition_display = gr.Markdown()
            examples_display = gr.Markdown()
            strategies_display = gr.Markdown()
            actions_display = gr.Markdown()

        def show_distortion_info(distortion_name):
            """Display information about selected distortion"""
            # Find the distortion by name
            for _key, info in distortions_db.items():
                if info['name'] == distortion_name:
                    definition = f"### {translations['definition']}\n{info['definition']}"

                    examples = f"### {translations['examples']}\n"
                    for example in info['examples']:
                        examples += f"- \"{example}\"\n"

                    strategies = f"### {translations['strategies']}\n"
                    for strategy in info['reframing_strategies']:
                        strategies += f"- {strategy}\n"

                    actions = f"### {translations['actions']}\n"
                    for action in info['micro_actions']:
                        actions += f"- {action}\n"

                    return definition, examples, strategies, actions

            return "", "", "", ""

        # Connect dropdown to display
        selected.change(
            show_distortion_info,
            inputs=[selected],
            outputs=[definition_display, examples_display, strategies_display, actions_display],
        )

        # Initialize with first distortion
        if distortion_names:
            selected.value = distortion_names[0]