Skip to content

Cognitive Reframer — Private, offline AI tool that helps you transform negative thoughts into positive, actionable perspectives, powered by local gpt-oss reasoning.

Notifications You must be signed in to change notification settings

abhishek085/cognitive_reframer

Repository files navigation

Cognitive Reframer

Alt text

Cognitive Reframer is a Python-based application designed to assist users in reframing thoughts, leveraging speech recognition and a user-friendly interface. The project is modular, with clear separation between API, speech processing, reframing logic, and UI components.

Overview

This app provides a web UI (Streamlit) and a backend API (FastAPI) for cognitive reframing. It uses:

  • FastAPI for backend endpoints
  • Streamlit for the user interface
  • Whisper for speech-to-text
  • Ollama (open-source LLM) for reframing logic
  • macOS TTS for speech output

Features

  • Speech Recognition: Uses macOS default speech APIs for capturing and processing user input.
  • Reframing Engine: Core logic to help users reframe negative or unproductive thoughts.
  • API Layer: Exposes reframing and speech functionalities via an internal API.
  • User Interface: Simple UI for interacting with the reframer and speech modules.

How It Works

  1. User enters or records a thought in the UI.
  2. The thought is sent to the FastAPI backend (/reframe endpoint).
  3. The backend uses Ollama LLM to:
    • Detect cognitive distortion
    • Generate a narrative reframe
    • Suggest a Socratic question
    • Propose an action plan
  4. Results are displayed in the UI and can be read aloud using macOS TTS.

Project Structure

pyproject.toml         # Project metadata and dependencies
requirements.txt       # Python dependencies
uv.lock                # Lock file for dependencies
README.md              # Project documentation
app/
	 app_api.py         # API layer for the application
	 Mac_speech_default.py # macOS speech recognition integration
	 reframer.py        # Core reframing logic
	 ui.py              # User interface logic
	 __pycache__/       # Compiled Python files

## Key Dependencies
- fastapi
- streamlit
- openai-whisper
- ollama
- sounddevice, wavio
- requests

Installation

  1. Clone the repository:
    git clone https://github.com/abhishek085/cognitive_reframer.git
    cd cognitive_reframer
  2. Install dependencies:
    pip install -r requirements.txt
    Or use uv for faster installs:
    uv pip install -r requirements.txt

Usage

1. Start the backend API

uvicorn app.app_api:app --reload --port 8090

2. Start the Streamlit UI

streamlit run app/ui.py

3. Use the app

  • Type or record a thought
  • Click "Reframe Thought" to get results

Sample Data

Use the following sample inputs to test the reframing logic of the app:

Sample Input:

I always mess things up.
I'm not good enough.
This will never work.

Expected Output (Reframed):

{
	"distortion": "All-or-nothing thinking",
	"narrative": "Everyone makes mistakes sometimes. I can learn and improve.",
	"socratic_question": "What evidence do I have that I always fail?",
	"action_plan": "Reflect on past successes and try a new approach."
}

## Modules
- **app_api.py**: Handles API requests and routes them to the appropriate module.
- **Mac_speech_default.py**: Integrates with macOS speech APIs for voice input.
- **reframer.py**: Contains the logic for reframing thoughts and generating responses.
- **ui.py**: Manages the user interface, connecting user actions to backend logic.

## API Example
POST `/reframe`
```json
{
	"text": "I always mess things up."
}

Response:

{
	"distortion": "All-or-nothing thinking",
	"narrative": "Everyone makes mistakes sometimes. I can learn and improve.",
	"socratic_question": "What evidence do I have that I always fail?",
	"action_plan": "Reflect on past successes and try a new approach."
}

Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes and commit them.
  4. Push to your branch and open a pull request.

License

This project is licensed under the MIT License.

Contact

For questions or support, open an issue on GitHub or contact the repository owner.

About

Cognitive Reframer — Private, offline AI tool that helps you transform negative thoughts into positive, actionable perspectives, powered by local gpt-oss reasoning.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages