Spaces:
Sleeping
Sleeping
| """ | |
| 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] | |