Show HN: Local GLaDOS

https://github.com/dnhkng/GlaDOS

GLaDOS Personality Core

This is a project dedicated to building a real-life version of GLaDOS.

NEW: If you want to chat or join the community, Join our discord!

localGLaDOS

This is a hardware and software project that will create an aware, interactive, and embodied GLaDOS.

This will entail:

  • Train GLaDOS voice generator
  • Generate a prompt that leads to a realistic "Personality Core"
  • Generate a MemGPT medium- and long-term memory for GLaDOS
  • Give GLaDOS vision via LLaVA
  • Create 3D-printable parts
  • Design the animatronics system

Software Architecture

The initial goals are to develop a low-latency platform, where GLaDOS can respond to voice interactions within 600ms.

To do this, the system constantly records data to a circular buffer, waiting for voice to be detected. When it's determined that the voice has stopped (including detection of normal pauses), it will be transcribed quickly. This is then passed to streaming local Large Language Model, where the streamed text is broken by sentence, and passed to a text-to-speech system. This means further sentences can be generated while the current is playing, reducing latency substantially.

Subgoals

  • The other aim of the project is to minimize dependencies, so this can run on constrained hardware. That means no PyTorch or other large packages.
  • As I want to fully understand the system, I have removed a large amount of redirection: which means extracting and rewriting code. i.e. as GLaDOS only speaks English, I have rewritten the wrapper around espeak and the entire Text-to-Speech subsystem is about 500 LOC and has only 3 dependencies: numpy, onnxruntime, and sounddevice.

Hardware System

This will be based on servo- and stepper-motors. 3D printable STL will be provided to create GlaDOS's body, and she will be given a set of animations to express herself. The vision system will allow her to track and turn toward people and things of interest.

Installation Instruction

New Simplified Windows Installation Process

Don't want to compile anything? Try this simplified process, but be aware it's still in the experimental stage!

  1. Open the Microsoft Store, search for python and install Python 3.12. a. To use Python 3.10, install typing_extensions and replace import typing in glados/llama.py with import typing_extensions.
  2. Download and unzip this repository somewhere in your home folder.
  3. Run the install_windows.bat. During the process, you will be prompted to install eSpeak-ng, which is necessary for GLaDOS's speech capabilities. This step also downloads the Whisper voice recognition model and the Llama-3 8B model.
  4. Once this is all done, you can initiate GLaDOS with the start_windows.bat script.

Even newer Simplified macOS Installation Process

