Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.12.0
metadata
title: Reframe Cognitive Reframing Assistant
emoji: π§
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.47.2
python_version: '3.10'
app_file: app.py
pinned: false
license: mit
hf_oauth: true
π§ reframe: Cognitive Reframing Assistant
A tool inspired by CBT (Cognitive Behavioral Therapy) designed to help identify and reframe cognitive distortions.
π― Features
- Educational Landing Page: Learn about CBT and cognitive reframing
- Interactive Chat: Share thoughts and receive balanced perspectives
- Pattern Recognition: Identifies cognitive distortions in thinking patterns
- Similar Situations: Shows relatable examples with reframed perspectives
- Learning Center: Explore 13+ cognitive distortions with examples
- Multilingual: Support for English and Spanish
- Privacy-First: No message content stored; only pseudonymous usage counters
- Agentic LLM: Uses Hugging Face Inference API (required for chat)
- Streaming Chat: Incremental assistant messages for a smoother UX
- Lightweight Memory: Assistant considers the last N turns (default 6)
π Project Structure
re-frame-gradio/
βββ app.py # Main Gradio application
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ cbt_knowledge/ # CBT knowledge base
β βββ __init__.py
β βββ distortions.py # Cognitive distortions database
β βββ reframing_tools.py # Reframing strategies
βββ ui_components/ # UI components
β βββ __init__.py
β βββ landing.py # Landing page
β βββ learn.py # Learning center
βββ locales/ # Translations (optional)
βββ en.json # English
βββ es.json # Spanish
π§© Cognitive Distortions Covered
- All-or-Nothing Thinking - Black and white thinking
- Fortune Telling - Negative predictions
- Catastrophizing - Expecting the worst
- Mind Reading - Assuming others' thoughts
- Mental Filter - Focusing on negatives
- Should Statements - Rigid rules
- Labeling - Global negative labels
- Personalization - Self-blame
- Emotional Reasoning - Feelings as facts
- Discounting Positives - Dismissing good things
- Jumping to Conclusions - Assumptions without evidence
- Magnification/Minimization - Distorting importance
- Overgeneralization - Broad conclusions from single events
π€ How It Works
- Share Your Thoughts: Type what's on your mind in the chat
- Pattern Detection: The system identifies thinking patterns
- Balanced Perspectives: Get alternative ways to view the situation
- Similar Examples: See how others reframed similar thoughts
- Learn More: Explore specific distortions in the Learn tab
β οΈ Important Disclaimers
- This is intended to be a helpful tool, NEVER a replacement for professional therapy
- NOT intended for crisis situations or medical advice
- If you're in crisis, please contact emergency services or a crisis helpline
- No message content is stored. For quotas and observability, the app records per-user interaction counters using salted hashes and aggregated metrics (no raw usernames, emails, or IPs).
π Login, Quotas, and Owner Controls
This Space supports "Login with Hugging Face" for stable and secure per-user quotas.
- The UI includes a Login button. Once logged in, the app receives an OAuth profile and derives a pseudonymous, salted user id.
- Per-user daily interactions are capped via
HF_AGENT_MAX_INTERACTIONS_PER_USER(default: 12). - An Owner tab is visible only to the Space owner.
- Environment variables:
HUGGINGFACEHUB_API_TOKENβ required: Inference API token (set as a Secret).HF_TOKENis also accepted, but prefer this name.HF_AGENT_MAX_INTERACTIONS_PER_USERβ per-user daily cap (default: 12)USAGE_SALTβ required: random salt for hashing user identifiersAGENT_CALL_LOG_PATHβ path to persist counters (e.g.,/data/agent_calls.json)APP_METRICS_PATHβ path to privacy-preserving metrics (e.g.,/data/app_metrics.json)HF_HOMEβ recommended: set to/data/.huggingfaceto persist cache across restarts
Notes:
- The app never stores raw usernames, emails, IPs, or message content.
- Configure persistent storage for those JSON files if you want counters to survive Space restarts. If using persistent storage, set
HF_HOME=/data/.huggingfaceso model/cache downloads persist too.
Owner-only Admin
Set the environment variable OWNER_USER to your Hugging Face username. The Owner tab will only be shown when the logged-in user matches this username.
OWNER_USERβ required to enable Owner tab (e.g.,carlos)
π Acknowledgments
- Inspired by CBT principles
- Original prototype built with Google ADK
- Built with Gradio and Hugging Face
π License
MIT License - See LICENSE file for details