This is still experimental. Any issues can be addressed in the Discord server. If you create an issue related to this, you will be referred to the Discord server.

  1. Install Python 3.12 from pythons website (https://www.python.org/downloads/release/python-3124/)
  2. (Optional) Install Homebrew before running the install_mac.sh. If you don't do this, it will install it for you (Not tested).
  3. git clone this repository using git clone github.com/dnhkng/glados.git
  4. Run the install_mac.sh. If you do not have Python installed, then you will run into an error.
  5. Once this finishes run the start_mac.sh to start GLaDOS

Regular installation

If you want to install the TTS Engine on your machine, please follow the steps below. This has only been tested on Linux, but I think it will work on Windows with small tweaks. If you are on Windows, I would recommend WSL with an Ubuntu image. Proper Windows and Mac support is in development.

  1. Install the espeak synthesizer according to the installation instructions for your operating system.
  2. Install the required Python packages, e.g., by running pip install -r requirements.txt on Mac or Linux systems without an Nvidia GPU, and pip install -r requirements_cuda.txt if you have a modern Nvidia GPU.
  3. Download the models:
    1. voice recognition model
    2. Llama-3 8B or
    3. Llama-3 70B and put them in the ".models" directory.
  4. For voice recognition, we use Whisper.cpp
    1. You can either download the compiled whisper.cpp DLLs (recommended for Windows), and copy the dll to the ./submodules/whisper.cpp directory
    2. Or compile them yourself.
      1. To pull the code, from the GLaDOS directory use: git submodule update --init --recursive
      2. Move to the right subdirectory: cd submodules/whisper.cpp
      3. Compile for your system (see the Documentation), e.g.
        1. Linux with CUDA: WHISPER_CUDA=1 make libwhisper.so -j
        2. Mac: make libwhisper.so -j. For Apple silicon devices, it is also possible to compile using Core ML like this WHISPER_COREML=1 make libwhisper.so -j, but it may be unnecessary--modern Macs are fast enough without it--and if you do, don't forget to follow the instructions to generate Core ML models.
  5. For the LLM, you have two options:
    1. Compile llama.cpp:
      1. Use: git submodule update --init --recursive to pull the llama.cpp repo
      2. Move to the right subdirectory: cd submodules/llama.cpp
      3. Compile llama.cpp, (see the Documentation)
        1. Linux with CUDA make llama-server LLAMA_CUDA=1
        2. MacOS with Metal make llama-server
    2. Use a commercial API or install an inference backend yourself, such as Ollama or Llamafile:
      1. Find and install a backend with an OpenAI compatible API (most of them)
      2. Edit the glados_config.yaml
        1. update completion_url to the URL of your local server
        2. for commercial APIs, add the api_key
        3. remove the LlamaServer configurations (make them null)

Help Section

  1. If you have an error about packages or files not being found, make sure you have the whisper and llama binaries in the respective submodules folders! They are empty by default, and you manually have to add the binaries as described above!

  2. Make sure you are using the right Llama-3 Model! I have made Llama-3 8B, with the quantization Q6_K the default. You might need to redownload the model if you don't have Meta-Llama-3-8B-Instruct-Q6_K.gguf in your models folder!

  3. If you have limited VRAM, you can save 3Gb by using downloading a highly quantised IQ3_XS model and moving it to the models folder. If you do this, modify the glados_config.yaml to modify the model used: model_path: "./models/Meta-Llama-3-8B-Instruct-IQ3_XS.gguf"

  4. If you find you are getting stuck in loops, as GLaDOS is hearing herself speak, you have two options:

    1. Solve this by upgrading your hardware. You need to you either headphone, so she can't physically hear herself speak, or a conference-style room microphone/speaker. These have hardware sound cancellation, and prevent these loops.
    2. Disable voice interruption. This means neither you nor GLaDOS can interrupt when GLaDOS is speaking. To accomplish this, edit the glados_config.yaml, and change interruptible: to false.

Windows Run

Prerequisite WSL2 with fresh drivers, here is guide https://docs.docker.com/desktop/gpu/

  1. git submodule update --init --recursive
  2. put models in models dir or mount that dir into a docker container
  3. docker build -t glados .
  4. docker run -e "PULSE_SERVER=/mnt/wslg/PulseServer" -v "/mnt/wslg/:/mnt/wslg/" --gpus=all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 glados

It works in ubuntu terminal started with WSL2

Running GLaDOS

To start GLaDOS, use: python glados.py

You can stop with "Ctrl-c".

Testing

You can test the systems by exploring the 'demo.ipynb'.

Star History

dnhkng%2FGlaDOS | Trendshift

Star History Chart

{
"by": "dnhkng",
"descendants": 1,
"id": 40237586,
"kids": [
40237931,
40237725
],
"score": 12,
"text": "I built GLaDOS's brain, with a low-latency chat interface. Sub 600ms voice-to-voice response, running on Llama-3 70B.",
"time": 1714664903,
"title": "Show HN: Local GLaDOS",
"type": "story",
"url": "https://github.com/dnhkng/GlaDOS"
}
{
"author": "dnhkng",
"date": null,
"description": "This is the Personality Core for GLaDOS, the first steps towards a real-life implementation of the AI from the Portal series by Valve. - dnhkng/GlaDOS",
"image": "https://opengraph.githubassets.com/daef995611057370ec14b853861619644e354afbc3cefe89b3e5fe4ee9a2a886/dnhkng/GlaDOS",
"logo": "https://logo.clearbit.com/github.com",
"publisher": "GitHub",
"title": "GitHub - dnhkng/GlaDOS: This is the Personality Core for GLaDOS, the first steps towards a real-life implementation of the AI from the Portal series by Valve.",
"url": "https://github.com/dnhkng/GlaDOS"
}
{
"url": "https://github.com/dnhkng/GlaDOS",
"title": "GitHub - dnhkng/GlaDOS: This is the Personality Core for GLaDOS, the first steps towards a real-life implementation of the AI from the Portal series by Valve.",
"description": "GLaDOS Personality Core This is a project dedicated to building a real-life version of GLaDOS. NEW: If you want to chat or join the community, Join our discord! This is a hardware and software project that...",
"links": [
"https://github.com/dnhkng/GlaDOS"
],
"image": "https://opengraph.githubassets.com/daef995611057370ec14b853861619644e354afbc3cefe89b3e5fe4ee9a2a886/dnhkng/GlaDOS",
"content": "<div><article><p></p><h2>GLaDOS Personality Core</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#glados-personality-core\"></a><p></p>\n<p>This is a project dedicated to building a real-life version of GLaDOS.</p>\n<p>NEW: If you want to chat or join the community, <a target=\"_blank\" href=\"https://discord.com/invite/ERTDKwpjNB\">Join our discord!</a></p>\n<p><a target=\"_blank\" href=\"https://www.youtube.com/watch?v=KbUfWpykBGg\"><img src=\"https://camo.githubusercontent.com/82d6db4edd9ad68f24c72fe552283721dd4113dc2c7de1b022f61fd2140ca990/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f4b6255665770796b4247672f302e6a7067\" alt=\"localGLaDOS\" /></a></p>\n<p><em>This is a hardware and software project that will create an aware, interactive, and embodied GLaDOS.</em></p>\n<p>This will entail:</p>\n<ul>\n<li> Train GLaDOS voice generator</li>\n<li> Generate a prompt that leads to a realistic \"Personality Core\"</li>\n<li> Generate a <a target=\"_blank\" href=\"https://github.com/cpacker/MemGPT\">MemGPT</a> medium- and long-term memory for GLaDOS</li>\n<li> Give GLaDOS vision via <a target=\"_blank\" href=\"https://llava-vl.github.io/\">LLaVA</a></li>\n<li> Create 3D-printable parts</li>\n<li> Design the animatronics system</li>\n</ul>\n<p></p><h2>Software Architecture</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#software-architecture\"></a><p></p>\n<p>The initial goals are to develop a low-latency platform, where GLaDOS can respond to voice interactions within 600ms.</p>\n<p>To do this, the system constantly records data to a circular buffer, waiting for <a target=\"_blank\" href=\"https://github.com/snakers4/silero-vad\">voice to be detected</a>. When it's determined that the voice has stopped (including detection of normal pauses), it will be <a target=\"_blank\" href=\"https://github.com/huggingface/distil-whisper\">transcribed quickly</a>. This is then passed to streaming <a target=\"_blank\" href=\"https://github.com/ggerganov/llama.cpp\">local Large Language Model</a>, where the streamed text is broken by sentence, and passed to a <a target=\"_blank\" href=\"https://github.com/rhasspy/piper\">text-to-speech system</a>. This means further sentences can be generated while the current is playing, reducing latency substantially.</p>\n<p></p><h3>Subgoals</h3><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#subgoals\"></a><p></p>\n<ul>\n<li>The other aim of the project is to minimize dependencies, so this can run on constrained hardware. That means no PyTorch or other large packages.</li>\n<li>As I want to fully understand the system, I have removed a large amount of redirection: which means extracting and rewriting code. i.e. as GLaDOS only speaks English, I have rewritten the wrapper around <a target=\"_blank\" href=\"https://espeak.sourceforge.net/\">espeak</a> and the entire Text-to-Speech subsystem is about 500 LOC and has only 3 dependencies: numpy, onnxruntime, and sounddevice.</li>\n</ul>\n<p></p><h2>Hardware System</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#hardware-system\"></a><p></p>\n<p>This will be based on servo- and stepper-motors. 3D printable STL will be provided to create GlaDOS's body, and she will be given a set of animations to express herself. The vision system will allow her to track and turn toward people and things of interest.</p>\n<p></p><h2>Installation Instruction</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#installation-instruction\"></a><p></p>\n<p></p><h3><em>New Simplified Windows Installation Process</em></h3><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#new-simplified--windows-installation-process\"></a><p></p>\n<p>Don't want to compile anything? Try this simplified process, but be aware it's still in the experimental stage!</p>\n<ol>\n<li>Open the Microsoft Store, search for <code>python</code> and install Python 3.12.\na. To use Python 3.10, install <code>typing_extensions</code> and replace <code>import typing</code> in <code>glados/llama.py</code> with <code>import typing_extensions</code>.</li>\n<li>Download and unzip this repository somewhere in your home folder.</li>\n<li>Run the <code>install_windows.bat</code>. During the process, you will be prompted to install eSpeak-ng, which is necessary for GLaDOS's speech capabilities. This step also downloads the Whisper voice recognition model and the Llama-3 8B model.</li>\n<li>Once this is all done, you can initiate GLaDOS with the <code>start_windows.bat</code> script.</li>\n</ol>\n<p></p><h3><em>Even newer Simplified macOS Installation Process</em></h3><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#even-newer-simplified-macos-installation-process\"></a><p></p>\n<p>This is still experimental. Any issues can be addressed in the Discord server. If you create an issue related to this, you will be referred to the Discord server.</p>\n<ol>\n<li>Install Python 3.12 from pythons website (<a target=\"_blank\" href=\"https://www.python.org/downloads/release/python-3124/\">https://www.python.org/downloads/release/python-3124/</a>)</li>\n<li>(Optional) Install Homebrew before running the <code>install_mac.sh</code>. If you don't do this, it will install it for you (Not tested).</li>\n<li><code>git clone</code> this repository using <code>git clone github.com/dnhkng/glados.git</code></li>\n<li>Run the <code>install_mac.sh</code>. If you do not have Python installed, then you will run into an error.</li>\n<li>Once this finishes run the <code>start_mac.sh</code> to start GLaDOS</li>\n</ol>\n<p></p><h2>Regular installation</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#regular-installation\"></a><p></p>\n<p>If you want to install the TTS Engine on your machine, please follow the steps\nbelow. This has only been tested on Linux, but I think it will work on Windows with small tweaks.\nIf you are on Windows, I would recommend WSL with an Ubuntu image. Proper Windows and Mac support is in development.</p>\n<ol>\n<li>Install the <a target=\"_blank\" href=\"https://github.com/espeak-ng/espeak-ng\"><code>espeak</code></a> synthesizer\naccording to the <a target=\"_blank\" href=\"https://github.com/espeak-ng/espeak-ng/blob/master/docs/guide.md\">installation\ninstructions</a>\nfor your operating system.</li>\n<li>Install the required Python packages, e.g., by running <code>pip install -r requirements.txt</code> on Mac or Linux systems without an Nvidia GPU, and <code>pip install -r requirements_cuda.txt</code> if you have a modern Nvidia GPU.</li>\n<li>Download the models:\n<ol>\n<li><a target=\"_blank\" href=\"https://huggingface.co/distil-whisper/distil-medium.en/resolve/main/ggml-medium-32-2.en.bin?download=true\">voice recognition model</a></li>\n<li><a target=\"_blank\" href=\"https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-Q6_K.gguf?download=true\">Llama-3 8B</a> or</li>\n<li><a target=\"_blank\" href=\"https://huggingface.co/bartowski/Meta-Llama-3-70B-Instruct-GGUF/resolve/main/Meta-Llama-3-70B-Instruct-IQ4_XS.gguf?download=true\">Llama-3 70B</a>\nand put them in the \".models\" directory.</li>\n</ol>\n</li>\n<li>For voice recognition, we use <a target=\"_blank\" href=\"https://github.com/ggerganov/whisper.cpp\">Whisper.cpp</a>\n<ol>\n<li>You can either download the compiled <a target=\"_blank\" href=\"https://github.com/ggerganov/whisper.cpp/releases\">whisper.cpp DLLs</a> (recommended for Windows), and copy the dll to the ./submodules/whisper.cpp directory</li>\n<li>Or compile them yourself.\n<ol>\n<li>To pull the code, from the GLaDOS directory use: <code>git submodule update --init --recursive</code></li>\n<li>Move to the right subdirectory: <code>cd submodules/whisper.cpp</code></li>\n<li>Compile for your system <a target=\"_blank\" href=\"https://github.com/ggerganov/whisper.cpp\">(see the Documentation)</a>, e.g.\n<ol>\n<li>Linux with <a target=\"_blank\" href=\"https://github.com/ggerganov/whisper.cpp?tab=readme-ov-file#nvidia-gpu-support\">CUDA</a>: <code>WHISPER_CUDA=1 make libwhisper.so -j</code></li>\n<li>Mac: <code>make libwhisper.so -j</code>. For Apple silicon devices, it is also possible to compile using Core ML like this <code>WHISPER_COREML=1 make libwhisper.so -j</code>,\nbut it may be unnecessary--modern Macs are fast enough without it--and if you do, don't forget to follow the <a target=\"_blank\" href=\"https://github.com/ggerganov/whisper.cpp?tab=readme-ov-file#core-ml-support\">instructions</a> to generate Core ML models.</li>\n</ol>\n</li>\n</ol>\n</li>\n</ol>\n</li>\n<li>For the LLM, you have two options:\n<ol>\n<li>Compile llama.cpp:\n<ol>\n<li>Use: <code>git submodule update --init --recursive</code> to pull the llama.cpp repo</li>\n<li>Move to the right subdirectory: <code>cd submodules/llama.cpp</code></li>\n<li>Compile llama.cpp, <a target=\"_blank\" href=\"https://github.com/ggerganov/whisper.cpp\">(see the Documentation)</a>\n<ol>\n<li>Linux with <a target=\"_blank\" href=\"https://github.com/ggerganov/llama.cpp?tab=readme-ov-file#cuda\">CUDA</a> <code>make llama-server LLAMA_CUDA=1</code></li>\n<li>MacOS with <a target=\"_blank\" href=\"https://github.com/ggerganov/llama.cpp?tab=readme-ov-file#metal-build\">Metal</a> <code>make llama-server</code></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>Use a commercial API or install an inference backend yourself, such as Ollama or Llamafile:\n<ol>\n<li>Find and install a backend with an OpenAI compatible API (most of them)</li>\n<li>Edit the glados_config.yaml\n<ol>\n<li>update <code>completion_url</code> to the URL of your local server</li>\n<li>for commercial APIs, add the <code>api_key</code></li>\n<li>remove the LlamaServer configurations (make them null)</li>\n</ol>\n</li>\n</ol>\n</li>\n</ol>\n</li>\n</ol>\n<p></p><h2>Help Section</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#help-section\"></a><p></p>\n<ol>\n<li>\n<p>If you have an error about packages or files not being found, make sure you have the whisper and llama binaries in the respective submodules folders! They are empty by default, and you manually have to add the binaries as described above!</p>\n</li>\n<li>\n<p>Make sure you are using the right Llama-3 Model! I have made Llama-3 8B, with the quantization Q6_K the default. You might need to redownload the model if you don't have <code>Meta-Llama-3-8B-Instruct-Q6_K.gguf</code> in your models folder!</p>\n</li>\n<li>\n<p>If you have limited VRAM, you can save 3Gb by using downloading a <a target=\"_blank\" href=\"https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-IQ3_XS.gguf?download=true\">highly quantised IQ3_XS model</a> and moving it to the models folder. If you do this, modify the <code>glados_config.yaml</code> to modify the model used: <code>model_path: \"./models/Meta-Llama-3-8B-Instruct-IQ3_XS.gguf\"</code></p>\n</li>\n<li>\n<p>If you find you are getting stuck in loops, as GLaDOS is hearing herself speak, you have two options:</p>\n<ol>\n<li>Solve this by upgrading your hardware. You need to you either headphone, so she can't physically hear herself speak, or a conference-style room microphone/speaker. These have hardware sound cancellation, and prevent these loops.</li>\n<li>Disable voice interruption. This means neither you nor GLaDOS can interrupt when GLaDOS is speaking. To accomplish this, edit the <code>glados_config.yaml</code>, and change <code>interruptible:</code> to <code>false</code>.</li>\n</ol>\n</li>\n</ol>\n<p></p><h2>Windows Run</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#windows-run\"></a><p></p>\n<p>Prerequisite WSL2 with fresh drivers, here is guide <a target=\"_blank\" href=\"https://docs.docker.com/desktop/gpu/\">https://docs.docker.com/desktop/gpu/</a></p>\n<ol>\n<li><code>git submodule update --init --recursive</code></li>\n<li>put models in models dir or mount that dir into a docker container</li>\n<li><code>docker build -t glados .</code></li>\n<li><code>docker run -e \"PULSE_SERVER=/mnt/wslg/PulseServer\" -v \"/mnt/wslg/:/mnt/wslg/\" --gpus=all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 glados</code></li>\n</ol>\n<p>It works in ubuntu terminal started with WSL2</p>\n<p></p><h2>Running GLaDOS</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#running-glados\"></a><p></p>\n<p>To start GLaDOS, use:\n<code>python glados.py</code></p>\n<p>You can stop with \"Ctrl-c\".</p>\n<p></p><h2>Testing</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#testing\"></a><p></p>\n<p>You can test the systems by exploring the 'demo.ipynb'.</p>\n<p></p><h2>Star History</h2><a target=\"_blank\" href=\"https://github.com/dnhkng/GlaDOS#star-history\"></a><p></p>\n<p><a target=\"_blank\" href=\"https://trendshift.io/repositories/9828\"><img src=\"https://camo.githubusercontent.com/11548e4e7f3d59c7480114c995de80ddc5c48403407d50f1c67134987de966e4/68747470733a2f2f7472656e6473686966742e696f2f6170692f62616467652f7265706f7369746f726965732f39383238\" alt=\"dnhkng%2FGlaDOS | Trendshift\" /></a></p>\n<p><a target=\"_blank\" href=\"https://star-history.com/#dnhkng/GlaDOS&amp;Date\"><img src=\"https://camo.githubusercontent.com/cd12fb552ec381a967d02fdca15505e4fe69dbccc54647235b35d7d3a1439e5d/68747470733a2f2f6170692e737461722d686973746f72792e636f6d2f7376673f7265706f733d646e686b6e672f476c61444f5326747970653d44617465\" alt=\"Star History Chart\" /></a></p>\n</article></div>",
"author": "",
"favicon": "https://github.githubassets.com/favicons/favicon.svg",
"source": "github.com",
"published": "",
"ttr": 223,
"type": "object"
}